https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96091

            Bug ID: 96091
           Summary: ICE during dom: tree check: expected integer_cst, have
                    poly_int_cst in to_wide, at tree.h:5911
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: qianchao9 at huawei dot com
  Target Milestone: ---

Created attachment 48840
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48840&action=edit
fix-gimple-fold

Compiling this with -S -ftree-vectorize -march=armv8.5-a+sve -O2
-mno-strict-align -ftracer:

void foo(short a[], short m)
{
  int i, j;
  int f1[10];
  short nc;

  nc = m + 1;
  for (i = 0, j = m; i < nc; i++, j--)
    {
      a[i] = f1[i];
      a[j] = i;
    }
  return;
}

gives:

during GIMPLE pass: dom
testcase.c: In function ‘foo’:
testcase.c:1:6: internal compiler error: tree check: expected integer_cst, have
poly_int_cst in to_wide, at tree.h:5911
    1 | void foo(short a[], short m)
      |      ^~~
0x17714fb tree_check_failed(tree_node const*, char const*, int, char const*,
...)
        ../../gcc/tree.c:9685
0x9ebf7f tree_int_cst_elt_check(tree_node const*, int, char const*, int, char
const*)
        ../../gcc/tree.h:3491
0xa3d5bf wi::to_wide(tree_node const*)
        ../../gcc/tree.h:5911
0x17787ff vector_cst_int_elt(tree_node const*, unsigned int)
        ../../gcc/tree.c:10964
0x1778a33 vector_cst_elt(tree_node const*, unsigned int)
        ../../gcc/tree.c:10991
0xdfa553 vec_cst_ctor_to_array
        ../../gcc/fold-const.c:9795
0xdfa9d7 fold_vec_perm(tree_node*, tree_node*, tree_node*, vec_perm_indices
const&)
        ../../gcc/fold-const.c:9836
0x1c85c27 generic_simplify_VEC_PERM_EXPR
        /home/qianchao/opt/gccRepo/gcc/build/gcc/generic-match.c:75993
0x1c86c37 generic_simplify(unsigned int, tree_code, tree_node*, tree_node*,
tree_node*, tree_node*)
        /home/qianchao/opt/gccRepo/gcc/build/gcc/generic-match.c:76143
0xe0703f fold_ternary_loc(unsigned int, tree_code, tree_node*, tree_node*,
tree_node*, tree_node*)
        ../../gcc/fold-const.c:12116
0x190eb43 gimple_resimplify3
        ../../gcc/gimple-match-head.c:354
0x1910bfb gimple_simplify(gimple*, gimple_match_op*, gimple**, tree_node*
(*)(tree_node*), tree_node* (*)(tree_node*))
        ../../gcc/gimple-match-head.c:1001
0xe86493 gimple_fold_stmt_to_constant_1(gimple*, tree_node* (*)(tree_node*),
tree_node* (*)(tree_node*))
        ../../gcc/gimple-fold.c:6329
0x1658c1f record_temporary_equivalences_from_stmts_at_dest
        ../../gcc/tree-ssa-threadedge.c:362
0x165a8db thread_through_normal_block
        ../../gcc/tree-ssa-threadedge.c:1064
0x165b363 thread_across_edge
        ../../gcc/tree-ssa-threadedge.c:1372
0x165b537 thread_outgoing_edges(basic_block_def*, gcond*, const_and_copies*,
avail_exprs_stack*, evrp_range_analyzer*, tree_node* (*)(gimple*, gimple*,
avail_exprs_stack*,   basic_block_def*))
        ../../gcc/tree-ssa-threadedge.c:1440
0x14f53bb dom_opt_dom_walker::after_dom_children(basic_block_def*)
        ../../gcc/tree-ssa-dom.c:1548
0x21663b7 dom_walker::walk(basic_block_def*)
        ../../gcc/domwalk.c:352
0x14f2df7 execute
        ../../gcc/tree-ssa-dom.c:724
...

The testcase failed to get unencoded elts in vector_cst during dom3, as the
vector_cst needs integer_cst elements. Howerver, the reason for ICE is that we
should not fold vector constructor that contains poly_int_cst elements to
vector_cst.

the following fixes the latent bug - we faild to limit folding poly_int_cst
constructor

diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 4e3de95d2d2..679a6770676 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -438,7 +438,7 @@ fold_gimple_assign (gimple_stmt_iterator *si)
            tree val;

            FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), i, val)
-             if (! CONSTANT_CLASS_P (val))
+             if (! CONSTANT_CLASS_P (val) || POLY_INT_CST_P (val))
                return NULL_TREE;

            return build_vector_from_ctor (TREE_TYPE (rhs),

Reply via email to