diff --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll b/clang/test/CodeGen/thinlto-distributed-newpm.ll --- a/clang/test/CodeGen/thinlto-distributed-newpm.ll +++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll @@ -78,7 +78,7 @@ ; CHECK-O: Running pass: GlobalDCEPass ; CHECK-O: Running pass: EliminateAvailableExternallyPass ; CHECK-O: Running pass: ReversePostOrderFunctionAttrsPass -; CHECK-O: Running pass: RequireAnalysisPass<{{.*}}GlobalsAA +; CHECK-O: Running pass: RecomputeGlobalsAAPass ; CHECK-O: Running pass: Float2IntPass on main ; CHECK-O: Running pass: LowerConstantIntrinsicsPass on main ; CHECK-O: Running pass: LoopSimplifyPass on main diff --git a/llvm/include/llvm/Analysis/GlobalsModRef.h b/llvm/include/llvm/Analysis/GlobalsModRef.h --- a/llvm/include/llvm/Analysis/GlobalsModRef.h +++ b/llvm/include/llvm/Analysis/GlobalsModRef.h @@ -14,6 +14,7 @@ #define LLVM_ANALYSIS_GLOBALSMODREF_H #include "llvm/Analysis/AliasAnalysis.h" +#include "llvm/IR/PassManager.h" #include "llvm/IR/ValueHandle.h" #include "llvm/Pass.h" #include @@ -77,6 +78,8 @@ const DataLayout &DL, std::function GetTLI); + friend struct RecomputeGlobalsAAPass; + public: GlobalsAAResult(GlobalsAAResult &&Arg); ~GlobalsAAResult(); @@ -137,6 +140,10 @@ GlobalsAAResult run(Module &M, ModuleAnalysisManager &AM); }; +struct RecomputeGlobalsAAPass : PassInfoMixin { + PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); +}; + /// Legacy wrapper pass to provide the GlobalsAAResult object. class GlobalsAAWrapperPass : public ModulePass { std::unique_ptr Result; diff --git a/llvm/lib/Analysis/GlobalsModRef.cpp b/llvm/lib/Analysis/GlobalsModRef.cpp --- a/llvm/lib/Analysis/GlobalsModRef.cpp +++ b/llvm/lib/Analysis/GlobalsModRef.cpp @@ -25,6 +25,7 @@ #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Module.h" +#include "llvm/IR/PassManager.h" #include "llvm/InitializePasses.h" #include "llvm/Pass.h" #include "llvm/Support/CommandLine.h" @@ -1009,6 +1010,24 @@ AM.getResult(M)); } +PreservedAnalyses RecomputeGlobalsAAPass::run(Module &M, + ModuleAnalysisManager &AM) { + if (auto *G = AM.getCachedResult(M)) { + auto &CG = AM.getResult(M); + G->NonAddressTakenGlobals.clear(); + G->UnknownFunctionsWithLocalLinkage = false; + G->IndirectGlobals.clear(); + G->AllocsForIndirectGlobals.clear(); + G->FunctionInfos.clear(); + G->FunctionToSCCMap.clear(); + G->Handles.clear(); + G->CollectSCCMembership(CG); + G->AnalyzeGlobals(M); + G->AnalyzeCallGraph(CG, M); + } + return PreservedAnalyses::all(); +} + char GlobalsAAWrapperPass::ID = 0; INITIALIZE_PASS_BEGIN(GlobalsAAWrapperPass, "globals-aa", "Globals Alias Analysis", false, true) diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -1159,14 +1159,14 @@ PGOOpt->ProfileRemappingFile); } - // Re-require GloblasAA here prior to function passes. This is particularly + // Re-compute GlobalsAA here prior to function passes. This is particularly // useful as the above will have inlined, DCE'ed, and function-attr // propagated everything. We should at this point have a reasonably minimal // and richly annotated call graph. By computing aliasing and mod/ref // information for all local globals here, the late loop passes and notably // the vectorizer will be able to use them to help recognize vectorizable // memory operations. - MPM.addPass(RequireAnalysisPass()); + MPM.addPass(RecomputeGlobalsAAPass()); FunctionPassManager OptimizePM; OptimizePM.addPass(Float2IntPass()); diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -94,6 +94,7 @@ MODULE_PASS("print-must-be-executed-contexts", MustBeExecutedContextPrinterPass(dbgs())) MODULE_PASS("print-stack-safety", StackSafetyGlobalPrinterPass(dbgs())) MODULE_PASS("print", ModuleDebugInfoPrinterPass(dbgs())) +MODULE_PASS("recompute-globalsaa", RecomputeGlobalsAAPass()) MODULE_PASS("rel-lookup-table-converter", RelLookupTableConverterPass()) MODULE_PASS("rewrite-statepoints-for-gc", RewriteStatepointsForGC()) MODULE_PASS("rewrite-symbols", RewriteSymbolPass()) diff --git a/llvm/test/Other/new-pm-defaults.ll b/llvm/test/Other/new-pm-defaults.ll --- a/llvm/test/Other/new-pm-defaults.ll +++ b/llvm/test/Other/new-pm-defaults.ll @@ -217,7 +217,7 @@ ; CHECK-DEFAULT-NEXT: Running pass: EliminateAvailableExternallyPass ; CHECK-LTO-NOT: Running pass: EliminateAvailableExternallyPass ; CHECK-O-NEXT: Running pass: ReversePostOrderFunctionAttrsPass -; CHECK-O-NEXT: Running pass: RequireAnalysisPass<{{.*}}GlobalsAA +; CHECK-O-NEXT: Running pass: RecomputeGlobalsAAPass ; CHECK-O-NEXT: Running pass: Float2IntPass ; CHECK-O-NEXT: Running pass: LowerConstantIntrinsicsPass on foo ; CHECK-MATRIX: Running pass: LowerMatrixIntrinsicsPass on f diff --git a/llvm/test/Other/new-pm-thinlto-defaults.ll b/llvm/test/Other/new-pm-thinlto-defaults.ll --- a/llvm/test/Other/new-pm-thinlto-defaults.ll +++ b/llvm/test/Other/new-pm-thinlto-defaults.ll @@ -189,7 +189,7 @@ ; CHECK-POSTLINK-O-NEXT: Running pass: GlobalDCEPass ; CHECK-POSTLINK-O-NEXT: Running pass: EliminateAvailableExternallyPass ; CHECK-POSTLINK-O-NEXT: Running pass: ReversePostOrderFunctionAttrsPass -; CHECK-POSTLINK-O-NEXT: Running pass: RequireAnalysisPass<{{.*}}GlobalsAA +; CHECK-POSTLINK-O-NEXT: Running pass: RecomputeGlobalsAAPass ; CHECK-POSTLINK-O-NEXT: Running pass: Float2IntPass ; CHECK-POSTLINK-O-NEXT: Running pass: LowerConstantIntrinsicsPass ; CHECK-EXT: Running pass: {{.*}}::Bye diff --git a/llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll b/llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll --- a/llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll +++ b/llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll @@ -160,7 +160,7 @@ ; CHECK-O-NEXT: Running pass: GlobalDCEPass ; CHECK-O-NEXT: Running pass: EliminateAvailableExternallyPass ; CHECK-O-NEXT: Running pass: ReversePostOrderFunctionAttrsPass -; CHECK-O-NEXT: Running pass: RequireAnalysisPass<{{.*}}GlobalsAA +; CHECK-O-NEXT: Running pass: RecomputeGlobalsAAPass ; CHECK-O-NEXT: Running pass: Float2IntPass ; CHECK-O-NEXT: Running pass: LowerConstantIntrinsicsPass ; CHECK-EXT: Running pass: {{.*}}::Bye diff --git a/llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll b/llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll --- a/llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll +++ b/llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll @@ -172,7 +172,7 @@ ; CHECK-O-NEXT: Running pass: GlobalDCEPass ; CHECK-O-NEXT: Running pass: EliminateAvailableExternallyPass ; CHECK-O-NEXT: Running pass: ReversePostOrderFunctionAttrsPass -; CHECK-O-NEXT: Running pass: RequireAnalysisPass<{{.*}}GlobalsAA +; CHECK-O-NEXT: Running pass: RecomputeGlobalsAAPass ; CHECK-O-NEXT: Running pass: Float2IntPass ; CHECK-O-NEXT: Running pass: LowerConstantIntrinsicsPass ; CHECK-EXT: Running pass: {{.*}}::Bye diff --git a/llvm/test/Transforms/PhaseOrdering/recompute-globalsaa.ll b/llvm/test/Transforms/PhaseOrdering/recompute-globalsaa.ll --- a/llvm/test/Transforms/PhaseOrdering/recompute-globalsaa.ll +++ b/llvm/test/Transforms/PhaseOrdering/recompute-globalsaa.ll @@ -12,12 +12,6 @@ ; CHECK-NEXT: store i1 true, i1* @a, align 4 ; CHECK-NEXT: [[TMP0:%.*]] = load i32*, i32** @e, align 8 ; CHECK-NEXT: store i32 0, i32* [[TMP0]], align 4 -; CHECK-NEXT: [[DOTB:%.*]] = load i1, i1* @a, align 4 -; CHECK-NEXT: br i1 [[DOTB]], label [[BAR_EXIT:%.*]], label [[IF_THEN_I:%.*]] -; CHECK: if.then.i: -; CHECK-NEXT: tail call void @foo() -; CHECK-NEXT: br label [[BAR_EXIT]] -; CHECK: bar.exit: ; CHECK-NEXT: store i32* null, i32** @e, align 8 ; CHECK-NEXT: ret i32 0 ;