diff --git a/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp b/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp --- a/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp +++ b/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp @@ -655,9 +655,13 @@ if (skipFunction(F)) return false; + auto &DT = getAnalysis().getDomTree(); auto &LI = getAnalysis().getLoopInfo(); + // There are no loops in the function. Return before computing other expensive + // analyses. + if (LI.empty()) + return false; auto &LAA = getAnalysis(); - auto &DT = getAnalysis().getDomTree(); auto *PSI = &getAnalysis().getPSI(); auto *BFI = (PSI && PSI->hasProfileSummary()) ? &getAnalysis().getBFI() : @@ -706,10 +710,14 @@ PreservedAnalyses LoopLoadEliminationPass::run(Function &F, FunctionAnalysisManager &AM) { - auto &SE = AM.getResult(F); + auto &DT = AM.getResult(F); auto &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 &TTI = AM.getResult(F); - auto &DT = AM.getResult(F); auto &TLI = AM.getResult(F); auto &AA = AM.getResult(F); auto &AC = AM.getResult(F); diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp --- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -1545,10 +1545,14 @@ PreservedAnalyses LoopUnrollPass::run(Function &F, FunctionAnalysisManager &AM) { - auto &SE = AM.getResult(F); + auto &DT = AM.getResult(F); auto &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 &TTI = AM.getResult(F); - auto &DT = AM.getResult(F); auto &AC = AM.getResult(F); auto &ORE = AM.getResult(F); diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2219,10 +2219,14 @@ if (skipFunction(F)) return false; - auto *SE = &getAnalysis().getSE(); + auto *DT = &getAnalysis().getDomTree(); auto *LI = &getAnalysis().getLoopInfo(); + // There are no loops in the function. Return before computing other expensive + // analyses. + if (LI->empty()) + return false; + auto *SE = &getAnalysis().getSE(); auto *TTI = &getAnalysis().getTTI(F); - auto *DT = &getAnalysis().getDomTree(); auto *BFI = &getAnalysis().getBFI(); auto *TLIP = getAnalysisIfAvailable(); auto *TLI = TLIP ? &TLIP->getTLI(F) : nullptr; @@ -10733,10 +10737,14 @@ PreservedAnalyses LoopVectorizePass::run(Function &F, FunctionAnalysisManager &AM) { - auto &SE = AM.getResult(F); + auto &DT = AM.getResult(F); auto &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 &TTI = AM.getResult(F); - auto &DT = AM.getResult(F); auto &BFI = AM.getResult(F); auto &TLI = AM.getResult(F); auto &AA = AM.getResult(F); diff --git a/llvm/test/Transforms/SCCP/preserve-analysis.ll b/llvm/test/Transforms/SCCP/preserve-analysis.ll --- a/llvm/test/Transforms/SCCP/preserve-analysis.ll +++ b/llvm/test/Transforms/SCCP/preserve-analysis.ll @@ -5,10 +5,8 @@ ; NEW-PM-DAG: Running analysis: LoopAnalysis on test ; NEW-PM-DAG: Running analysis: DominatorTreeAnalysis on test -; NEW-PM-DAG: Running analysis: AssumptionAnalysis on test -; NEW-PM-DAG: Running analysis: TargetLibraryAnalysis on test -; NEW-PM-DAG: Running analysis: TargetIRAnalysis on test ; NEW-PM: Running pass: SCCPPass on test +; NEW-PM: Running analysis: TargetLibraryAnalysis on test ; NEW-PM-NOT: Running analysis: LoopAnalysis on test ; NEW-PM-NOT: Running analysis: DominatorTreeAnalysis on test ; NEW-PM-NOT: Running analysis: AssumptionAnalysis on test