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

            Bug ID: 112458
           Summary: SLP permute optimization issue
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

I'm facing an ICE on the vect-slp-only branch when compiling
gcc.target/i386/pr98928.c with --param vect-single-lane-slp=1, I get

during GIMPLE pass: vect
/space/rguenther/src/gcc-clean/gcc/testsuite/gcc.target/i386/pr98928.c: In
function 'main':
/space/rguenther/src/gcc-clean/gcc/testsuite/gcc.target/i386/pr98928.c:11:6:
internal compiler error: in operator[], at vec.h:910
0x1a69a9e vec<slpg_partition_info, va_heap, vl_embed>::operator[](unsigned int)
        /space/rguenther/src/gcc-clean/gcc/vec.h:910
0x1a646f4 vec<slpg_partition_info, va_heap, vl_ptr>::operator[](unsigned int)
        /space/rguenther/src/gcc-clean/gcc/vec.h:1599
0x1a4e5b2 vect_optimize_slp_pass::change_vec_perm_layout(_slp_tree*,
vec<std::pair<unsigned int, unsigned int>, va_heap, vl_ptr>&, int, unsigned
int)
        /space/rguenther/src/gcc-clean/gcc/tree-vect-slp.cc:4779
0x1a4e746 vect_optimize_slp_pass::internal_node_cost(_slp_tree*, int, unsigned
int)
        /space/rguenther/src/gcc-clean/gcc/tree-vect-slp.cc:4827
0x1a503c7 vect_optimize_slp_pass::forward_pass()
        /space/rguenther/src/gcc-clean/gcc/tree-vect-slp.cc:5419
0x1a527d5 vect_optimize_slp_pass::run()
        /space/rguenther/src/gcc-clean/gcc/tree-vect-slp.cc:5953

and the issue is we end up in change_vec_perm_layout for

/space/rguenther/src/gcc-clean/gcc/testsuite/gcc.target/i386/pr98928.c:11:6:
note: node 0x462f8d0 (max_nunits=1, refcnt=1) vector(8) float
/space/rguenther/src/gcc-clean/gcc/testsuite/gcc.target/i386/pr98928.c:11:6:
note: op: VEC_PERM_EXPR
/space/rguenther/src/gcc-clean/gcc/testsuite/gcc.target/i386/pr98928.c:11:6:
note:      { }
/space/rguenther/src/gcc-clean/gcc/testsuite/gcc.target/i386/pr98928.c:11:6:
note:      lane permutation { 0[0] 1[0] }
/space/rguenther/src/gcc-clean/gcc/testsuite/gcc.target/i386/pr98928.c:11:6:
note:      children 0x462ee30 0x462ef40

where the first child is a constant def:

/space/rguenther/src/gcc-clean/gcc/testsuite/gcc.target/i386/pr98928.c:11:6:
note: node (constant) 0x462ee30 (max_nunits=1, refcnt=1) vector(8) float
/space/rguenther/src/gcc-clean/gcc/testsuite/gcc.target/i386/pr98928.c:11:6:
note:      { 0.0 }

and the second child is internal:

/space/rguenther/src/gcc-clean/gcc/testsuite/gcc.target/i386/pr98928.c:11:6:
note: node 0x462ef40 (max_nunits=16, refcnt=1) vector(8) float
/space/rguenther/src/gcc-clean/gcc/testsuite/gcc.target/i386/pr98928.c:11:6:
note: op template: patt_53 = patt_26 ? _93 : 0.0;
/space/rguenther/src/gcc-clean/gcc/testsuite/gcc.target/i386/pr98928.c:11:6:
note:      stmt 0 patt_53 = patt_26 ? _93 : 0.0;
/space/rguenther/src/gcc-clean/gcc/testsuite/gcc.target/i386/pr98928.c:11:6:
note:      children 0x462efc8 0x462f5a0 0x462f738

now, for the constant def child the partition number is -1 and thus

4777              slp_tree in_node = SLP_TREE_CHILDREN (node)[entry.first];
4778              unsigned int in_partition_i =
m_vertices[in_node->vertex].partition;
4779              this_in_layout_i = m_partitions[in_partition_i].layout;

we crash here.  I wonder where to fend this off or where exactly we
assume all children of a VEC_PERM are either internal or not.  I've seen

      /* Check that the child nodes support the chosen layout.  Checking
         the first child is enough, since any second child would have the
         same shape.  */
      auto first_child = SLP_TREE_CHILDREN (node)[0];
      if (in_layout_i > 0
          && !is_compatible_layout (first_child, in_layout_i))
        return -1;

but it doesn't apply here since in_layout_i is -1.

Reply via email to