[llvm] Support replacing `add rd, Zero, Zero` with `c.li rd, 0` (PR #86937)

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 11 02:00:02 PDT 2024


asb wrote:

> @wangpc-pp , you are right, we often generate _addi_ with _imm=0_, but writing some optimizations on asm by hands was found this case. Another reason, in the future we might generate _add_ with _zero_ registers. So, I think it would not be superfluous to add this replacement.

I agree that having this replacement makes sense. Whether the pattern realistically comes from codegen or not doesn't matter, because the RISC-V assembler should opportunistically replace user-written 32-bit instructions with compressed ones whenever possible. With that in mind, I think the .ll test case with inline asm isn't a very useful way to test this and it would be better to just test it at MC layer only in llvm/test/MC/RISCV/compress-rv32i.s.

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


More information about the llvm-commits mailing list