From: Richard Biener Date: Tue, 12 Aug 2025 07:00:48 +0000 (+0200) Subject: tree-optimization/121514 - ICE with recent VN improvement X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a440b382e43203857de9195eb526c4a16f21ceb1;p=thirdparty%2Fgcc.git 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 --git a/gcc/testsuite/gcc.dg/torture/pr121514.c b/gcc/testsuite/gcc.dg/torture/pr121514.c new file mode 100644 index 00000000000..95b7a0b2439 --- /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 0f6760de4d4..3884f0fca7e 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; } }