Index: include/llvm/Analysis/MustExecute.h =================================================================== --- include/llvm/Analysis/MustExecute.h +++ include/llvm/Analysis/MustExecute.h @@ -34,9 +34,7 @@ /// Captures loop safety information. /// It keep information for loop blocks may throw exception or otherwise /// exit abnormaly on any iteration of the loop which might actually execute -/// at runtime. The primary way to consume this infromation is via -/// isGuaranteedToExecute below, but some callers bailout or fallback to -/// alternate reasoning if a loop contains any implicit control flow. +/// at runtime. /// NOTE: LoopSafetyInfo contains cached information regarding loops and their /// particular blocks. This information is only dropped on invocation of /// computeLoopSafetyInfo. If the loop or any of its block is deleted, or if @@ -82,14 +80,6 @@ LoopSafetyInfo(DominatorTree *DT): ICF(DT) {} }; - -/// Returns true if the instruction in a loop is guaranteed to execute at least -/// once (under the assumption that the loop is entered). -/// TODO: Remove the function, call SafetyInfi->mustExecuteInLoop instead. -bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT, - const Loop *CurLoop, - const LoopSafetyInfo *SafetyInfo); - } #endif Index: lib/Analysis/MustExecute.cpp =================================================================== --- lib/Analysis/MustExecute.cpp +++ lib/Analysis/MustExecute.cpp @@ -171,15 +171,6 @@ ICF.invalidateBlock(BB); } -/// Returns true if the instruction in a loop is guaranteed to execute at least -/// once. -bool llvm::isGuaranteedToExecute(const Instruction &Inst, - const DominatorTree *DT, const Loop *CurLoop, - const LoopSafetyInfo *SafetyInfo) { - return SafetyInfo->mustExecuteInLoop(CurLoop, &Inst, DT); -} - - namespace { struct MustExecutePrinter : public FunctionPass { @@ -214,7 +205,7 @@ // caller actually gets the full power at the moment. LoopSafetyInfo LSI(DT); LSI.computeLoopSafetyInfo(L); - return isGuaranteedToExecute(I, DT, L, &LSI) || + return LSI.mustExecuteInLoop(L, &I, DT) || isGuaranteedToExecuteForEveryIteration(&I, L); } Index: lib/Transforms/Scalar/LICM.cpp =================================================================== --- lib/Transforms/Scalar/LICM.cpp +++ lib/Transforms/Scalar/LICM.cpp @@ -1084,9 +1084,9 @@ // is valid in the loop preheader. if (I.hasMetadataOtherThanDebugLoc() && // The check on hasMetadataOtherThanDebugLoc is to prevent us from burning - // time in isGuaranteedToExecute if we don't actually have anything to + // time in mustExecuteInLoop if we don't actually have anything to // drop. It is a compile time optimization, not required for correctness. - !isGuaranteedToExecute(I, DT, CurLoop, SafetyInfo)) + !SafetyInfo->mustExecuteInLoop(CurLoop, &I, DT)) I.dropUnknownNonDebugMetadata(); // Contents of a block has changed, we need to mark it in safety info. @@ -1121,8 +1121,7 @@ if (isSafeToSpeculativelyExecute(&Inst, CtxI, DT)) return true; - bool GuaranteedToExecute = - isGuaranteedToExecute(Inst, DT, CurLoop, SafetyInfo); + bool GuaranteedToExecute = SafetyInfo->mustExecuteInLoop(CurLoop, &Inst, DT); if (!GuaranteedToExecute) { auto *LI = dyn_cast(&Inst); @@ -1382,7 +1381,7 @@ if (!DereferenceableInPH || !SafeToInsertStore || (InstAlignment > Alignment)) { - if (isGuaranteedToExecute(*UI, DT, CurLoop, SafetyInfo)) { + if (SafetyInfo->mustExecuteInLoop(CurLoop, UI, DT)) { DereferenceableInPH = true; SafeToInsertStore = true; Alignment = std::max(Alignment, InstAlignment); Index: lib/Transforms/Scalar/LoopUnswitch.cpp =================================================================== --- lib/Transforms/Scalar/LoopUnswitch.cpp +++ lib/Transforms/Scalar/LoopUnswitch.cpp @@ -700,8 +700,7 @@ // in the code that did not have one. // This is a workaround for the discrepancy between LLVM IR and MSan // semantics. See PR28054 for more details. - if (SanitizeMemory && - !isGuaranteedToExecute(*TI, DT, currentLoop, SafetyInfo)) + if (SanitizeMemory && !SafetyInfo->mustExecuteInLoop(currentLoop, TI, DT)) continue; if (BranchInst *BI = dyn_cast(TI)) {