[PowerPC] Move TOC save to prologue when profitable
commit7a06a3c98ab514952287091d42f706ca5e3296da
authorNemanja Ivanovic <nemanja.i.ibm@gmail.com>
Fri, 5 Jul 2019 18:38:09 +0000 (5 18:38 +0000)
committerNemanja Ivanovic <nemanja.i.ibm@gmail.com>
Fri, 5 Jul 2019 18:38:09 +0000 (5 18:38 +0000)
treec0bab5e43ecd6b0239248736ba65a189d747f25e
parente0a5d6341709bc8af0e24847664adb18e3e6034a
[PowerPC] Move TOC save to prologue when profitable

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.

Differential revision: https://reviews.llvm.org/D63803

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365232 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/PowerPC/PPCFrameLowering.cpp
lib/Target/PowerPC/PPCMIPeephole.cpp
lib/Target/PowerPC/PPCMachineFunctionInfo.h
test/CodeGen/PowerPC/MCSE-caller-preserved-reg.ll
test/CodeGen/PowerPC/remove-redundant-toc-saves.ll
test/CodeGen/PowerPC/tocSaveInPrologue.ll