]> gcc.gnu.org Git - gcc.git/commitdiff
tree-optimization/109849 - fix fallout of PRE hoisting change
authorRichard Biener <rguenther@suse.de>
Wed, 24 May 2023 10:36:28 +0000 (12:36 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 24 May 2023 11:17:10 +0000 (13:17 +0200)
The PR109849 fix made us no longer hoist some memory loads because
of the expression set intersection.  We can still avoid to compute
the union by simply taking the first sets expressions and leave
the pruning of expressions with values not suitable for hoisting
to sorted_array_from_bitmap_set.

PR tree-optimization/109849
* tree-ssa-pre.cc (do_hoist_insertion): Do not intersect
expressions but take the first sets.

* gcc.dg/tree-ssa/ssa-hoist-9.c: New testcase.

gcc/testsuite/gcc.dg/tree-ssa/ssa-hoist-9.c [new file with mode: 0644]
gcc/tree-ssa-pre.cc

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-hoist-9.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-hoist-9.c
new file mode 100644 (file)
index 0000000..388f79f
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-pre-stats" } */
+
+int foo (int flag, int * __restrict a, int * __restrict b)
+{
+  int res;
+  if (flag)
+    res = *a + *b;
+  else
+    {
+      res = *a;
+      *a = 1;
+      res += *b;
+    }
+  return res;
+}
+
+/* { dg-final { scan-tree-dump "HOIST inserted: 3" "pre" } } */
+/* { dg-final { scan-tree-dump-times " = \\\*" 2 "pre" } } */
+/* { dg-final { scan-tree-dump-times " = \[^\r\n\]* \\\+ \[^\r\n\]*;" 1 "pre" } } */
index b1ceea90a8e06915e3fdd60e0f307b2728ccec77..7bbfa5ac43db211e4b1ff3d5215bb91ccd99b2c9 100644 (file)
@@ -3625,8 +3625,9 @@ do_hoist_insertion (basic_block block)
 
   /* We have multiple successors, compute ANTIC_OUT by taking the intersection
      of all of ANTIC_IN translating through PHI nodes.  Note we do not have to
-     worry about iteration stability here so just intersect the expression sets
-     as well.  This is a simplification of what we do in compute_antic_aux.  */
+     worry about iteration stability here so just use the expression set
+     from the first set and prune that by sorted_array_from_bitmap_set.
+     This is a simplification of what we do in compute_antic_aux.  */
   bitmap_set_t ANTIC_OUT = bitmap_set_new ();
   bool first = true;
   FOR_EACH_EDGE (e, ei, block->succs)
@@ -3641,15 +3642,10 @@ do_hoist_insertion (basic_block block)
          bitmap_set_t tmp = bitmap_set_new ();
          phi_translate_set (tmp, ANTIC_IN (e->dest), e);
          bitmap_and_into (&ANTIC_OUT->values, &tmp->values);
-         bitmap_and_into (&ANTIC_OUT->expressions, &tmp->expressions);
          bitmap_set_free (tmp);
        }
       else
-       {
-         bitmap_and_into (&ANTIC_OUT->values, &ANTIC_IN (e->dest)->values);
-         bitmap_and_into (&ANTIC_OUT->expressions,
-                          &ANTIC_IN (e->dest)->expressions);
-       }
+       bitmap_and_into (&ANTIC_OUT->values, &ANTIC_IN (e->dest)->values);
     }
 
   /* Compute the set of hoistable expressions from ANTIC_OUT.  First compute
This page took 0.087451 seconds and 5 git commands to generate.