[llvm] [SLP] Loop aware cost model/tree building (PR #150450)
Hari Limaye via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 8 01:14:21 PDT 2026
hazzlim wrote:
> > Hi @alexey-bataev - any update on fixing these regressions?
>
> Sorry, was on PTO. I checked this one and looks like SLP is correct here. The actual issue is in AARCH64 TTI, the cost of the fmul is overestimated. Currently, AARCH64 TTI estimates it as 2, making vector code to be way more profitable than the scalar (e.g., for 2 scalar fmuls cost is 4, while vector is only 2). We ran into this issue already, so it should be fixed in TTI.
No problem! I had a look at this, and I don't think the issue here is the FMUL cost - the total regression we have seen from recent SLP patches has been ~6.5%. Lowering the cost of FMUL to 1 gave us a much more modest improvement of 1%, but caused larger regressions elsewhere in SPEC.
Having had a further look at this - the issue in namd seems to be that we have reductions spanning across sibling loops like this:
```
void pair_sibling_simplified(const unsigned n1,
const unsigned n2,
const double *arr,
double *out) {
double acc = 0.0;
// Sibling loop A.
for (unsigned i = 0; i + 1 < n1; i += 2) {
acc = acc + arr[i] * 2.0;
acc = acc + arr[i + 1] * 2.0;
}
// Sibling loop B (different bound).
for (unsigned i = 0; i + 1 < n2; i += 2) {
acc = acc + arr[i] * 4.0;
acc = acc + arr[i + 1] * 4.0;
}
*out = acc;
}
```
and so SLP now always bails out to a gather node when it would be more profitable to continue vectorizing the chain.
Since https://github.com/llvm/llvm-project/pull/192801 we admit sibling loops, but only when BTCs are represented by equal SCEVs, which isn't the case here.
I've opened https://github.com/llvm/llvm-project/pull/208164 with a potential fix for this - please let me know if you'd be happy with this direction or if you think an alternative approach would be more suitable.
https://github.com/llvm/llvm-project/pull/150450
More information about the llvm-commits
mailing list