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 A6ABF385803F for ; Thu, 28 Oct 2021 12:32:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A6ABF385803F 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-143-TgbRtzPQOkWbVk-dJvhPNQ-1; Thu, 28 Oct 2021 08:32:32 -0400 X-MC-Unique: TgbRtzPQOkWbVk-dJvhPNQ-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 29881A40C1; Thu, 28 Oct 2021 12:32:31 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.193.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B73465DF56; Thu, 28 Oct 2021 12:32:22 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.16.1/8.15.2) with ESMTPS id 19SCWLT8498151 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 28 Oct 2021 14:32:21 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 19SCWLoZ498150; Thu, 28 Oct 2021 14:32:21 +0200 From: Aldy Hernandez To: GCC patches Subject: [COMMITTED] Improve backward threading with switches. Date: Thu, 28 Oct 2021 14:32:15 +0200 Message-Id: <20211028123215.498066-2-aldyh@redhat.com> In-Reply-To: <20211028123215.498066-1-aldyh@redhat.com> References: <20211028123215.498066-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-13.0 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_H4, 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: Thu, 28 Oct 2021 12:32:37 -0000 We've been essentially using find_taken_edge_switch_expr() in the backward threader, but this is suboptimal because said function only works with singletons. VRP has a much smarter find_case_label_range that works with ranges. Tested on x86-64 Linux with: a) Bootstrap & regtests. b) Verifying we get more threads than before. c) Asserting that the new code catches everything the old one code caught (over a set of bootstrap .ii files). Committed as obvious. gcc/ChangeLog: * tree-ssa-threadbackward.c (back_threader::find_taken_edge_switch): Use find_case_label_range instead of find_taken_edge. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/vrp106.c: Adjust for threading. * gcc.dg/tree-ssa/vrp113.c: Same. --- gcc/testsuite/gcc.dg/tree-ssa/vrp106.c | 4 ++-- gcc/testsuite/gcc.dg/tree-ssa/vrp113.c | 2 -- gcc/tree-ssa-threadbackward.c | 8 ++++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp106.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp106.c index f25ea9c3826..dc5021a57b5 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/vrp106.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp106.c @@ -1,6 +1,6 @@ /* PR tree-optimization/18046 */ -/* { dg-options "-O2 -fdump-tree-vrp-thread1-details" } */ -/* { dg-final { scan-tree-dump-times "Threaded jump" 1 "vrp-thread1" } } */ +/* { dg-options "-O2 -fdump-tree-ethread-details" } */ +/* { dg-final { scan-tree-dump-times "Registering jump thread" 1 "ethread" } } */ /* During VRP we expect to thread the true arm of the conditional through the switch and to the BB that corresponds to the 7 ... 9 case label. */ extern void foo (void); diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp113.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp113.c index ab8d91e0f10..dfe4989d313 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/vrp113.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp113.c @@ -13,5 +13,3 @@ int f(int a) { case 7: return 19; } } - -/* { dg-final { scan-tree-dump "return 3;" "vrp1" { xfail *-*-* } } } */ diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-threadbackward.c index 6c1b15904ce..456effca5e1 100644 --- a/gcc/tree-ssa-threadbackward.c +++ b/gcc/tree-ssa-threadbackward.c @@ -195,11 +195,11 @@ back_threader::find_taken_edge_switch (const vec &path, if (r.varying_p ()) return NULL; - tree val; - if (r.singleton_p (&val)) - return ::find_taken_edge (gimple_bb (sw), val); + tree label = find_case_label_range (sw, &r); + if (!label) + return NULL; - return NULL; + return find_edge (gimple_bb (sw), label_to_block (cfun, CASE_LABEL (label))); } // Same as find_taken_edge, but for paths ending in a GIMPLE_COND. -- 2.31.1