llvm-project
46e07d38 - [RISCV] Prefer SP over FP for frame index access when offset fits within compressed immediate range. (#193962)

Commit
8 days ago
[RISCV] Prefer SP over FP for frame index access when offset fits within compressed immediate range. (#193962) Before this change, we would use fp/s0/x8 for most stack accesses when frame pointers were present. This is an over-approximation when a stack slot is reachable from both SP and FP with no scalable offset. This patch replaces the unconditional getFrameRegister() call in getFrameIndexReference with an explicit register selection decision tree. When both SP and FP are available (no stack realignment, no RVV objects, no variable-sized objects), prefer SP if the SP-relative offset fits in the compressed instruction immediate range (<=252 for RV32, <=504 for RV64). This enables compression for sp-relative instructions to c.swsp/c.lwsp (RV32) and c.sdsp/c.ldsp (RV64) thereby reducing code size.
Author
Parents
Loading