Improve backward threading with switches.
authorAldy Hernandez <aldyh@redhat.com>
Thu, 28 Oct 2021 09:44:13 +0000 (11:44 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Thu, 28 Oct 2021 12:30:06 +0000 (14:30 +0200)
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).

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
gcc/testsuite/gcc.dg/tree-ssa/vrp113.c
gcc/tree-ssa-threadbackward.c

index f25ea9c..dc5021a 100644 (file)
@@ -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);
index ab8d91e..dfe4989 100644 (file)
@@ -13,5 +13,3 @@ int f(int a) {
       case 7: return 19;
     }
 }
-
-/* { dg-final { scan-tree-dump "return 3;" "vrp1" { xfail *-*-* } } } */
index 6c1b159..456effc 100644 (file)
@@ -195,11 +195,11 @@ back_threader::find_taken_edge_switch (const vec<basic_block> &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.