[llvm] [AMDGPU] Scale the frame register in place when lowering scalar frame indices (PR #221972)

Pankaj Dwivedi via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 03:24:45 PDT 2026


================
@@ -3419,11 +3419,40 @@ bool SIRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator MI,
       bool IsCopy = MI->getOpcode() == AMDGPU::V_MOV_B32_e32 ||
                     MI->getOpcode() == AMDGPU::V_MOV_B32_e64 ||
                     MI->getOpcode() == AMDGPU::S_MOV_B32;
-      Register ResultReg =
-          IsCopy ? MI->getOperand(0).getReg()
-                 : RS->scavengeRegisterBackwards(*RC, MI, false, 0);
 
       int64_t Offset = FrameInfo.getObjectOffset(Index);
+      int64_t ScaledOffset = -Offset * ST.getWavefrontSize();
+
+      // Scaling FrameReg in place is the last resort when there is nothing to
+      // scavenge. It has to be undone after MI, which is only possible while MI
+      // does not use FrameReg for anything besides the frame index, and while
+      // the offset can be folded back in wave space. A second frame index on MI
+      // would be lowered while FrameReg is still scaled, so keep away from it.
+      bool HasOneFrameIndex =
----------------
PankajDwivedi-25 wrote:

> Does the verifier check if there's only one?

No, it doesn't. MachineVerifier.cpp has no such rule, RegScavenger::getFrameIndexOperandNum simply returns the first FI operand it finds, and PEI deliberately loops over all of them.

One thing I found is we already have a test file which has test cases with >1 frame idx (Ex:: AMDGPU/fold-operands-s-add-copy-to-vgpr.mir, but this doesn't run through the prolog epilog inserter pass and never reach to eliminateFrameIdx this is just to let you know).

I am drooping that guard.

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


More information about the llvm-commits mailing list