]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/122079 - PRE antic_compute doesn't converge
authorRichard Biener <rguenther@suse.de>
Wed, 1 Oct 2025 12:16:50 +0000 (14:16 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 2 Oct 2025 07:12:10 +0000 (09:12 +0200)
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.

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 [new file with mode: 0644]
gcc/tree-ssa-pre.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr122079-1.c b/gcc/testsuite/gcc.dg/torture/pr122079-1.c
new file mode 100644 (file)
index 0000000..0af01a5
--- /dev/null
@@ -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);
+}
index 64ffaca21aba1b869d4c079c4766a4bd860086fb..d08caab952a1b91517486e04002101fbfb9bd1fb 100644 (file)
@@ -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)