[llvm] [RISCV] Prefer SP over FP for frame index access when offset fits within compressed immediate range. (PR #193962)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 27 13:51:35 PDT 2026
================
@@ -1518,8 +1518,30 @@ RISCVFrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI,
assert(!MFI.hasVarSizedObjects());
FrameReg = SPReg;
}
+ } else if (!RI->hasStackRealignment(MF)) {
+ // Note: Keeping the following as multiple 'if' statements rather than
+ // merging to a single expression for readability.
+ if (!hasFP(MF)) {
+ // No FP available, must use SP.
+ FrameReg = SPReg;
+ } else {
+ FrameReg = FPReg;
+ // Both FP and SP are candidates.
+ if (RVFI->getRVVStackSize() == 0 && !MFI.hasVarSizedObjects()) {
+ // Prefer SP when the SP-relative offset fits in the compressed
+ // instruction immediate range.
----------------
topperc wrote:
If it's not harmful to uncompressed instructions, I would prefer to not a separate behavior for compressed and uncompressed here. It just adds complexity to the compiler.
https://github.com/llvm/llvm-project/pull/193962
More information about the llvm-commits
mailing list