diff --git a/lib/Passes/PassBuilder.cpp b/lib/Passes/PassBuilder.cpp index bb7d800f8b4..52f7026c40e 100644 --- a/lib/Passes/PassBuilder.cpp +++ b/lib/Passes/PassBuilder.cpp @@ -1539,8 +1539,17 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline( MPM.addPass(LowerTypeTestsPass(nullptr, ImportSummary)); } - if (Level == OptimizationLevel::O0) + if (Level == OptimizationLevel::O0) { + // Run a second time to clean up any type tests left behind by WPD for use + // in ICP. + MPM.addPass(LowerTypeTestsPass(nullptr, nullptr, true)); + // Drop available_externally and unreferenced globals. This is necessary + // with ThinLTO in order to avoid leaving undefined references to dead + // globals in the object file. + MPM.addPass(EliminateAvailableExternallyPass()); + MPM.addPass(GlobalDCEPass()); return MPM; + } // Force any function attributes we want the rest of the pipeline to observe. MPM.addPass(ForceFunctionAttrsPass()); diff --git a/test/Other/new-pm-O0-defaults.ll b/test/Other/new-pm-O0-defaults.ll index 8900a77b1f2..b7cd5ecae79 100644 --- a/test/Other/new-pm-O0-defaults.ll +++ b/test/Other/new-pm-O0-defaults.ll @@ -35,6 +35,9 @@ ; CHECK-PRE-LINK-NEXT: Running pass: CanonicalizeAliasesPass ; CHECK-PRE-LINK-NEXT: Running pass: NameAnonGlobalPass ; CHECK-THINLTO-NEXT: Running pass: Annotation2MetadataPass +; CHECK-THINLTO-NEXT: Running pass: LowerTypeTestsPass +; CHECK-THINLTO-NEXT: Running pass: EliminateAvailableExternallyPass +; CHECK-THINLTO-NEXT: Running pass: GlobalDCEPass ; CHECK-LTO-NEXT: Running pass: Annotation2MetadataPass ; CHECK-LTO-NEXT: Running pass: WholeProgramDevirtPass ; CHECK-LTO-NEXT: Running analysis: InnerAnalysisManagerProxy