]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/121514 - ICE with recent VN improvement
authorRichard Biener <rguenther@suse.de>
Tue, 12 Aug 2025 07:00:48 +0000 (09:00 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 12 Aug 2025 08:19:46 +0000 (10:19 +0200)
When inserting a compensation stmt during VN we are making sure to
register the result for the original stmt into the hashtable so
VN iteration has the chance to converge and we avoid inserting
another copy each time.  But the implementation doesn't work for
non-SSA name values, and is also not necessary for constants since
we did not insert anything for them.  The following appropriately
guards the calls to vn_nary_op_insert_stmt as was already done
in one place.

PR tree-optimization/121514
* tree-ssa-sccvn.cc (visit_nary_op): Only call
vn_nary_op_insert_stmt for SSA name result.

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

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

diff --git a/gcc/testsuite/gcc.dg/torture/pr121514.c b/gcc/testsuite/gcc.dg/torture/pr121514.c
new file mode 100644 (file)
index 0000000..95b7a0b
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile { target int128 } } */
+/* { dg-additional-options "-Wno-psabi" } */
+
+typedef unsigned U __attribute__((__vector_size__(64)));
+typedef char V __attribute__((vector_size(64)));
+typedef __int128 W __attribute__((vector_size(64)));
+char c;
+int i;
+U u;
+V v;
+W w;
+
+W
+foo()
+{
+  u = 0 <= u;
+  __builtin_mul_overflow(i, c, &u[7]);
+  v ^= (V)u;
+  return (W)u + w;
+}
index 0f6760de4d42284634551900fb4bbd795965b507..3884f0fca7e5962bdad1b9c3abd613038235e1b4 100644 (file)
@@ -5593,7 +5593,8 @@ visit_nary_op (tree lhs, gassign *stmt)
                          if (result)
                            {
                              bool changed = set_ssa_val_to (lhs, result);
-                             vn_nary_op_insert_stmt (stmt, result);
+                             if (TREE_CODE (result) == SSA_NAME)
+                               vn_nary_op_insert_stmt (stmt, result);
                              return changed;
                            }
                        }
@@ -5609,7 +5610,8 @@ visit_nary_op (tree lhs, gassign *stmt)
                          if (result)
                            {
                              bool changed = set_ssa_val_to (lhs, result);
-                             vn_nary_op_insert_stmt (stmt, result);
+                             if (TREE_CODE (result) == SSA_NAME)
+                               vn_nary_op_insert_stmt (stmt, result);
                              return changed;
                            }
                        }
@@ -5689,7 +5691,8 @@ visit_nary_op (tree lhs, gassign *stmt)
                      if (result)
                        {
                          bool changed = set_ssa_val_to (lhs, result);
-                         vn_nary_op_insert_stmt (stmt, result);
+                         if (TREE_CODE (result) == SSA_NAME)
+                           vn_nary_op_insert_stmt (stmt, result);
                          return changed;
                        }
                    }
@@ -5727,7 +5730,8 @@ visit_nary_op (tree lhs, gassign *stmt)
                  if (result)
                    {
                      bool changed = set_ssa_val_to (lhs, result);
-                     vn_nary_op_insert_stmt (stmt, result);
+                     if (TREE_CODE (result) == SSA_NAME)
+                       vn_nary_op_insert_stmt (stmt, result);
                      return changed;
                    }
                }