@@ -831,8 +831,11 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
831831 if (AttributorRun & AttributorRunOption::CGSCC)
832832 MainCGPipeline.addPass (AttributorCGSCCPass ());
833833
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 ));
836839
837840 // When at O3 add argument promotion to the pass pipeline.
838841 // FIXME: It isn't at all clear why this should be limited to O3.
@@ -847,14 +850,25 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
847850 for (auto &C : CGSCCOptimizerLateEPCallbacks)
848851 C (MainCGPipeline, Level);
849852
850- // Lastly, add the core function simplification pipeline nested inside the
853+ // Add the core function simplification pipeline nested inside the
851854 // CGSCC walk.
852855 MainCGPipeline.addPass (createCGSCCToFunctionPassAdaptor (
853856 buildFunctionSimplificationPipeline (Level, Phase),
854857 PTO.EagerlyInvalidateAnalyses , /* NoRerun=*/ true ));
855858
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+
856869 MainCGPipeline.addPass (CoroSplitPass (Level != OptimizationLevel::O0));
857870
871+ // Make sure we don't affect potential future NoRerun CGSCC adaptors.
858872 MIWP.addLateModulePass (createModuleToFunctionPassAdaptor (
859873 InvalidateAnalysisPass<ShouldNotRunFunctionPassesAnalysis>()));
860874
0 commit comments