From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 33B0E3858C60 for ; Mon, 3 Jan 2022 11:00:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 33B0E3858C60 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-349-9oWlpwaCNq-K4uyDSI1P5Q-1; Mon, 03 Jan 2022 06:00:16 -0500 X-MC-Unique: 9oWlpwaCNq-K4uyDSI1P5Q-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 982C4363A4; Mon, 3 Jan 2022 11:00:15 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.2.16.169]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1B265752CE; Mon, 3 Jan 2022 11:00:14 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 203B0Bkd1335456 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 3 Jan 2022 12:00:11 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 203B0A411335455; Mon, 3 Jan 2022 12:00:10 +0100 Date: Mon, 3 Jan 2022 12:00:10 +0100 From: Jakub Jelinek To: Segher Boessenkool , Jeff Law , Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] shrink-wrapping: Don't call can_get_prologue unnecessarily [PR103860] Message-ID: <20220103110010.GT2646553@tucnak> Reply-To: Jakub Jelinek References: <20211230094332.GZ2646553@tucnak> <20211230100825.GL614@gate.crashing.org> MIME-Version: 1.0 In-Reply-To: <20211230100825.GL614@gate.crashing.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Mon, 03 Jan 2022 11:00:21 -0000 On Thu, Dec 30, 2021 at 04:08:25AM -0600, Segher Boessenkool wrote: > > The following simple patch makes sure we call can_get_prologue even after > > the last former iteration when vec is already empty and only break from > > the loop afterwards (and only if the updating of pro done because of > > !can_get_prologue didn't push anything into vec again). During the development of the above patch I've noticed that in many cases we call can_get_prologue often on the same pro again and again and again, we can have many basic blocks pushed into vec and if most of those don't require pro updates, i.e. basic_block bb = vec.pop (); if (!can_dup_for_shrink_wrapping (bb, pro, max_grow_size)) while (!dominated_by_p (CDI_DOMINATORS, bb, pro)) isn't true, then pro is can_get_prologue checked for each bb in the vec. The following simple patch just remembers which bb we've verified already and verifies again only when pro changes. Most of the patch is just reindentation. Ok for trunk if it passes bootstrap/regtest? 2022-01-03 Jakub Jelinek PR rtl-optimization/103860 * shrink-wrap.c (try_shrink_wrapping): Don't call can_get_prologue uselessly for blocks for which it has been called already. --- gcc/shrink-wrap.c.jj 2022-01-03 10:40:41.758156451 +0100 +++ gcc/shrink-wrap.c 2022-01-03 11:43:36.200744640 +0100 @@ -781,14 +781,20 @@ try_shrink_wrapping (edge *entry_edge, r unsigned max_grow_size = get_uncond_jump_length (); max_grow_size *= param_max_grow_copy_bb_insns; + basic_block checked_pro = NULL; + while (pro != entry) { - while (pro != entry && !can_get_prologue (pro, prologue_clobbered)) + if (pro != checked_pro) { - pro = get_immediate_dominator (CDI_DOMINATORS, pro); + while (pro != entry && !can_get_prologue (pro, prologue_clobbered)) + { + pro = get_immediate_dominator (CDI_DOMINATORS, pro); - if (bitmap_set_bit (bb_with, pro->index)) - vec.quick_push (pro); + if (bitmap_set_bit (bb_with, pro->index)) + vec.quick_push (pro); + } + checked_pro = pro; } if (vec.is_empty ()) Jakub