This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Move TOC save to prologue when profitable
ClosedPublic

Authored by nemanjai on Jun 25 2019, 7:41 PM.

Details

Summary

The indirect call sequence on PPC requires that the TOC base register be saved prior to the indirect call and restored after the call since the indirect call may branch to a global entry point in another DSO which will update the TOC base. Over the last couple of years, we have improved this to:

  • be able to hoist TOC saves from loops (with changes to MachineLICM)
  • avoid multiple saves when one dominates the other[s]

However, it is still possible to have multiple TOC saves dynamically in the execution path if there is no dominance relationship between them.

This patch moves the TOC save to the prologue when one of the TOC saves is in a block that post-dominates entry (i.e. it cannot be avoided) or if it is in a block that is hotter than entry.

Diff Detail

Repository
rL LLVM

Event Timeline

nemanjai created this revision.Jun 25 2019, 7:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 25 2019, 7:41 PM
hfinkel added inline comments.Jun 25 2019, 7:50 PM
llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
447 ↗(On Diff #206576)

You've introduced this function, which contains two lines of code, and then make a Boolean variable in several later places with the same name. I recommend just moving this code into its caller below and eliminating any potential confusion.

1314 ↗(On Diff #206576)

Need a MustSaveTOC check here?

llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
229 ↗(On Diff #206576)

Why the MFI.hasVarSizedObjects() check?

nemanjai marked 3 inline comments as done.Jun 26 2019, 4:26 AM
nemanjai added inline comments.
llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
447 ↗(On Diff #206576)

Will do. I was a little on the fence about the value of this function as well.

1314 ↗(On Diff #206576)

Yup, this is an omission. I'll fix it.

llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
229 ↗(On Diff #206576)

It is actually not necessary as this function won't be called when processing functions that have dynamic objects.

nemanjai updated this revision to Diff 206642.Jun 26 2019, 5:46 AM

Remove unnecessary function and fix up conditions for the transformation.

hfinkel accepted this revision.Jul 3 2019, 7:10 PM

One question below, but otherwise, LGTM.

llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
1874 ↗(On Diff #206642)

The point of this is that, if we have R2 here, we'll hit the llvm_unreachable below? Can you write an assert instead?

This revision is now accepted and ready to land.Jul 3 2019, 7:10 PM
nemanjai marked 2 inline comments as done.Jul 5 2019, 11:37 AM
nemanjai added inline comments.
llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
1874 ↗(On Diff #206642)

That's a good point. I'll change it on the commit.

This revision was automatically updated to reflect the committed changes.
nemanjai marked an inline comment as done.