From patchwork Fri Jan 29 14:45:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1433331 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=e/TMtGzr; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DS0Wv2WSMz9sCq for ; Sat, 30 Jan 2021 01:46:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 07D4E39DA50F; Fri, 29 Jan 2021 14:45:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 07D4E39DA50F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1611931559; bh=EU5v+OfvunRBPrg2c9p+O+87kqlOT2G8TjNDUkeYaeg=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=e/TMtGzr9JIfeqCPbjR3HOGINMT9myg3yMhfYdns7qjI68e3uVYfdoFrxfOr8RY9G MgXe7rm1YS8Im1GuKiZVclhOAM5XU4xLc4dUp8/GvIkGCZGPD8Tk1BPfHUetGMIzG4 Yftm+nmTWuBr3h25w7eiG6S7iWW95cM6fn7y9bpE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id A79D5387087C for ; Fri, 29 Jan 2021 14:45:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A79D5387087C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-193-Vj7ITsDUOrGMhUCbplx0uQ-1; Fri, 29 Jan 2021 09:45:52 -0500 X-MC-Unique: Vj7ITsDUOrGMhUCbplx0uQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 12F1A1842140 for ; Fri, 29 Jan 2021 14:45:51 +0000 (UTC) Received: from [10.10.118.121] (ovpn-118-121.rdu2.redhat.com [10.10.118.121]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7BF1710016DB for ; Fri, 29 Jan 2021 14:45:50 +0000 (UTC) Subject: [PATCH] tree-optimization/98866 - Compile time hog in VRP To: gcc-patches Message-ID: Date: Fri, 29 Jan 2021 09:45:49 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Ranger spends a lot of time tracking pointer type ssa_names which are initialized to non-null, ie (a_2 = &foo). This turns out to be a waste of effort. Pointers can effectively  have one of 3 values we care about: VARYING, [0,0], or [1, +INF].   If an ssa_name is globally [0,0] or [1, +INF], the only "refinement" that can be made on an outgoing edge is to evaluate to UNDEFINED.    There is no need to track UNDEFINED on the un-taken edge as the branch will be folded and the edge removed.  The range will remain the same on the other edge. Initializing to [0,0] produces a singleton range, and constants like this tend to be propagated away anyway, so their usage patterns are less of an issue.   [1, +INF] however looks like a range which can be modified,  and we spend a lot of pointless time in this PR processing it. This patch extends current invariant tracking to also include pointers which evaluate to [1, +INF] at their definition, and thus will not be included in the on-entry cache, and resolves the compilation time issue. I also renamed the local member name as it now has a more specific definition. Bootstrapped on x86_64-pc-linux-gnu with no regressions. I'm not sure the current protocol for checking things in, so I will ask for blessing from the release managers:-)  OK for trunk? Andrew commit ca1d3735fd826c42e71b48c6d79240402fa4a6f9 Author: Andrew MacLeod Date: Fri Jan 29 09:23:48 2021 -0500 tree-optimization/98866 - Compile time hog in VRP Don't track [1, +INF] for pointer types, treat them as invariant for caching purposes as they cannot be further refined without evaluating to UNDEFINED. PR tree-optimization/98866 * gimple-range-gori.h (gori_map::set_range_invariant): New. (gori_map::m_maybe_invariant): Rename from all_outgoing. (gori_map::gori_map): Rename all_outgoing to m_maybe_invariant. (gori_map::is_export_p): Ditto. (gori_map::calculate_gori): Ditto. (gori_compute::set_range_invariant): New. * gimple-range-gori.h (gori_compute:set_range_invariant): New. * gimple-range.cc (gimple_ranger::range_of_stmt): Set range invariant for pointers evaluating to [1, +INF]. diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 65faa2d24d4..7f7f3dc0d69 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -232,13 +232,14 @@ public: bool is_export_p (tree name, basic_block bb = NULL); bool def_chain_in_export_p (tree name, basic_block bb); bitmap exports (basic_block bb); + void set_range_invariant (tree name); void dump (FILE *f); void dump (FILE *f, basic_block bb); private: bitmap_obstack m_bitmaps; vec m_outgoing; // BB: Outgoing ranges calculatable on edges - bitmap all_outgoing; // All outgoing ranges combined. + bitmap m_maybe_variant; // Names which might have outgoing ranges. void maybe_add_gori (tree name, basic_block bb); void calculate_gori (basic_block bb); }; @@ -251,7 +252,7 @@ gori_map::gori_map () m_outgoing.create (0); m_outgoing.safe_grow_cleared (last_basic_block_for_fn (cfun)); bitmap_obstack_initialize (&m_bitmaps); - all_outgoing = BITMAP_ALLOC (&m_bitmaps); + m_maybe_variant = BITMAP_ALLOC (&m_bitmaps); } // Free any memory the GORI map allocated. @@ -280,10 +281,18 @@ gori_map::is_export_p (tree name, basic_block bb) { // If no BB is specified, test if it is exported anywhere in the IL. if (!bb) - return bitmap_bit_p (all_outgoing, SSA_NAME_VERSION (name)); + return bitmap_bit_p (m_maybe_variant, SSA_NAME_VERSION (name)); return bitmap_bit_p (exports (bb), SSA_NAME_VERSION (name)); } +// Clear the m_maybe_variant bit so ranges will not be tracked for NAME. + +void +gori_map::set_range_invariant (tree name) +{ + bitmap_clear_bit (m_maybe_variant, SSA_NAME_VERSION (name)); +} + // Return true if any element in the def chain of NAME is in the // export list for BB. @@ -348,7 +357,7 @@ gori_map::calculate_gori (basic_block bb) maybe_add_gori (name, gimple_bb (stmt)); } // Add this bitmap to the aggregate list of all outgoing names. - bitmap_ior_into (all_outgoing, m_outgoing[bb->index]); + bitmap_ior_into (m_maybe_variant, m_outgoing[bb->index]); } // Dump the table information for BB to file F. @@ -447,7 +456,7 @@ gori_compute::gori_compute () m_gori_map = new gori_map; unsigned x, lim = last_basic_block_for_fn (cfun); // Calculate outgoing range info upfront. This will fully populate the - // all_outgoing bitmap which will help eliminate processing of names + // m_maybe_variant bitmap which will help eliminate processing of names // which never have their ranges adjusted. for (x = 0; x < lim ; x++) { @@ -996,6 +1005,14 @@ gori_compute::has_edge_range_p (tree name, edge e) || m_gori_map->def_chain_in_export_p (name, e->src)); } +// Clear the m_maybe_variant bit so ranges will not be tracked for NAME. + +void +gori_compute::set_range_invariant (tree name) +{ + m_gori_map->set_range_invariant (name); +} + // Dump what is known to GORI computes to listing file F. void diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h index 3b9db0d406b..48c746d1f37 100644 --- a/gcc/gimple-range-gori.h +++ b/gcc/gimple-range-gori.h @@ -72,6 +72,7 @@ public: ~gori_compute (); bool outgoing_edge_range_p (irange &r, edge e, tree name); bool has_edge_range_p (tree name, edge e = NULL); + void set_range_invariant (tree name); void dump (FILE *f); protected: virtual void ssa_range_in_bb (irange &r, tree name, basic_block bb); diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 029aaa58640..6158a754dd6 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -1072,6 +1072,12 @@ gimple_ranger::range_of_stmt (irange &r, gimple *s, tree name) // can sometimes get different results. See PR 97741. r.intersect (tmp); m_cache.set_global_range (name, r); + + // Pointers which resolve to non-zero at the defintion point do not need + // tracking in the cache as they will never change. See PR 98866. + if (POINTER_TYPE_P (TREE_TYPE (name)) && r.nonzero_p ()) + m_cache.set_range_invariant (name); + return true; }