[llvm] [AMDGPU] Restore SP correctly in functions with dynamic allocas (PR #122743)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 14 03:24:24 PST 2025
================
@@ -525,8 +525,11 @@ Register SIRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
bool SIRegisterInfo::hasBasePointer(const MachineFunction &MF) const {
// When we need stack realignment, we can't reference off of the
// stack pointer, so we reserve a base pointer.
+ // For functions with dynamically sized stack objects, we need to reference
+ // off the base pointer in the epilog to restore the stack frame.
const MachineFrameInfo &MFI = MF.getFrameInfo();
- return MFI.getNumFixedObjects() && shouldRealignStack(MF);
+ return (MFI.getNumFixedObjects() && shouldRealignStack(MF)) ||
+ MFI.hasVarSizedObjects();
----------------
easyonaadit wrote:
> We should have the use fp path and use BP as a fallback if really necessary. What is the idea?
The FP path is ideal for dynamic allocas with default alignment.
When some object is over-aligned, currently in the prolog:
`sp += frameSize + alignment`
This is working fine but is not the right calculation, we are allocating excess space on the stack.
Once FP and BP have been established, we should just:
`sp = aligned_fp + frameSize`
I wasn't sure about the design decision behind the current calculations, so I didn't want to tinker with it. I guess this was needed when we didn't have BP supported, as there is no other way to unwind the stack in the epilog, if it has been realigned in the prolog.
I assume this will need an overhaul in the PEI code tho.
https://github.com/llvm/llvm-project/pull/122743
More information about the llvm-commits
mailing list