Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -178,6 +178,11 @@ PM.add(createAddDiscriminatorsPass()); } +static void addInstructionCombiningPass(const PassManagerBuilder &Builder, + legacy::PassManagerBase &PM) { + PM.add(createInstructionCombiningPass()); +} + static void addBoundsCheckingPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) { PM.add(createBoundsCheckingPass()); @@ -439,7 +444,6 @@ legacy::FunctionPassManager *FPM = getPerFunctionPasses(); if (CodeGenOpts.VerifyModule) FPM->add(createVerifierPass()); - PMBuilder.populateFunctionPassManager(*FPM); // Set up the per-module pass manager. if (!CodeGenOpts.RewriteMapFiles.empty()) @@ -478,9 +482,13 @@ if (CodeGenOpts.hasProfileIRUse()) PMBuilder.PGOInstrUse = CodeGenOpts.ProfileInstrumentUsePath; - if (!CodeGenOpts.SampleProfileFile.empty()) + if (!CodeGenOpts.SampleProfileFile.empty()) { MPM->add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile)); + PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, + addInstructionCombiningPass); + } + PMBuilder.populateFunctionPassManager(*FPM); PMBuilder.populateModulePassManager(*MPM); }