Plumb TLI through isSafeToExecuteUnconditionally [NFC]

Split from D95815 to reduce patch size.  Isn't (yet) used for anything, only the client side is wired up.
This commit is contained in:
Philip Reames 2021-03-24 17:51:06 -07:00
parent 7ad55a3df5
commit 9a82f42d12
3 changed files with 13 additions and 8 deletions

View File

@ -461,7 +461,8 @@ constexpr unsigned MaxAnalysisRecursionDepth = 6;
/// for such instructions, moving them may change the resulting value.
bool isSafeToSpeculativelyExecute(const Value *V,
const Instruction *CtxI = nullptr,
const DominatorTree *DT = nullptr);
const DominatorTree *DT = nullptr,
const TargetLibraryInfo *TLI = nullptr);
/// Returns true if the result or effects of the given instructions \p I
/// depend on or influence global memory.

View File

@ -4411,7 +4411,8 @@ bool llvm::mustSuppressSpeculation(const LoadInst &LI) {
bool llvm::isSafeToSpeculativelyExecute(const Value *V,
const Instruction *CtxI,
const DominatorTree *DT) {
const DominatorTree *DT,
const TargetLibraryInfo *TLI) {
const Operator *Inst = dyn_cast<Operator>(V);
if (!Inst)
return false;
@ -4458,7 +4459,7 @@ bool llvm::isSafeToSpeculativelyExecute(const Value *V,
const DataLayout &DL = LI->getModule()->getDataLayout();
return isDereferenceableAndAlignedPointer(
LI->getPointerOperand(), LI->getType(), MaybeAlign(LI->getAlignment()),
DL, CtxI, DT);
DL, CtxI, DT, TLI);
}
case Instruction::Call: {
auto *CI = cast<const CallInst>(Inst);

View File

@ -162,6 +162,7 @@ static bool sink(Instruction &I, LoopInfo *LI, DominatorTree *DT,
OptimizationRemarkEmitter *ORE);
static bool isSafeToExecuteUnconditionally(Instruction &Inst,
const DominatorTree *DT,
const TargetLibraryInfo *TLI,
const Loop *CurLoop,
const LoopSafetyInfo *SafetyInfo,
OptimizationRemarkEmitter *ORE,
@ -921,7 +922,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
ORE) &&
worthSinkOrHoistInst(I, CurLoop->getLoopPreheader(), ORE, BFI) &&
isSafeToExecuteUnconditionally(
I, DT, CurLoop, SafetyInfo, ORE,
I, DT, TLI, CurLoop, SafetyInfo, ORE,
CurLoop->getLoopPreheader()->getTerminator())) {
hoist(I, DT, CurLoop, CFH.getOrCreateHoistedBlock(BB), SafetyInfo,
MSSAU, SE, ORE);
@ -1815,11 +1816,12 @@ static void hoist(Instruction &I, const DominatorTree *DT, const Loop *CurLoop,
/// or if it is a trapping instruction and is guaranteed to execute.
static bool isSafeToExecuteUnconditionally(Instruction &Inst,
const DominatorTree *DT,
const TargetLibraryInfo *TLI,
const Loop *CurLoop,
const LoopSafetyInfo *SafetyInfo,
OptimizationRemarkEmitter *ORE,
const Instruction *CtxI) {
if (isSafeToSpeculativelyExecute(&Inst, CtxI, DT))
if (isSafeToSpeculativelyExecute(&Inst, CtxI, DT, TLI))
return true;
bool GuaranteedToExecute =
@ -2093,8 +2095,9 @@ bool llvm::promoteLoopAccessesToScalars(
// to execute does as well. Thus we can increase our guaranteed
// alignment as well.
if (!DereferenceableInPH || (InstAlignment > Alignment))
if (isSafeToExecuteUnconditionally(*Load, DT, CurLoop, SafetyInfo,
ORE, Preheader->getTerminator())) {
if (isSafeToExecuteUnconditionally(*Load, DT, TLI, CurLoop,
SafetyInfo, ORE,
Preheader->getTerminator())) {
DereferenceableInPH = true;
Alignment = std::max(Alignment, InstAlignment);
}
@ -2141,7 +2144,7 @@ bool llvm::promoteLoopAccessesToScalars(
if (!DereferenceableInPH) {
DereferenceableInPH = isDereferenceableAndAlignedPointer(
Store->getPointerOperand(), Store->getValueOperand()->getType(),
Store->getAlign(), MDL, Preheader->getTerminator(), DT);
Store->getAlign(), MDL, Preheader->getTerminator(), DT, TLI);
}
} else
return false; // Not a load or store.