diff --git a/llvm/include/llvm/Transforms/Scalar/SCCP.h b/llvm/include/llvm/Transforms/Scalar/SCCP.h index dfc3421df967a..d05806b4b3fec 100644 --- a/llvm/include/llvm/Transforms/Scalar/SCCP.h +++ b/llvm/include/llvm/Transforms/Scalar/SCCP.h @@ -43,6 +43,7 @@ class SCCPPass : public PassInfoMixin { struct AnalysisResultsForFn { std::unique_ptr PredInfo; DominatorTree *DT; + PostDominatorTree *PDT; }; bool runIPSCCP(Module &M, const DataLayout &DL, const TargetLibraryInfo *TLI, diff --git a/llvm/lib/Transforms/IPO/SCCP.cpp b/llvm/lib/Transforms/IPO/SCCP.cpp index 7cb7cdc0ebbce..d2c34abfc1327 100644 --- a/llvm/lib/Transforms/IPO/SCCP.cpp +++ b/llvm/lib/Transforms/IPO/SCCP.cpp @@ -1,5 +1,6 @@ #include "llvm/Transforms/IPO/SCCP.h" #include "llvm/Analysis/AssumptionCache.h" +#include "llvm/Analysis/PostDominators.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Scalar/SCCP.h" @@ -14,7 +15,7 @@ PreservedAnalyses IPSCCPPass::run(Module &M, ModuleAnalysisManager &AM) { DominatorTree &DT = FAM.getResult(F); return { make_unique(F, DT, FAM.getResult(F)), - &DT}; + &DT, FAM.getCachedResult(F)}; }; if (!runIPSCCP(M, DL, &TLI, getAnalysis)) @@ -22,6 +23,7 @@ PreservedAnalyses IPSCCPPass::run(Module &M, ModuleAnalysisManager &AM) { PreservedAnalyses PA; PA.preserve(); + PA.preserve(); PA.preserve(); return PA; } @@ -56,8 +58,8 @@ class IPSCCPLegacyPass : public ModulePass { F, DT, this->getAnalysis().getAssumptionCache( F)), - nullptr}; // We cannot preserve the DT with the legacy pass manager, - // so so set it to nullptr. + nullptr, // We cannot preserve the DT or PDT with the legacy pass + nullptr}; // manager, so set them to nullptr. }; return runIPSCCP(M, DL, TLI, getAnalysis); diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp index 1d75e58e31f96..a8b5a765f9a66 100644 --- a/llvm/lib/Transforms/Scalar/SCCP.cpp +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp @@ -262,10 +262,10 @@ class SCCPSolver : public InstVisitor { return A->second.PredInfo->getPredicateInfoFor(I); } - DominatorTree *getDomTree(Function &F) { + DomTreeUpdater getDTU(Function &F) { auto A = AnalysisResults.find(&F); assert(A != AnalysisResults.end() && "Need analysis results for function."); - return A->second.DT; + return {A->second.DT, A->second.PDT, DomTreeUpdater::UpdateStrategy::Lazy}; } SCCPSolver(const DataLayout &DL, const TargetLibraryInfo *tli) @@ -2036,8 +2036,7 @@ bool llvm::runIPSCCP( } } - DomTreeUpdater DTU(Solver.getDomTree(F), - DomTreeUpdater::UpdateStrategy::Lazy); + DomTreeUpdater DTU = Solver.getDTU(F); // Change dead blocks to unreachable. We do it after replacing constants // in all executable blocks, because changeToUnreachable may remove PHI // nodes in executable blocks we found values for. The function's entry diff --git a/llvm/test/Transforms/SCCP/ipsccp-preserve-domtree.ll b/llvm/test/Transforms/SCCP/ipsccp-preserve-analysis.ll similarity index 55% rename from llvm/test/Transforms/SCCP/ipsccp-preserve-domtree.ll rename to llvm/test/Transforms/SCCP/ipsccp-preserve-analysis.ll index 1b3cdd6051e1b..b840e5e09fdc2 100644 --- a/llvm/test/Transforms/SCCP/ipsccp-preserve-domtree.ll +++ b/llvm/test/Transforms/SCCP/ipsccp-preserve-analysis.ll @@ -3,31 +3,24 @@ ; IPSCCP can simplify, so we can test the case where IPSCCP makes changes. ; RUN: opt -disable-verify -debug-pass-manager \ -; RUN: -passes='ipsccp,globalopt' -S %s 2>&1 \ +; RUN: -passes='function(require,require),ipsccp,function(require,require)' -S %s 2>&1 \ ; RUN: | FileCheck -check-prefixes='IR,NEW-PM' %s -; RUN: opt -passes='ipsccp,function(verify)' -S %s | FileCheck -check-prefixes='IR' %s +; RUN: opt -passes='function(require),ipsccp,function(verify)' -S %s | FileCheck -check-prefixes='IR' %s ; NEW-PM: Starting llvm::Module pass manager run. -; NEW-PM-NEXT: Running pass: IPSCCPPass -; NEW-PM-DAG: Running analysis: TargetLibraryAnalysis -; NEW-PM-DAG: Running analysis: InnerAnalysisManagerProxy +; NEW-PM: Running analysis: DominatorTreeAnalysis on f1 +; NEW-PM: Running analysis: PostDominatorTreeAnalysis on f1 +; NEW-PM: Running analysis: DominatorTreeAnalysis on f2 +; NEW-PM: Running analysis: PostDominatorTreeAnalysis on f2 +; NEW-PM: Running pass: IPSCCPPass ; NEW-PM-DAG: Running analysis: AssumptionAnalysis on f1 -; NEW-PM-DAG: Running analysis: DominatorTreeAnalysis on f1 -; NEW-PM-DAG: Running analysis: PassInstrumentationAnalysis on f1 -; NEW-PM-DAG: Running analysis: DominatorTreeAnalysis on f2 ; NEW-PM-DAG: Running analysis: AssumptionAnalysis on f2 -; NEW-PM-DAG: Running analysis: PassInstrumentationAnalysis on f2 ; NEW-PM-NEXT: Invalidating all non-preserved analyses for: ; NEW-PM-NEXT: Invalidating all non-preserved analyses for: f1 ; NEW-PM-NEXT: Invalidating all non-preserved analyses for: f2 -; NEW-PM-NEXT: Running pass: GlobalOptPass on -; NEW-PM-DAG: Running analysis: BlockFrequencyAnalysis on f2 -; NEW-PM-DAG: Running analysis: LoopAnalysis on f2 -; NEW-PM-DAG: Running analysis: BranchProbabilityAnalysis on f2 -; NEW-PM-DAG: Running analysis: TargetLibraryAnalysis on f2 -; NEW-PM-NEXT: Running analysis: TargetIRAnalysis on f1 -; NEW-PM-NEXT: Invalidating all non-preserved analyses for: +; NEW-PM-NEXT: Running pass: ModuleToFunctionPassAdaptor +; NEW-PM-NOT: Running analysis: ; IR-LABEL: @f1 ; IR-LABEL: entry: