]> git.ipfire.org Git - thirdparty/gcc.git/commit
vect: Avoid divide by zero for permutes of extern VLA vectors
authorRichard Sandiford <richard.sandiford@arm.com>
Thu, 10 Oct 2024 14:15:26 +0000 (15:15 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Thu, 10 Oct 2024 14:15:26 +0000 (15:15 +0100)
commit9bd19ff515c95af71b29bc6e232785532afa6823
treea9a888c750b3872c0f42e45df0f7a9ca9175493c
parentc1b2100e736c8ad80479fa6417db760695a00256
vect: Avoid divide by zero for permutes of extern VLA vectors

My recent VLA SLP patches caused a regression with cross compilers
in gcc.dg/torture/neon-sve-bridge.c.  There we have a VEC_PERM_EXPR
created from two BIT_FIELD_REFs, with the child node being an
external VLA vector:

note:   node 0x3704a70 (max_nunits=1, refcnt=2) vector(2) long int
note:   op: VEC_PERM_EXPR
note:          stmt 0 val1Return_9 = BIT_FIELD_REF <sveReturn_8, 64, 0>;
note:          stmt 1 val2Return_10 = BIT_FIELD_REF <sveReturn_8, 64, 64>;
note:          lane permutation { 0[0] 0[1] }
note:          children 0x3704b08
note:   node (external) 0x3704b08 (max_nunits=1, refcnt=1) svint64_t
note:          { }

For this kind of external node, the SLP_TREE_LANES is normally
the total number of lanes in the vector, but it is zero if the
vector has variable length:

      auto nunits = TYPE_VECTOR_SUBPARTS (SLP_TREE_VECTYPE (vnode));
      unsigned HOST_WIDE_INT const_nunits;
      if (nunits.is_constant (&const_nunits))
SLP_TREE_LANES (vnode) = const_nunits;

This led to division by zero in:

      /* Check whether the output has N times as many lanes per vector.  */
      else if (constant_multiple_p (SLP_TREE_LANES (node) * op_nunits,
    SLP_TREE_LANES (child) * nunits,
    &this_unpack_factor)
       && (i == 0 || unpack_factor == this_unpack_factor))
unpack_factor = this_unpack_factor;

No repetition takes place for this kind of external node, so this
patch goes with Richard's suggestion to check for external nodes
that have no scalar statements.

This didn't show up for my native testing since division by zero
doesn't trap on AArch64.

gcc/
* tree-vect-slp.cc (vectorizable_slp_permutation_1): Set repeating_p
to false if we have an external node for a pre-existing vector.
gcc/tree-vect-slp.cc