[llvm] a9b33ff - [ThinLTO][NewPM] Clean up dead code under -O0
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 24 17:09:18 PST 2021
Author: Arthur Eubanks
Date: 2021-02-24T17:08:57-08:00
New Revision: a9b33ffb8f84f0f5b1c2253973ed04bc776bd710
URL: https://github.com/llvm/llvm-project/commit/a9b33ffb8f84f0f5b1c2253973ed04bc776bd710
DIFF: https://github.com/llvm/llvm-project/commit/a9b33ffb8f84f0f5b1c2253973ed04bc776bd710.diff
LOG: [ThinLTO][NewPM] Clean up dead code under -O0
We're running into undefined references using ThinLTO with -O0 on
Windows/Chrome. This fixes that.
This matches the legacy PM.
Reviewed By: tejohnson
Differential Revision: https://reviews.llvm.org/D97414
Added:
Modified:
llvm/lib/Passes/PassBuilder.cpp
llvm/test/Other/new-pm-O0-defaults.ll
Removed:
################################################################################
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index bb7d800f8b4f..52f7026c40eb 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/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/llvm/test/Other/new-pm-O0-defaults.ll b/llvm/test/Other/new-pm-O0-defaults.ll
index 8900a77b1f22..b7cd5ecae795 100644
--- a/llvm/test/Other/new-pm-O0-defaults.ll
+++ b/llvm/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
More information about the llvm-commits
mailing list