https://gcc.gnu.org/g:a440b382e43203857de9195eb526c4a16f21ceb1

commit r16-3161-ga440b382e43203857de9195eb526c4a16f21ceb1
Author: Richard Biener <rguent...@suse.de>
Date:   Tue Aug 12 09:00:48 2025 +0200

    tree-optimization/121514 - ICE with recent VN improvement
    
    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.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr121514.c | 20 ++++++++++++++++++++
 gcc/tree-ssa-sccvn.cc                   | 12 ++++++++----
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr121514.c 
b/gcc/testsuite/gcc.dg/torture/pr121514.c
new file mode 100644
index 000000000000..95b7a0b24398
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr121514.c
@@ -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;
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 0f6760de4d42..3884f0fca7e5 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -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;
                    }
                }

Reply via email to