vect: Avoid external fallback while operand swap retry is possible
When building operand zero of a commutative BB SLP node, a failed child
discovery may build operands from scalars right away. That hides the failure
from the existing retry path, even when retrying with swapped operands could
still fix the current node.
Track the distance from operand-zero subtree discovery to the nearest upthread
swap opportunity. Skip scalar fallback only when that distance is exactly one,
so discovery reaches the retry path first.
My local tests show no regression for vect.exp, only a few for rvv.exp,
but those are reasonable, just need update test expectations.
PR tree-optimization/125567
gcc/
* tree-vect-slp.cc (least_upthread_swappable_op_distance): New.
(vect_build_slp_tree_2): Compute swap checks before building operand
zero. Skip external fallback while swap retry is possible. Reuse the
swap checks in the retry path.
gcc/testsuite/
* gcc.dg/vect/pr125567.c: New test.