The following fixes another case of us pruning from the value set
based on the expression set after expression removal when the
maximum expression set is involved.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

        PR tree-optimization/122079
        * tree-ssa-pre.cc (prune_clobbered_mems): Do not prune
        values when the maximum expression set is involved.

        * gcc.dg/torture/pr122079-1.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr122079-1.c | 27 +++++++++++++++++++++++
 gcc/tree-ssa-pre.cc                       |  8 +++++--
 2 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr122079-1.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr122079-1.c 
b/gcc/testsuite/gcc.dg/torture/pr122079-1.c
new file mode 100644
index 00000000000..0af01a581a1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr122079-1.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fcode-hoisting" } */
+
+int a, b, c;
+void e(int *f) {
+  int d = 0;
+  if (f)
+    goto g;
+  goto h;
+i:
+  d = 1 + f[0];
+j:
+  if (c)
+    goto h;
+k:
+  if (b)
+    goto i;
+  if (a)
+    goto j;
+g:
+  if (d + f[0])
+    goto k;
+h:
+  int l[] = {f[0]};
+  if (a)
+    e(l);
+}
diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc
index 64ffaca21ab..d08caab952a 100644
--- a/gcc/tree-ssa-pre.cc
+++ b/gcc/tree-ssa-pre.cc
@@ -2049,8 +2049,12 @@ prune_clobbered_mems (bitmap_set_t set, basic_block 
block, bool clean_traps)
      the bitmap_find_leader way to see if there's still an expression
      for it.  For some ratio of to be removed values and number of
      values/expressions in the set this might be faster than rebuilding
-     the value-set.  */
-  if (any_removed)
+     the value-set.
+     Note when there's a MAX solution on one edge (clean_traps) do not
+     prune values as we need to consider the resulting expression set MAX
+     as well.  This avoids a later growing ANTIC_IN value-set during
+     iteration, when the explicitly represented expression set grows. */
+  if (any_removed && !clean_traps)
     {
       bitmap_clear (&set->values);
       FOR_EACH_EXPR_ID_IN_SET (set, i, bi)
-- 
2.43.0

Reply via email to