[llvm] [SystemZ] Add shrink-wrapping support for ELF prologue/epilogue (PR #225240)
Ulrich Weigand via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 25 03:12:53 PDT 2026
uweigand wrote:
Thanks for looking into this. I think for correctness we need to review whether everything done by current prolog/epilog code generated via any of these
- `saveCalleeSavedRegisters`
- `restoreCalleeSavedRegisters`
- `emitPrologue`
- `emitEpilogue`
is still safe if emitted at any of the non-default save/restore points.
In `saveCalleeSavedRegisters`, I see the vararg handling - you're already checking for this. In `restoreCalleeSavedRegisters`, I was wondering about the frame-pointer handling, but on second thought, this should be OK given that `restoreCalleeSavedRegisters` can only be called on paths where `saveCalleeSavedRegisters` was previously called, so if `HasFP` is true for the function, the frame pointer must have been set up.
Looking at `emitPrologue`, I think this should be OK for the "normal" case. But there's quite a few special cases that likely need extra consideration:
- GHC calling convention: this *might* be OK as-is, but for GHC the prolog and epilog are mostly no-ops anyway, so shrink-wrapping doesn't really make sense here. Probably best to disable for this case.
- mcount instrumentation: we need to call mcount exactly once per function call, so this cannot be added anywhere but the entry block. Probably best to disable shrink-wrapping for instrumented functions.
- backchain: the code to set the stack backchain hard-codes use of %r1 as temporary register. This is indeed guaranteed to be available in the entry block, but not necessarily elsewhere. Either we need to generalize the temp register handling, or disable shrink-wrapping if backchain is enabled.
- stack probing: similarly, the probing code will use %r1 and/or %r0 as temp registers - same issue as with backchain.
- frame pointer handling: as the comment says "Mark the FramePtr as live at the beginning of every block except the entry block." - this is wrong in the presence of shrink-wrapping. It should only be marked live in blocks dominated by a save point (and postdominated by a restore point).
I'm not seeing any further issues in `emitEpilogue` so far.
All the above issues could for now be handled by simply disabling shrink-wrapping if any of those circumstances apply. In a few cases we might look into re-enabling after changing the code to properly support non-entry-blocks. But that can certainly be done in follow-up PRs.
https://github.com/llvm/llvm-project/pull/225240
More information about the llvm-commits
mailing list