[ShrinkWrap] check for PPC's non-callee-saved LR
authorNick Desaulniers <ndesaulniers@google.com>
Tue, 11 Jan 2022 18:01:25 +0000 (10:01 -0800)
committerNick Desaulniers <ndesaulniers@google.com>
Tue, 11 Jan 2022 18:01:34 +0000 (10:01 -0800)
commit9c4b49db1928be41f9b531d3e050d1e4c22a77aa
treebf5598b46bbd306d8a46854df635940f8d460bb3
parent630084549b33f297fdc4cab78190c783688603ea
[ShrinkWrap] check for PPC's non-callee-saved LR

As pointed out in https://reviews.llvm.org/D115688#inline-1108193, we
don't want to sink the save point past an INLINEASM_BR, otherwise
prologepilog may incorrectly sink a prolog past the MBB containing an
INLINEASM_BR and into the wrong MBB.

ShrinkWrap is getting this wrong because LR is not in the list of callee
saved registers. Specifically, ShrinkWrap::useOrDefCSROrFI calls
RegisterClassInfo::getLastCalleeSavedAlias which reads
CalleeSavedAliases which was populated by
RegisterClassInfo::runOnMachineFunction by iterating the list of
MCPhysReg returned from MachineRegisterInfo::getCalleeSavedRegs.

Because PPC's LR is non-allocatable, it's NOT considered callee saved.
Add an interface to TargetRegisterInfo for such a case and use it in
Shrinkwrap to ensure we don't sink a prolog past an INLINEASM or
INLINEASM_BR that clobbers LR.

Reviewed By: jyknight, efriedma, nemanjai, #powerpc

Differential Revision: https://reviews.llvm.org/D116424
llvm/include/llvm/CodeGen/TargetRegisterInfo.h
llvm/lib/CodeGen/ShrinkWrap.cpp
llvm/lib/Target/PowerPC/PPCRegisterInfo.h
llvm/test/CodeGen/PowerPC/ppc64-inlineasm-clobber.ll