From 3fd1902ad8ebfaecc57e68aaa6620332dda8d5f9 Mon Sep 17 00:00:00 2001 From: Sjoerd Meijer Date: Thu, 4 Nov 2021 10:36:19 +0000 Subject: [PATCH] [FuncSpec] Enable it only with -O3 Function specialisation was running at all optimisation levels (if enabled on the command line, it is not on by default). That was an oversight and not something we want to do. Function specialisation duplicates functions when it triggers, so the backend is processing more functions/instructions resulting in compile-time increases, which seems more appropriate with -O3 and inline with GCC. Please note that since function specialisation is not enabled by default, this didn't require updating any pass manager tests. Differential Revision: https://reviews.llvm.org/D112129 --- llvm/lib/Passes/PassBuilderPipelines.cpp | 4 ++-- llvm/lib/Transforms/IPO/PassManagerBuilder.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index f0f7803..8274aee 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -832,7 +832,7 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, 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 @@ -1406,7 +1406,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level, MPM.addPass(PGOIndirectCallPromotion( true /* InLTO */, PGOOpt && PGOOpt->Action == PGOOptions::SampleUse)); - if (EnableFunctionSpecialization) + if (EnableFunctionSpecialization && Level == OptimizationLevel::O3) MPM.addPass(FunctionSpecializationPass()); // Propagate constants at call sites into the functions they call. This // opens opportunities for globalopt (and inlining) by substituting function diff --git a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp index f0b5589..74f6853 100644 --- a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp +++ b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -1017,7 +1017,7 @@ void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) { 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 -- 2.7.4