[llvm] [AMDGPU] Restore SP correctly in functions with dynamic allocas (PR #122743)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 19 20:58:22 PST 2025
================
@@ -1259,6 +1259,23 @@ void SIFrameLowering::emitEpilogue(MachineFunction &MF,
Register FramePtrRegScratchCopy;
Register SGPRForFPSaveRestoreCopy =
FuncInfo->getScratchSGPRCopyDstReg(FramePtrReg);
+
+ if (MFI.hasVarSizedObjects()) {
+ // If we have over-aligned dynamic-sized objects, then restore SP with
+ // saved-BP, else restore it with saved-FP.
+ if (FuncInfo->isStackRealigned()) {
+ Register BasePtrReg = TRI.getBaseRegister();
+ BuildMI(MBB, MBBI, DL, TII->get(AMDGPU::S_ADD_I32), StackPtrReg)
+ .addReg(BasePtrReg)
+ .addImm(RoundedSize * getScratchScaleFactor(ST))
+ .setMIFlag(MachineInstr::FrameDestroy);
+ } else {
+ BuildMI(MBB, MBBI, DL, TII->get(AMDGPU::S_ADD_I32), StackPtrReg)
+ .addReg(FramePtrReg)
+ .addImm(RoundedSize * getScratchScaleFactor(ST))
+ .setMIFlag(MachineInstr::FrameDestroy);
----------------
easyonaadit wrote:
Should SP restoration be marked as `FrameDestroy` ?
Since SP is actually modified during ISel, and there is no counter `FrameSetup` action in the prolog for this.
https://github.com/llvm/llvm-project/pull/122743
More information about the llvm-commits
mailing list