@@ -831,8 +831,11 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
831
831
if (AttributorRun & AttributorRunOption::CGSCC)
832
832
MainCGPipeline.addPass (AttributorCGSCCPass ());
833
833
834
- // Now deduce any function attributes based in the current code.
835
- MainCGPipeline.addPass (PostOrderFunctionAttrsPass ());
834
+ // Deduce function attributes. We do another run of this after the function
835
+ // simplification pipeline, so this only needs to run when it could affect the
836
+ // function simplification pipeline, which is only the case with recursive
837
+ // functions.
838
+ MainCGPipeline.addPass (PostOrderFunctionAttrsPass (/* SkipNonRecursive*/ true ));
836
839
837
840
// When at O3 add argument promotion to the pass pipeline.
838
841
// FIXME: It isn't at all clear why this should be limited to O3.
@@ -847,14 +850,25 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
847
850
for (auto &C : CGSCCOptimizerLateEPCallbacks)
848
851
C (MainCGPipeline, Level);
849
852
850
- // Lastly, add the core function simplification pipeline nested inside the
853
+ // Add the core function simplification pipeline nested inside the
851
854
// CGSCC walk.
852
855
MainCGPipeline.addPass (createCGSCCToFunctionPassAdaptor (
853
856
buildFunctionSimplificationPipeline (Level, Phase),
854
857
PTO.EagerlyInvalidateAnalyses , /* NoRerun=*/ true ));
855
858
859
+ // Finally, deduce any function attributes based on the fully simplified
860
+ // function.
861
+ MainCGPipeline.addPass (PostOrderFunctionAttrsPass ());
862
+
863
+ // Mark that the function is fully simplified and that it shouldn't be
864
+ // simplified again if we somehow revisit it due to CGSCC mutations unless
865
+ // it's been modified since.
866
+ MainCGPipeline.addPass (createCGSCCToFunctionPassAdaptor (
867
+ RequireAnalysisPass<ShouldNotRunFunctionPassesAnalysis, Function>()));
868
+
856
869
MainCGPipeline.addPass (CoroSplitPass (Level != OptimizationLevel::O0));
857
870
871
+ // Make sure we don't affect potential future NoRerun CGSCC adaptors.
858
872
MIWP.addLateModulePass (createModuleToFunctionPassAdaptor (
859
873
InvalidateAnalysisPass<ShouldNotRunFunctionPassesAnalysis>()));
860
874
0 commit comments