[PATCH] D158190: [wip] AMDGPU: Try to restore SP correctly in presence of dynamic stack adjustments

Sebastian Neubauer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 17 09:21:23 PDT 2023


sebastian-ne added a comment.

Just to make sure I understand our current scheme correctly (before this patch).
If we re-align the stack, we do (ignoring the scale factor)

  fp = sp + (alignment - 1)
  fp &= -alignment
  sp += frameSize + alignment

And in the epilogue:

  sp -= frameSize + alignment

Due to the alignment of fp (but not sp), the allocated stack size `sp - fp` may be larger than needed, but it is restored correctly.
However, sp is not aligned, so maybe this causes problems when calling another function that expects the stack to be already aligned?

In case the stack is already aligned and does not need re-alignment, using a `sp = fp` in the epilogue sounds ok to me.
For the re-alignment case, `sp = fp - (alignment - 1)` looks incorrect to me.

If we do not want the over-commitment, we need to enforce the presence of a base pointer and in the epilogue, restore the stack pointer from the base pointer (`sp = bp`).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158190/new/

https://reviews.llvm.org/D158190



More information about the llvm-commits mailing list