]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/122016 - PRE insertion breaks abnormal coalescing
authorRichard Biener <rguenther@suse.de>
Mon, 22 Sep 2025 08:14:31 +0000 (10:14 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 22 Sep 2025 09:42:28 +0000 (11:42 +0200)
When PRE asks VN to simplify a NARY but not insert, that bypasses
the abnormal guard in maybe_push_res_to_seq and we blindly accept
new uses of abnormals.  The following fixes this.

PR tree-optimization/122016
* tree-ssa-sccvn.cc (vn_nary_simplify): Do not use the
simplified expression when it references abnormals.

* gcc.dg/torture/pr122016.c: New testcase.

gcc/testsuite/gcc.dg/torture/pr122016.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr122016.c b/gcc/testsuite/gcc.dg/torture/pr122016.c
new file mode 100644 (file)
index 0000000..027a63d
--- /dev/null
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-ftree-pre" } */
+
+int merge_parse_args_argc;
+char merge_parse_args_argv_0;
+int strncmp(char *, char *, long);
+void _setjmp();
+typedef enum { FALSE, TRUE } boool;
+void directory_exists();
+void merge_parse_args() {
+  int i;
+  boool help_found = FALSE;
+  while (i < merge_parse_args_argc && !help_found) {
+    if (strncmp("", &merge_parse_args_argv_0, 2))
+      help_found = TRUE;
+    else {
+      for (;;) {
+        _setjmp();
+        break;
+      }
+      i++;
+      directory_exists();
+    }
+    i++;
+  }
+  _setjmp();
+}
index 8ec0a199705cef67e4a07342a3b273c1d300b51d..246fa082561ed46bf45a592193f4d0c6d4297e04 100644 (file)
@@ -2622,6 +2622,12 @@ vn_nary_simplify (vn_nary_op_t nary)
                      nary->type, nary->length);
   memcpy (op.ops, nary->op, sizeof (tree) * nary->length);
   tree res = vn_nary_build_or_lookup_1 (&op, false, true);
+  /* Do not update *NARY with a simplified result that contains abnormals.
+     This matches what maybe_push_res_to_seq does when requesting insertion.  */
+  for (unsigned i = 0; i < op.num_ops; ++i)
+    if (TREE_CODE (op.ops[i]) == SSA_NAME
+       && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (op.ops[i]))
+      return res;
   if (op.code.is_tree_code ()
       && op.num_ops <= nary->length
       && (tree_code) op.code != CONSTRUCTOR)