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

commit r16-9097-ga55a425bde33b90f215abf079197771e2ba6f276
Author: Richard Biener <[email protected]>
Date:   Tue Jun 2 14:03:24 2026 +0200

    tree-optimization/125553 - ICE with VN trick
    
    The following avoids re-doing an earlier CSE when trying to handle
    a BIT_FIELD_REF as memory reference by combining it with a
    defining load.  This might (as in this case) result in double-insertion
    to the VN hashtables which rightfully ICEs.
    
            PR tree-optimization/125553
            * tree-ssa-sccvn.cc (visit_nary_op): Valueize the BIT_FIELD_REF
            operand before looking at its definition.
    
            * gcc.dg/torture/pr125553.c: New testcase.
    
    (cherry picked from commit a62132ff21b6cec68bbf27fc5802b4e0e381920e)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr125553.c | 22 ++++++++++++++++++++++
 gcc/tree-ssa-sccvn.cc                   |  7 ++++---
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr125553.c 
b/gcc/testsuite/gcc.dg/torture/pr125553.c
new file mode 100644
index 000000000000..6908b85f92f0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr125553.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+
+#include <stdint.h>
+
+typedef int64_t v8i64 __attribute__((vector_size(64)));
+int64_t g2, g17;
+void *g24;
+static v8i64 g25;
+
+void hash()
+{
+  v8i64 vec6;
+lbl_b3:
+  *(v8i64 *)g24 = g25;
+  uint64_t __ov_tmp_g17 = __builtin_sub_overflow(g2, g2, &__ov_tmp_g17);
+  g17 = __ov_tmp_g17;
+  g25 = vec6;
+  vec6 = *(v8i64 *)g24;
+  g2 = vec6[0];
+  goto lbl_b3;
+  g25[7];
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index e19beb439d20..ca3ce8546236 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -5779,9 +5779,10 @@ visit_nary_op (tree lhs, gassign *stmt)
     case BIT_FIELD_REF:
       if (TREE_CODE (TREE_OPERAND (rhs1, 0)) == SSA_NAME)
        {
-         tree op0 = TREE_OPERAND (rhs1, 0);
-         gassign *ass = dyn_cast <gassign *> (SSA_NAME_DEF_STMT (op0));
-         if (ass
+         tree op0 = vn_valueize (TREE_OPERAND (rhs1, 0));
+         gassign *ass;
+         if (TREE_CODE (op0) == SSA_NAME
+             && (ass = dyn_cast <gassign *> (SSA_NAME_DEF_STMT (op0)))
              && !gimple_has_volatile_ops (ass)
              && vn_get_stmt_kind (ass) == VN_REFERENCE)
            {

Reply via email to