]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/125553 - ICE with VN trick
authorRichard Biener <rguenther@suse.de>
Tue, 2 Jun 2026 12:03:24 +0000 (14:03 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 2 Jun 2026 13:26:03 +0000 (15:26 +0200)
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.

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

diff --git a/gcc/testsuite/gcc.dg/torture/pr125553.c b/gcc/testsuite/gcc.dg/torture/pr125553.c
new file mode 100644 (file)
index 0000000..6908b85
--- /dev/null
@@ -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];
+}
index 09b8a1cd4466f25c1788891487ada20b788f96cb..98b837be01d0af217170618093f0eb93edf44afa 100644 (file)
@@ -5778,9 +5778,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)
            {