This is an archive of the discontinued LLVM Phabricator instance.

[SystemZ][z/OS] Save (and restore) R3 to avoid clobbering parameter when call stack frame extension is invoked
ClosedPublic

Authored by Everybody0523 on May 10 2023, 5:09 PM.

Details

Summary

When the stack frame extension routine is used, the contents of r3 is overwritten. However, if r3 is live in the prologue (ie. one of the function's parameters resides in r3), it needs to be saved. We save r3 in r0 if r0 is available (ie. r0 is not used as temporary storage for r4), and in the corresponding stack slot for the third parameter otherwise.

Diff Detail

Event Timeline

Everybody0523 created this revision.May 10 2023, 5:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2023, 5:09 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
Everybody0523 requested review of this revision.May 10 2023, 5:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2023, 5:09 PM
Everybody0523 edited the summary of this revision. (Show Details)May 10 2023, 5:10 PM
uweigand added inline comments.May 11 2023, 3:45 AM
llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
1354

%r0 cannot be used as base register. Is this really supposed to store to the low core? (On Linux, that might be unsafe as it could be clobbered if we're e.g. interrupted by an async signal handler - not sure if there are similar concerns on z/OS.) If yes, you need to use addReg(0) here. If no, I guess some other changes are required.

Don't use r0 as base register...

Everybody0523 added inline comments.
llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
1354

Right, this was indeed a mistake. I've amended it to use the incoming value of r4 (ie. r4 before the stack update) for the store, and then to use r3 as the base register (after a load from r0 to r3) in the load.

uweigand accepted this revision.May 11 2023, 2:33 PM

LGTM.

This revision is now accepted and ready to land.May 11 2023, 2:33 PM

Fix build failure with expensive checks.