-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[AMDGPU] Restore SP correctly in functions with dynamic allocas #122743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should SP restoration be marked as |
||
} | ||
} | ||
if (FPSaved) { | ||
// CSR spill restores should use FP as base register. If | ||
// SGPRForFPSaveRestoreCopy is not true, restore the previous value of FP | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's any kind of dynamic stack adjustment. I think this is the same conditions as hasFP (that's what I was using in my last attempt at this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasFP checks for variable-sized objects, stack realignment, disable-frame-pointer-elimination optimization, and these intrinsics:
@llvm.frameaddress
,@llvm.experimental.stackmap
,@llvm.experimental.patchpoint
.Of these, I think we only need SP restoration in case of variable-sized objects and stack realignment.
If a function has only stack-realignment without variable-sized objects, then that is handled in the existing prolog/epilog.
So I think we only need to handle SP restoration for variable sized objects (unless there is something else which does a dynamic stack adjustment)