[llvm] [RISCV][GlobalISel] Fold large constant offsets in selectAddrRegImm (PR #219161)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 03:01:37 PDT 2026
================
@@ -1687,6 +1709,29 @@ bool RISCVInstructionSelector::isRegInFprb(Register Reg) const {
return RBI.getRegBank(Reg, *MRI, TRI)->getID() == RISCV::FPRBRegBankID;
}
+// A G_PTR_ADD result is worth splitting into Hi (materialized) +
+// Lo12 (folded offset) only if every user is a plain scalar load/store
+// using it as the address. Otherwise the ADD is selected on its own with
+// the full materialized constant, making the Hi materialization here redundant.
+bool RISCVInstructionSelector::isWorthFoldingAdd(Register AddResult) const {
+ for (const MachineOperand &Use : MRI->use_operands(AddResult)) {
+ const MachineInstr *User = Use.getParent();
+ auto *LdSt = dyn_cast<GLoadStore>(User);
----------------
arsenm wrote:
```suggestion
for (const MachineInstr &User : MRI->use_nodbg_instructions(AddResult)) {
auto *LdSt = dyn_cast<GLoadStore>(User);
```
https://github.com/llvm/llvm-project/pull/219161
More information about the llvm-commits
mailing list