This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Create a FixedStack object for CR save in linkage area.
ClosedPublic

Authored by sfertile on Jan 30 2020, 7:18 AM.

Details

Summary

hasReservedSpillSlot returns a dummy frame index of '0' on PPC64 for the non-volatile condition registers, which leads to the CalleSavedInfo either referencing an unrelated stack object, or an invalid object if there are no stack objects. The latter case causes the mir-printer to crash due to assertions that check if the frame index referenced by a CalleeSavedInfo is valid. To fix the problem I simply create an immutable FixedStack object at the correct offset in the previous stack frame (ie SP + positive offset).

Initially I tried to fix this by handling the CR save similar to the link register. My reasoning was that since both have custom saving and restoring to the linkage area inserted as part of the prologue/epilogue we should reset CR2/CR3/CR4 in the callee saved register mask and not create CalleeSavedInfos. This has the draw back that they don't get added as live-ins in updateLiveness so I abandoned the approach.

Diff Detail

Event Timeline

sfertile created this revision.Jan 30 2020, 7:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 30 2020, 7:19 AM
jsji added a reviewer: Restricted Project.Jan 30 2020, 7:28 AM
jsji added a project: Restricted Project.
sfertile updated this revision to Diff 242109.Feb 3 2020, 9:51 AM

Remove unneeded info in the mir test.

jsji added inline comments.Feb 5 2020, 2:39 PM
llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
1804

aliases? looks confusing, as IsAliased below is always false.

llvm/test/CodeGen/PowerPC/ppc64-crsave.mir
11

Can we add some test with alloca in callee stack?

sfertile updated this revision to Diff 242971.Feb 6 2020, 11:54 AM
  • Reworded comment to avoid confusing usage of 'alias'. which conflicted with the 'IsAliased' argument used in the function call being commented.
  • Added a test that contains an alloca and a function call.
jsji accepted this revision as: jsji.Feb 6 2020, 12:02 PM

LGTM. Thanks.

This revision is now accepted and ready to land.Feb 6 2020, 12:02 PM
sfertile marked 2 inline comments as done.Feb 6 2020, 12:02 PM
sfertile added inline comments.
llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
1804

Your right, the comment makes the code look like its passing the wrong value for the argument. I've reworded the comment.

llvm/test/CodeGen/PowerPC/ppc64-alloca-crspill.ll
32

I'm not sure why the offset of the variably size object is -8, which overlaps with the fixed save slot for the frame pointer. It might be that the offset is not a valid field for variably sized objects? I'm going to investigate this now

37

I suspect this stack object is padding for keeping the stack pointer 16 byte aligned: 32 byte linkage area + 8 bytes spill for $x31 would have only been 8 bytes.

llvm/test/CodeGen/PowerPC/ppc64-crsave.mir
11

Good idea. I've added it in a separate test since I though it was best to use IR input and stop after prologue/epilogiue insertion.

sfertile marked 2 inline comments as done.Feb 7 2020, 8:16 AM
sfertile added inline comments.
llvm/test/CodeGen/PowerPC/ppc64-alloca-crspill.ll
32

If I add multiple allocas they are all at offset -8, so the field must not mean anything for dynamic objects.

37

Not padding, we allocate this object for scavenging purposes.

This revision was automatically updated to reflect the committed changes.