Index: llvm/lib/Passes/PassBuilderPipelines.cpp =================================================================== --- llvm/lib/Passes/PassBuilderPipelines.cpp +++ llvm/lib/Passes/PassBuilderPipelines.cpp @@ -832,7 +832,7 @@ C(MPM, Level); // Specialize functions with IPSCCP. - if (EnableFunctionSpecialization) + if (EnableFunctionSpecialization && Level == OptimizationLevel::O3) MPM.addPass(FunctionSpecializationPass()); // Interprocedural constant propagation now that basic cleanup has occurred @@ -1399,7 +1399,7 @@ MPM.addPass(PGOIndirectCallPromotion( true /* InLTO */, PGOOpt && PGOOpt->Action == PGOOptions::SampleUse)); - if (EnableFunctionSpecialization) + if (EnableFunctionSpecialization && Level.getSpeedupLevel() > 2) MPM.addPass(FunctionSpecializationPass()); // Propagate constants at call sites into the functions they call. This // opens opportunities for globalopt (and inlining) by substituting function Index: llvm/lib/Transforms/IPO/PassManagerBuilder.cpp =================================================================== --- llvm/lib/Transforms/IPO/PassManagerBuilder.cpp +++ llvm/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -1017,7 +1017,7 @@ createPGOIndirectCallPromotionLegacyPass(true, !PGOSampleUse.empty())); // Propage constant function arguments by specializing the functions. - if (EnableFunctionSpecialization) + if (EnableFunctionSpecialization && OptLevel > 2) PM.add(createFunctionSpecializationPass()); // Propagate constants at call sites into the functions they call. This