]> git.ipfire.org Git - thirdparty/gcc.git/commit
vect: Avoid external fallback while operand swap retry is possible
authorZhongyao Chen <chen.zhongyao@zte.com.cn>
Wed, 3 Jun 2026 12:44:59 +0000 (20:44 +0800)
committerZhongyao Chen <chen.zhongyao@zte.com.cn>
Thu, 11 Jun 2026 01:01:32 +0000 (01:01 +0000)
commit9f8409f2e2c28f64bf6a584bc81afcae0f084785
tree2e310e27dd36c5d121dd609b0254daa501442845
parent3f33c69f7b7520c49bfca26c328ba4a8b126337f
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.

Signed-off-by: Zhongyao Chen <chen.zhongyao@zte.com.cn>
gcc/testsuite/gcc.dg/vect/pr125567.c [new file with mode: 0644]
gcc/tree-vect-slp.cc