diff --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp --- a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp +++ b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp @@ -1761,10 +1761,14 @@ } PreservedAnalyses IRCEPass::run(Function &F, FunctionAnalysisManager &AM) { - auto &SE = AM.getResult(F); auto &DT = AM.getResult(F); - auto &BPI = AM.getResult(F); LoopInfo &LI = AM.getResult(F); + // There are no loops in the function. Return before computing other expensive + // analyses. + if (LI.empty()) + return PreservedAnalyses::all(); + auto &SE = AM.getResult(F); + auto &BPI = AM.getResult(F); // Get BFI analysis result on demand. Please note that modification of // CFG invalidates this analysis and we should handle it.