https://gcc.gnu.org/g:77d01927bd7c989d431035251a5c196fe39bcec9

commit r15-7498-g77d01927bd7c989d431035251a5c196fe39bcec9
Author: Richard Biener <rguent...@suse.de>
Date:   Wed Feb 12 15:01:53 2025 +0100

    tree-optimization/118817 - fix ICE with VN CTOR simplification
    
    The representation of CONSTRUCTOR nodes in VN NARY and gimple_match_op
    do not agree so do not attempt to marshal between them.
    
            PR tree-optimization/118817
            * tree-ssa-sccvn.cc (vn_nary_simplify): Do not process
            CONSTRUCTOR NARY or update from CONSTRUCTOR simplified
            gimple_match_op.
    
            * gcc.dg/pr118817.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/pr118817.c | 14 ++++++++++++++
 gcc/tree-ssa-sccvn.cc           |  9 +++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr118817.c b/gcc/testsuite/gcc.dg/pr118817.c
new file mode 100644
index 000000000000..6cfb424dbf4f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr118817.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+typedef int v4si __attribute__((vector_size (sizeof(int) * 4)));
+
+v4si x;
+
+void foo (int flag)
+{
+  v4si tem = (v4si) { 0, 0, 0, 0 };
+  if (flag)
+    tem = (v4si) { flag };
+  x = __builtin_shufflevector (tem, tem, 0, 0, 0, 0);
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 06f6b0ccd724..8bb45780a981 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -2604,13 +2604,18 @@ vn_nary_build_or_lookup (gimple_match_op *res_op)
 tree
 vn_nary_simplify (vn_nary_op_t nary)
 {
-  if (nary->length > gimple_match_op::MAX_NUM_OPS)
+  if (nary->length > gimple_match_op::MAX_NUM_OPS
+      /* For CONSTRUCTOR the vn_nary_op_t and gimple_match_op representation
+        does not match.  */
+      || nary->opcode == CONSTRUCTOR)
     return NULL_TREE;
   gimple_match_op op (gimple_match_cond::UNCOND, nary->opcode,
                      nary->type, nary->length);
   memcpy (op.ops, nary->op, sizeof (tree) * nary->length);
   tree res = vn_nary_build_or_lookup_1 (&op, false, true);
-  if (op.code.is_tree_code () && op.num_ops <= nary->length)
+  if (op.code.is_tree_code ()
+      && op.num_ops <= nary->length
+      && (tree_code) op.code != CONSTRUCTOR)
     {
       nary->opcode = (tree_code) op.code;
       nary->length = op.num_ops;

Reply via email to