Index: llvm/include/llvm/Analysis/ValueTracking.h =================================================================== --- llvm/include/llvm/Analysis/ValueTracking.h +++ llvm/include/llvm/Analysis/ValueTracking.h @@ -452,6 +452,7 @@ /// for such instructions, moving them may change the resulting value. bool isSafeToSpeculativelyExecute(const Instruction *I, const Instruction *CtxI = nullptr, + AssumptionCache *AC = nullptr, const DominatorTree *DT = nullptr, const TargetLibraryInfo *TLI = nullptr); @@ -474,7 +475,8 @@ /// intentional. bool isSafeToSpeculativelyExecuteWithOpcode( unsigned Opcode, const Instruction *Inst, const Instruction *CtxI = nullptr, - const DominatorTree *DT = nullptr, const TargetLibraryInfo *TLI = nullptr); + AssumptionCache *AC = nullptr, const DominatorTree *DT = nullptr, + const TargetLibraryInfo *TLI = nullptr); /// Returns true if the result or effects of the given instructions \p I /// depend values not reachable through the def use graph. Index: llvm/lib/Analysis/ValueTracking.cpp =================================================================== --- llvm/lib/Analysis/ValueTracking.cpp +++ llvm/lib/Analysis/ValueTracking.cpp @@ -4718,15 +4718,17 @@ bool llvm::isSafeToSpeculativelyExecute(const Instruction *Inst, const Instruction *CtxI, + AssumptionCache *AC, const DominatorTree *DT, const TargetLibraryInfo *TLI) { return isSafeToSpeculativelyExecuteWithOpcode(Inst->getOpcode(), Inst, CtxI, - DT, TLI); + AC, DT, TLI); } bool llvm::isSafeToSpeculativelyExecuteWithOpcode( unsigned Opcode, const Instruction *Inst, const Instruction *CtxI, - const DominatorTree *DT, const TargetLibraryInfo *TLI) { + AssumptionCache *AC, const DominatorTree *DT, + const TargetLibraryInfo *TLI) { #ifndef NDEBUG if (Inst->getOpcode() != Opcode) { // Check that the operands are actually compatible with the Opcode override. @@ -4784,10 +4786,9 @@ if (mustSuppressSpeculation(*LI)) return false; const DataLayout &DL = LI->getModule()->getDataLayout(); - return isDereferenceableAndAlignedPointer( - LI->getPointerOperand(), LI->getType(), LI->getAlign(), DL, CtxI, - nullptr, // FIXME - DT, TLI); + return isDereferenceableAndAlignedPointer(LI->getPointerOperand(), + LI->getType(), LI->getAlign(), DL, + CtxI, AC, DT, TLI); } case Instruction::Call: { auto *CI = dyn_cast(Inst); Index: llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp +++ llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp @@ -462,7 +462,7 @@ static bool isHoistable(Instruction *I, DominatorTree &DT) { if (!isHoistableInstructionType(I)) return false; - return isSafeToSpeculativelyExecute(I, nullptr, &DT); + return isSafeToSpeculativelyExecute(I, nullptr, nullptr, &DT); } // Recursively traverse the use-def chains of the given value and return a set Index: llvm/lib/Transforms/Scalar/GVN.cpp =================================================================== --- llvm/lib/Transforms/Scalar/GVN.cpp +++ llvm/lib/Transforms/Scalar/GVN.cpp @@ -1533,10 +1533,12 @@ // to speculatively execute the load at that points. if (MustEnsureSafetyOfSpeculativeExecution) { if (CriticalEdgePred.size()) - if (!isSafeToSpeculativelyExecute(Load, LoadBB->getFirstNonPHI(), DT)) + if (!isSafeToSpeculativelyExecute(Load, LoadBB->getFirstNonPHI(), nullptr, + DT)) return false; for (auto &PL : PredLoads) - if (!isSafeToSpeculativelyExecute(Load, PL.first->getTerminator(), DT)) + if (!isSafeToSpeculativelyExecute(Load, PL.first->getTerminator(), + nullptr, DT)) return false; } Index: llvm/lib/Transforms/Scalar/GuardWidening.cpp =================================================================== --- llvm/lib/Transforms/Scalar/GuardWidening.cpp +++ llvm/lib/Transforms/Scalar/GuardWidening.cpp @@ -93,7 +93,7 @@ } // Set the condition for \p I to \p NewCond. \p I can either be a guard or a -// conditional branch. +// conditional branch. static void setCondition(Instruction *I, Value *NewCond) { if (IntrinsicInst *GI = dyn_cast(I)) { assert(GI->getIntrinsicID() == Intrinsic::experimental_guard && @@ -261,7 +261,7 @@ void widenGuard(Instruction *ToWiden, Value *NewCondition, bool InvertCondition) { Value *Result; - + widenCondCommon(getCondition(ToWiden), NewCondition, ToWiden, Result, InvertCondition); if (isGuardAsWidenableBranch(ToWiden)) { @@ -468,7 +468,7 @@ if (!Inst || DT.dominates(Inst, Loc) || Visited.count(Inst)) return true; - if (!isSafeToSpeculativelyExecute(Inst, Loc, &DT) || + if (!isSafeToSpeculativelyExecute(Inst, Loc, nullptr, &DT) || Inst->mayReadFromMemory()) return false; @@ -488,7 +488,7 @@ if (!Inst || DT.dominates(Inst, Loc)) return; - assert(isSafeToSpeculativelyExecute(Inst, Loc, &DT) && + assert(isSafeToSpeculativelyExecute(Inst, Loc, nullptr, &DT) && !Inst->mayReadFromMemory() && "Should've checked with isAvailableAt!"); for (Value *Op : Inst->operands()) Index: llvm/lib/Transforms/Scalar/LICM.cpp =================================================================== --- llvm/lib/Transforms/Scalar/LICM.cpp +++ llvm/lib/Transforms/Scalar/LICM.cpp @@ -1736,7 +1736,8 @@ const Loop *CurLoop, const LoopSafetyInfo *SafetyInfo, OptimizationRemarkEmitter *ORE, const Instruction *CtxI, bool AllowSpeculation) { - if (AllowSpeculation && isSafeToSpeculativelyExecute(&Inst, CtxI, DT, TLI)) + if (AllowSpeculation && + isSafeToSpeculativelyExecute(&Inst, CtxI, nullptr, DT, TLI)) return true; bool GuaranteedToExecute =