tree-optimization/125553 - ICE with VN trick

Message ID 20260602132616.CF3C54BA2E12@sourceware.org
State Committed
Headers
Series tree-optimization/125553 - ICE with VN trick |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-aarch64-bootstrap fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap fail Patch failed to apply

Commit Message

Richard Biener June 2, 2026, 1:25 p.m. UTC
  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.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	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 | 22 ++++++++++++++++++++++
 gcc/tree-ssa-sccvn.cc                   |  7 ++++---
 2 files changed, 26 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr125553.c
  

Patch

diff --git a/gcc/testsuite/gcc.dg/torture/pr125553.c b/gcc/testsuite/gcc.dg/torture/pr125553.c
new file mode 100644
index 00000000000..6908b85f92f
--- /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 09b8a1cd446..98b837be01d 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -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)
 	    {