[llvm] [SLP]Vectorize unique scalars of splat gather nodes as separate subtrees (PR #218250)
Ryan Buchner via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 29 19:00:00 PDT 2026
bababuck wrote:
Sorry I am not intending to block progress with my concerns. One option would be to drop the gather sub-tree entirely in cases where some of the gathers are trimmed, and then pick up the corner cases in a future MR. My understanding is the change that you added to fix the above issue is to cost after trimming to decide whether or not to keep the partial gather. However, I'm still seeing cases where we end up with seemingly unprofitable subtrees (and I don't entirely understand why, this case doesn't seem to hit the `BVCost` check when I run with `gdb`). Though I admit there could be an interaction with `slp-threshold` that I am missing, I am intending to use `slp-threshold` to make the test writing easier for myself.
`opt -passes=slp-vectorizer -S -mtriple=riscv64 --mattr=+v,+zvl256b -slp-threshold=-7`
```
define void @splat_trim(ptr %A, ptr %C, ptr %D, ptr %F, ptr %S, ptr %E, ptr %B) {
entry:
%A0 = load i64, ptr %A, align 8
%B0 = load i64, ptr %B, align 8
%C0 = load i64, ptr %C, align 8
%D0 = load i64, ptr %D, align 8
%E0 = load i64, ptr %E, align 8
%F0 = load i64, ptr %F, align 8
%v1 = add i64 1, %A0
%v2 = add i64 1, %B0
%v3 = add i64 1, %E0
%AS0 = add i64 %v1, %v2
%AS1 = add i64 %v1, %v2
%AS2 = add i64 %v1, %v2
%AS3 = sub i64 %v1, %v2
%Sh0 = shl i64 %AS0, %C0
%Sh1 = lshr i64 %AS1, %D0
%Sh2 = lshr i64 %AS2, %E0
%Sh3 = shl i64 %AS3, %F0
%AS10 = add i64 %Sh0, %C0
%AS11 = add i64 %Sh1, %D0
%AS12 = add i64 %Sh3, %F0
%AS13 = sub i64 %Sh2, %E0
%AS20 = add i64 %AS10, 1
%AS21 = add i64 %AS11, 1
%AS22 = add i64 %AS12, 1
%AS23 = add i64 %AS13, 1
%Add0 = add i64 %AS20, %v3
%Add1 = add i64 %AS21, %v2
%Add2 = add i64 %AS22, %v3
%Add3 = add i64 %AS23, %v3
%idxS1 = getelementptr inbounds i64, ptr %S, i64 1
%idxS2 = getelementptr inbounds i64, ptr %S, i64 2
%idxS3 = getelementptr inbounds i64, ptr %S, i64 3
store i64 %Add0, ptr %S, align 8
store i64 %Add1, ptr %idxS1, align 8
store i64 %Add2, ptr %idxS2, align 8
store i64 %Add3, ptr %idxS3, align 8
ret void
}
```
Outputs this sequence:
```
%0 = insertelement <2 x i64> poison, i64 %A0, i64 0
%1 = insertelement <2 x i64> %0, i64 %B0, i64 1
%2 = add <2 x i64> splat (i64 1), %1
%3 = extractelement <2 x i64> %2, i64 1
%4 = extractelement <2 x i64> %2, i64 0
```
https://github.com/llvm/llvm-project/pull/218250
More information about the llvm-commits
mailing list