Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -150,6 +150,12 @@ PM.add(createAddDiscriminatorsPass()); } +static void addPGOOnlyOptimizations( + const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) { + PM.add(createLoopSinkPass()); + PM.add(createInstructionSimplifierPass()); +} + static void addBoundsCheckingPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) { PM.add(createBoundsCheckingPass()); @@ -459,6 +465,10 @@ MPM.add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile)); } + if (!CodeGenOpts.SampleProfileFile.empty() || CodeGenOpts.hasProfileIRUse()) + PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast, + addPGOOnlyOptimizations); + PMBuilder.populateFunctionPassManager(FPM); PMBuilder.populateModulePassManager(MPM); }