[llvm] [LSR] Add unequal cost eval for dropping solutions (PR #178039)
John Brawn via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 12 09:27:07 PST 2026
john-brawn-arm wrote:
Looking at the ``-debug`` output for this function it has
```
LSR is examining the following uses:
LSR Use: Kind=ICmpZero, Offsets={0}, all-fixups-unconditional, widest fixup type: i64
reg({%n,+,-1}<nw><%for.body>)
LSR Use: Kind=Address of i32 in addrspace(0), Offsets={0,0}, all-fixups-unconditional, widest fixup type: ptr
reg({%x,+,4}<nuw><%for.body>)
The baseline solution requires 2 instructions 2 regs, with addrec cost 2, plus 2 setup cost
The chosen solution requires 2 instructions 2 regs, with addrec cost 2, plus 2 setup cost:
LSR Use: Kind=ICmpZero, Offsets={0}, all-fixups-unconditional, widest fixup type: i64
reg({%n,+,-1}<nw><%for.body>)
LSR Use: Kind=Address of i32 in addrspace(0), Offsets={0,0}, all-fixups-unconditional, widest fixup type: ptr
reg({%x,+,4}<nuw><%for.body>)
Baseline is more profitable than chosen solution, dropping LSR solution.
```
It's not that the chosen solution that was found is no better than the baseline, but rather that the chosen solution _is_ the baseline solution. And the reason that dropping the LSR solution makes things worse is that transforming using the baseline solution is better than not doing any transformation at all (and conversely in the test cases where this change improves things, the baseline solution is better than not doing any transformation).
So I think a better solution here is to add a check that the chosen solution is better than not doing any transformation at all.
https://github.com/llvm/llvm-project/pull/178039
More information about the llvm-commits
mailing list