[llvm] [AMDGPU] Restore SP from saved-FP or saved-BP (PR #124007)

Christudasan Devadasan via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 23 22:36:32 PST 2025


cdevadas wrote:

In addition, with this patch, we should be able to avoid the additional bump in the stack frame when there is a dyn_realignment. 

The stack size computation in the compiler today.
Prolog
  bp = sp
  fp = sp + (alignment - 1)
  fp &= -alignment
  **sp = sp + frame_size + max_alignment** // suboptimal as we always add the max_alignment to restore SP correctly later.
 
Epilog
  **sp -= frame_size + max_alignment**
 
Can be improved to:

Prolog:
  bp = sp
  fp = sp + (alignment - 1)
  fp &= -alignment
  **sp = fp + frame_size** // optimal
 
Epilog:
  sp = bp;

I will vouch for this patch as it is and a follow-up patch to optimize the stack allocated as mentioned here even if there is a cost to force BP in certain situations.

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


More information about the llvm-commits mailing list