Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -341,12 +341,19 @@ MPM.add(new TargetLibraryInfoWrapperPass(*TLII)); // Add target-specific passes that need to run as early as possible. - if (TM) + if (TM) { PMBuilder.addExtension( PassManagerBuilder::EP_EarlyAsPossible, [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) { - TM->addEarlyAsPossiblePasses(PM); + TM->addEarlyAsPossiblePasses(PM, PMT_FunctionPassManager); + }); + + PMBuilder.addExtension( + PassManagerBuilder::EP_ModuleOptimizerEarly, + [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) { + TM->addEarlyAsPossiblePasses(PM, PMT_ModulePassManager); }); + } PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, addAddDiscriminatorsPass);