diff --git a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h --- a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h +++ b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h @@ -358,9 +358,14 @@ Optional LoopPassManager::runSinglePass( IRUnitT &IR, PassT &Pass, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U, PassInstrumentation &PI) { + // Pass the outermost loop to BeforePass and AfterPass callbacks in case of + // LoopNest Pass. + const Loop *L = any_isa(&IR) + ? &any_cast(&IR)->getOutermostLoop() + : any_cast(&IR); // Check the PassInstrumentation's BeforePass callbacks before running the // pass, skip its execution completely if asked to (callback returns false). - if (!PI.runBeforePass(*Pass, IR)) + if (!PI.runBeforePass(*Pass, *L)) return None; PreservedAnalyses PA; @@ -373,7 +378,7 @@ if (U.skipCurrentLoop()) PI.runAfterPassInvalidated(*Pass, PA); else - PI.runAfterPass(*Pass, IR, PA); + PI.runAfterPass(*Pass, *L, PA); return PA; }