[RISCV] Fold low 12 bits into instruction during frame index elimination
authorPhilip Reames <preames@rivosinc.com>
Fri, 2 Dec 2022 19:45:53 +0000 (11:45 -0800)
committerPhilip Reames <listmail@philipreames.com>
Fri, 2 Dec 2022 19:54:06 +0000 (11:54 -0800)
commitb77533306876fc807e58e355d95d848a0077131f
treefa04522efb3a92774d1e97e39c6a96eabbe56da5
parent86fe4dfdb626d472f88bf8331da7cc98e9631cfe
[RISCV] Fold low 12 bits into instruction during frame index elimination

Fold the low 12 bits of an immediate offset into the offset field of the using instruction. That using instruction will be a load, store, or addi which performs an add of a signed 12-bit immediate as part of it's operation. Splitting out the low bits allows the high bits to be generated via a single LUI instead of needing an LUI/ADDI pair.

The codegen effect of this is mostly converting cases where "split addi" kicks in to using LUI + a folded offset. There are a couple of straight dynamic instruction count wins, and using a canonical LUI is probably better than a chain of SP adds if the dynamic instruction count is equal.

Differential Revision: https://reviews.llvm.org/D139037
llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
llvm/test/CodeGen/RISCV/branch-relaxation.ll
llvm/test/CodeGen/RISCV/local-stack-slot-allocation.ll
llvm/test/CodeGen/RISCV/out-of-reach-emergency-slot.mir
llvm/test/CodeGen/RISCV/pr58286.ll
llvm/test/CodeGen/RISCV/vararg.ll