[llvm] [AArch64][TTI] Fix extract cost for scalar fmul users (PR #212739)

Anutosh Bhat via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 30 01:47:58 PDT 2026


anutosh491 wrote:

> The test case seems to use -slp-threshold=3, and seems to vectorize fine without it.

Yes, the threshold was used to put the original cost of -2 and the corrected cost of -4 on opposite sides of the vectorization decision. I agree that this is artificial because both are profitable with the default threshold.

I have updated the test for it to look more natural. Main reports a cost of 0 and the patch reports -2, so it exposes the difference using the default threshold.

On main 
```
ExtractElement cost for double from <2 x double>: 2
SLP: Extract Cost = 2.
SLP: Total Cost = 0.
SLP: Found cost = 0 for VF=2

%x0 = fadd double %a0, %c
%x1 = fadd double %a1, %c

; Only [x2, x3] was vectorized.
%3 = fadd <2 x double> %0, %2

store double %x0, ptr %o0
store double %x1, ptr %o1
store <2 x double> %3, ptr %o2

%4 = extractelement <2 x double> %3, i64 0
%mul = fmul double %x1, %4
```

On Branch
```
ExtractElement cost for double from <2 x double>: 0
SLP: Extract Cost = 0.
SLP: Total Cost = -2.
SLP: Found cost = -2 for VF=2
SLP: Decided to vectorize cost = -2

%3 = fadd <2 x double> %0, %2
%5 = fadd <2 x double> %4, %2

store <2 x double> %3, ptr %o0
store <2 x double> %5, ptr %o2

%6 = extractelement <2 x double> %3, i64 1
%7 = extractelement <2 x double> %5, i64 0
%mul = fmul double %6, %7
```

https://github.com/llvm/llvm-project/pull/212739


More information about the llvm-commits mailing list