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 @@ -635,7 +635,7 @@ FunctionPassManager FPM; FPM.addPass(SROAPass()); - FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies. + FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies. FPM.addPass(SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp( true))); // Merge & remove basic blocks. FPM.addPass(InstCombinePass()); // Combine silly sequences. @@ -728,10 +728,9 @@ if (PGOOpt) IP.EnableDeferral = EnablePGOInlineDeferral; - ModuleInlinerWrapperPass MIWP( - IP, PerformMandatoryInliningsFirst, - InlineContext{Phase, InlinePass::CGSCCInliner}, - UseInlineAdvisor, MaxDevirtIterations); + ModuleInlinerWrapperPass MIWP(IP, PerformMandatoryInliningsFirst, + InlineContext{Phase, InlinePass::CGSCCInliner}, + UseInlineAdvisor, MaxDevirtIterations); // Require the GlobalsAA analysis for the module so we can query it within // the CGSCC pipeline. @@ -767,6 +766,14 @@ if (Level == OptimizationLevel::O3) MainCGPipeline.addPass(ArgumentPromotionPass()); + // The ArgumentPromotion pass runs Mem2Reg promotion at the end and this can + // make some arguments unused in the callee. Any unused arguments must be + // removed. + // FIXME: If ArgumentPromotionPass wouldn't be limited to O3, this also + // shouldn't. + if (Level == OptimizationLevel::O3) + MIWP.addLateModulePass(DeadArgumentEliminationPass()); + // Try to perform OpenMP specific optimizations. This is a (quick!) no-op if // there are no OpenMP runtime calls present in the module. if (Level == OptimizationLevel::O2 || Level == OptimizationLevel::O3) @@ -1612,7 +1619,7 @@ getInlineParamsFromOptLevel(Level), /* MandatoryFirst */ true, InlineContext{ThinOrFullLTOPhase::FullLTOPostLink, - InlinePass::CGSCCInliner})); + InlinePass::CGSCCInliner})); // Optimize globals again after we ran the inliner. MPM.addPass(GlobalOptPass()); @@ -1624,6 +1631,11 @@ // transform it to pass arguments by value instead of by reference. MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(ArgumentPromotionPass())); + // The ArgumentPromotion pass runs Mem2Reg promotion at the end and this + // can make some arguments unused in the callee. Any unused arguments must be + // removed. + MPM.addPass(DeadArgumentEliminationPass()); + FunctionPassManager FPM; // The IPO Passes may leave cruft around. Clean up after them. FPM.addPass(InstCombinePass()); @@ -1686,7 +1698,6 @@ MainFPM.addPass(DSEPass()); MainFPM.addPass(MergedLoadStoreMotionPass()); - if (EnableConstraintElimination) MainFPM.addPass(ConstraintEliminationPass()); @@ -1711,8 +1722,7 @@ addVectorPasses(Level, MainFPM, /* IsFullLTO */ true); // Run the OpenMPOpt CGSCC pass again late. - MPM.addPass( - createModuleToPostOrderCGSCCPassAdaptor(OpenMPOptCGSCCPass())); + MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(OpenMPOptCGSCCPass())); invokePeepholeEPCallbacks(MainFPM, Level); MainFPM.addPass(JumpThreadingPass()); 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 @@ -214,6 +214,7 @@ ; CHECK-O-NEXT: Running pass: InstCombinePass ; CHECK-EP-PEEPHOLE-NEXT: Running pass: NoOpFunctionPass ; CHECK-O-NEXT: Running pass: CoroSplitPass +; CHECK-O3-NEXT: Running pass: DeadArgumentEliminationPass ; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis ; CHECK-O-NEXT: Running pass: CoroCleanupPass ; CHECK-O-NEXT: Running pass: GlobalOptPass diff --git a/llvm/test/Other/new-pm-lto-defaults.ll b/llvm/test/Other/new-pm-lto-defaults.ll --- a/llvm/test/Other/new-pm-lto-defaults.ll +++ b/llvm/test/Other/new-pm-lto-defaults.ll @@ -87,6 +87,7 @@ ; CHECK-O23SZ-NEXT: Running pass: GlobalOptPass ; CHECK-O23SZ-NEXT: Running pass: GlobalDCEPass ; CHECK-O23SZ-NEXT: Running pass: ArgumentPromotionPass +; CHECK-O23SZ-NEXT: Running pass: DeadArgumentEliminationPass ; CHECK-O23SZ-NEXT: Running pass: InstCombinePass ; CHECK-EP-Peephole-NEXT: Running pass: NoOpFunctionPass ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass 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 @@ -183,6 +183,7 @@ ; CHECK-O-NEXT: Running pass: SimplifyCFGPass ; CHECK-O-NEXT: Running pass: InstCombinePass ; CHECK-O-NEXT: Running pass: CoroSplitPass +; CHECK-O3-NEXT: Running pass: DeadArgumentEliminationPass ; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis ; CHECK-O-NEXT: Running pass: CoroCleanupPass ; CHECK-PRELINK-O-NEXT: Running pass: GlobalOptPass 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 @@ -155,6 +155,7 @@ ; CHECK-O-NEXT: Running pass: SimplifyCFGPass ; CHECK-O-NEXT: Running pass: InstCombinePass ; CHECK-O-NEXT: Running pass: CoroSplitPass +; CHECK-O3-NEXT: Running pass: DeadArgumentEliminationPass ; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis ; CHECK-O-NEXT: Running pass: CoroCleanupPass ; CHECK-O-NEXT: Running pass: GlobalOptPass 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 @@ -167,6 +167,7 @@ ; CHECK-O3-NEXT: Running analysis: RegionInfoAnalysis on foo ; CHECK-O3-NEXT: Running analysis: DominanceFrontierAnalysis on foo ; CHECK-O-NEXT: Running pass: CoroSplitPass +; CHECK-O3-NEXT: Running pass: DeadArgumentEliminationPass ; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis ; CHECK-O-NEXT: Running pass: CoroCleanupPass ; CHECK-O-NEXT: Running pass: GlobalOptPass diff --git a/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll b/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll --- a/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll +++ b/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll @@ -196,6 +196,7 @@ ; CHECK-O3-NEXT: Running analysis: RegionInfoAnalysis on foo ; CHECK-O3-NEXT: Running analysis: DominanceFrontierAnalysis on foo ; CHECK-O-NEXT: Running pass: CoroSplitPass +; CHECK-O3-NEXT: Running pass: DeadArgumentEliminationPass ; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis ; CHECK-O-NEXT: Running pass: CoroCleanupPass ; CHECK-O-NEXT: Running pass: GlobalOptPass diff --git a/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll b/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll --- a/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll +++ b/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll @@ -161,6 +161,7 @@ ; CHECK-O3-NEXT: Running analysis: RegionInfoAnalysis on foo ; CHECK-O3-NEXT: Running analysis: DominanceFrontierAnalysis on foo ; CHECK-O-NEXT: Running pass: CoroSplitPass +; CHECK-O3-NEXT: Running pass: DeadArgumentEliminationPass ; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis ; CHECK-O-NEXT: Running pass: CoroCleanupPass ; CHECK-O-NEXT: Running pass: GlobalOptPass diff --git a/llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll b/llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll --- a/llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll +++ b/llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll @@ -9,7 +9,7 @@ define internal void @f(%struct.ss* byval(%struct.ss) align 8 %b, i32* byval(i32) align 4 %X) noinline nounwind { ; CHECK-LABEL: define {{[^@]+}}@f -; CHECK-SAME: (i32 [[B_0:%.*]], i32 [[X:%.*]]){{[^#]*}} #[[ATTR0:[0-9]+]] { +; CHECK-SAME: (i32 [[B_0:%.*]]){{[^#]*}} #[[ATTR0:[0-9]+]] { ; CHECK-NEXT: entry: ; CHECK-NEXT: [[TEMP:%.*]] = add i32 [[B_0]], 1 ; CHECK-NEXT: store i32 [[TEMP]], i32* [[DUMMY]], align 4 @@ -28,8 +28,7 @@ ; CHECK-LABEL: define {{[^@]+}}@test ; CHECK-SAME: (i32* {{[^%]*}} [[X:%.*]]){{[^#]*}} #[[ATTR1:[0-9]+]] { ; CHECK-NEXT: entry: -; CHECK-NEXT: [[X_VAL:%.*]] = load i32, i32* [[X]], align 4 -; CHECK-NEXT: tail call {{.*}}void @f(i32 1, i32 [[X_VAL]]) +; CHECK-NEXT: tail call {{.*}}void @f(i32 1) ; CHECK-NEXT: ret i32 0 ; entry: