[llvm] [RISCV] Use addi rather than addiw for immediates materialised by lui+addi(w) pairs when possible (PR #141663)

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 2 06:30:44 PDT 2025


asb wrote:

> > > I think something like this should work.
> > 
> > 
> > Not sure if it makes sense to break out to a separate PR, but I've added this tentatively to this PR so at least we're all looking at the same thing. I can no longer see any cases of sext.w being introduced looking at the llvm-test-suite diff. I do see one or two odd cases where we end up with `lwu` but didn't before which I need to look into.
> > EDIT: the test-suite + SPEC just finished and I get failures on perlbench, so it seems there's a correctness issue here.
> 
> Does the failure only appear with my change to RISCVOptWInstrs?

It was, it turned out to just be a matter of the code needing to `continue` rather than `return true`. Rather surprising that only resulted in a single failure - it took longer than it should have for me to realise it was something so simple as I was expecting a much more subtle corner case.

I've pushed a fix as well as MIR test cases.

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


More information about the llvm-commits mailing list