CodeGenPrep: add separate hook say when GEPs should be used for sinking. NFCI.

Up to now, we've decided whether to sink address calculations using GEPs or
normal arithmetic based on the useAA hook, but there are other reasons GEPs
might be preferred. So this patch splits the two questions, with a default
implementation falling back to useAA.

llvm-svn: 371721
This commit is contained in:
Tim Northover 2019-09-12 10:21:00 +00:00
parent 719087bbb7
commit 98534843fb
2 changed files with 8 additions and 2 deletions

View File

@ -274,6 +274,12 @@ public:
/// scheduling, DAGCombine, etc.).
virtual bool useAA() const;
/// \brief Sink addresses into blocks using GEP instructions rather than
/// pointer casts and arithmetic.
virtual bool addrSinkUsingGEPs() const {
return useAA();
}
/// Enable the use of the early if conversion pass.
virtual bool enableEarlyIfConversion() const { return false; }

View File

@ -4791,8 +4791,8 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
<< " for " << *MemoryInst << "\n");
if (SunkAddr->getType() != Addr->getType())
SunkAddr = Builder.CreatePointerCast(SunkAddr, Addr->getType());
} else if (AddrSinkUsingGEPs ||
(!AddrSinkUsingGEPs.getNumOccurrences() && TM && TTI->useAA())) {
} else if (AddrSinkUsingGEPs || (!AddrSinkUsingGEPs.getNumOccurrences() &&
TM && SubtargetInfo->addrSinkUsingGEPs())) {
// By default, we use the GEP-based method when AA is used later. This
// prevents new inttoptr/ptrtoint pairs from degrading AA capabilities.
LLVM_DEBUG(dbgs() << "CGP: SINKING nonlocal addrmode: " << AddrMode