Page MenuHomePhabricator

[ThinLTO/FullLTO] Support Os and Oz
Needs ReviewPublic

Authored by ychen on Jan 8 2020, 10:35 AM.

Details

Summary
  • When optnone is not present, add optsize for Os and minsize for Oz.
  • Pass Os/Oz to (old/new PM) LTO pipeline setup.
  • Ran SPEC2017 & test-suite MultiSource to confirm the size reduction are comparable with NonLTO.

Diff Detail

Event Timeline

ychen created this revision.Jan 8 2020, 10:35 AM
Herald added a project: Restricted Project. · View Herald Transcript
ychen retitled this revision from [ThinLTO] Support Os and Oz to [WIP][ThinLTO] Support Os and Oz.Jan 8 2020, 10:35 AM
pcc requested changes to this revision.Jan 8 2020, 10:47 AM
pcc added a subscriber: pcc.

This is going in the wrong direction IMO. We already have a way of specifying the size optimization level, which is to specify -Os or -Oz at compile time. Why is that not sufficient?

This revision now requires changes to proceed.Jan 8 2020, 10:47 AM
ychen edited the summary of this revision. (Show Details)Jan 8 2020, 10:47 AM
ormris added a subscriber: ormris.Jan 8 2020, 10:50 AM
ychen added a comment.EditedJan 8 2020, 11:03 AM
In D72404#1810489, @pcc wrote:

This is going in the wrong direction IMO. We already have a way of specifying the size optimization level, which is to specify -Os or -Oz at compile time. Why is that not sufficient?

Thanks for the quick feedback, @pcc. :-) I saw your comments somewhere on this.
I don't know why is this changing directions. It only gives the user choice to optimize for size at link stage.
They still have the freedom the do this at compile stage.

From user perspective, if O1, O2 etc. are valid options for linker stage,
I don't see a reason Os and Oz can not be used or not do the right thing.

With ThinLTO, many decisions are postponed til linker stage to have more flexibility. I guess this is one of them?

Unit tests: fail. 60542 tests passed, 1 failed and 726 were skipped.

failed: lld.wasm/lto/opt-level.ll

clang-tidy: fail. Please fix clang-tidy findings.

clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

ychen updated this revision to Diff 236907.Jan 8 2020, 2:31 PM
ychen edited the summary of this revision. (Show Details)
  • fix test
ychen updated this revision to Diff 236908.Jan 8 2020, 2:32 PM

fix test

Unit tests: unknown.

clang-tidy: unknown.

clang-format: unknown.

Build artifacts: diff.json, console-log.txt

Unit tests: fail. 60542 tests passed, 1 failed and 726 were skipped.

failed: lld.ELF/note.s

clang-tidy: fail. Please fix clang-tidy findings.

clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

ychen updated this revision to Diff 238028.Jan 14 2020, 10:15 AM
  • when optnone is not present, add optsize for Os and minsize for Oz
  • add Os Oz function attribute test.
  • add Os Oz pipeline test
Herald added a project: Restricted Project. · View Herald TranscriptJan 14 2020, 10:15 AM
ychen updated this revision to Diff 238034.Jan 14 2020, 10:28 AM
  • fix a typo
ychen updated this revision to Diff 238042.Jan 14 2020, 10:54 AM
  • Rebase

Unit tests: fail. 60543 tests passed, 1 failed and 726 were skipped.

failed: Clang.CodeGen/thinlto-debug-pm.c

clang-tidy: unknown.

clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Unit tests: fail. 60543 tests passed, 1 failed and 726 were skipped.

failed: Clang.CodeGen/thinlto-debug-pm.c

clang-tidy: unknown.

clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Unit tests: fail. 61849 tests passed, 1 failed and 781 were skipped.

failed: Clang.CodeGen/thinlto-debug-pm.c

clang-tidy: unknown.

clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

MaskRay added a subscriber: tycho.
ychen updated this revision to Diff 238071.Jan 14 2020, 12:34 PM
  • rebase & clang-format
ychen retitled this revision from [WIP][ThinLTO] Support Os and Oz to [ThinLTO/FullLTO] Support Os and Oz.Jan 14 2020, 12:39 PM
ychen edited the summary of this revision. (Show Details)
ychen edited reviewers, added: steven_wu, tejohnson, mehdi_amini; removed: espindola.

Unit tests: fail. 61858 tests passed, 1 failed and 781 were skipped.

failed: Clang.CodeGen/thinlto-debug-pm.c

clang-tidy: unknown.

clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

tycho added a subscriber: merge_guards_bot.EditedJan 14 2020, 1:58 PM

Unit tests: fail. 61858 tests passed, 1 failed and 781 were skipped.

failed: Clang.CodeGen/thinlto-debug-pm.c

I think that failure can be fixed with something like this:

diff --git a/clang/test/CodeGen/thinlto-debug-pm.c b/clang/test/CodeGen/thinlto-debug-pm.c
index 5f449d493af..185a8c8fb8b 100644
--- a/clang/test/CodeGen/thinlto-debug-pm.c
+++ b/clang/test/CodeGen/thinlto-debug-pm.c
@@ -13,17 +13,17 @@
 // O0123sz-NEWPM: Running analysis: PassInstrumentationAnalysis
 // O0123sz-NEWPM: Starting llvm::Module pass manager run.
 // O0123sz-NEWPM: Running pass: WholeProgramDevirtPass
-// O0123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::AnalysisManager<llvm::Function>, llvm::Module>
+// O0123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::FunctionAnalysisManager, llvm::Module>
 // O0123sz-NEWPM: Running pass: LowerTypeTestsPass
 // O0123sz-NEWPM: Invalidating all non-preserved analyses for:
-// O0123sz-NEWPM: Invalidating analysis: InnerAnalysisManagerProxy<llvm::AnalysisManager<llvm::Function>, llvm::Module>
+// O0123sz-NEWPM: Invalidating analysis: InnerAnalysisManagerProxy<llvm::FunctionAnalysisManager, llvm::Module>
 // O123sz-NEWPM: Running pass: ForceFunctionAttrsPass
 // O123sz-NEWPM: Running pass: PassManager<llvm::Module>
 // O123sz-NEWPM: Starting llvm::Module pass manager run.
 // O123sz-NEWPM: Running pass: PGOIndirectCallPromotion
 // O123sz-NEWPM: Running analysis: ProfileSummaryAnalysis
 // O123sz-NEWPM: Running pass: InferFunctionAttrsPass
-// O123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::AnalysisManager<llvm::Function>, llvm::Module>
+// O123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::FunctionAnalysisManager, llvm::Module>
 // O123sz-NEWPM: Running pass: ModuleToFunctionPassAdaptor<llvm::PassManager<llvm::Function> >
 // O123sz-NEWPM: Running analysis: PassInstrumentationAnalysis on foo
 // O123sz-NEWPM: Starting llvm::Function pass manager run.
@@ -41,9 +41,9 @@
 // O123sz-NEWPM: Running pass: CalledValuePropagationPass
 // O123sz-NEWPM: Running pass: GlobalOptPass
 // O123sz-NEWPM: Invalidating all non-preserved analyses for:
-// O123sz-NEWPM: Invalidating analysis: InnerAnalysisManagerProxy<llvm::AnalysisManager<llvm::Function>, llvm::Module>
+// O123sz-NEWPM: Invalidating analysis: InnerAnalysisManagerProxy<llvm::FunctionAnalysisManager, llvm::Module>
 // O123sz-NEWPM: Running pass: ModuleToFunctionPassAdaptor<llvm::PromotePass>
-// O123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::AnalysisManager<llvm::Function>, llvm::Module>
+// O123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::FunctionAnalysisManager, llvm::Module>
 // O123sz-NEWPM: Running analysis: DominatorTreeAnalysis on foo
 // O123sz-NEWPM: Running analysis: PassInstrumentationAnalysis on foo
 // O123sz-NEWPM: Running analysis: AssumptionAnalysis on foo
@@ -57,20 +57,20 @@
 // O123sz-NEWPM: Running analysis: BasicAA on foo
 // O123sz-NEWPM: Running analysis: ScopedNoAliasAA on foo
 // O123sz-NEWPM: Running analysis: TypeBasedAA on foo
-// O123sz-NEWPM: Running analysis: OuterAnalysisManagerProxy<llvm::AnalysisManager<llvm::Module>, llvm::Function> on foo
+// O123sz-NEWPM: Running analysis: OuterAnalysisManagerProxy<llvm::ModuleAnalysisManager, llvm::Function> on foo
 // O123sz-NEWPM: Running pass: SimplifyCFGPass on foo
 // O123sz-NEWPM: Running analysis: TargetIRAnalysis on foo
 // O123sz-NEWPM: Finished llvm::Function pass manager run.
-// O123sz-NEWPM: Running pass: RequireAnalysisPass<llvm::GlobalsAA, llvm::Module>
+// O123sz-NEWPM: Running pass: RequireAnalysisPass<llvm::GlobalsAA, llvm::Module, llvm::AnalysisManager<llvm::Module>>
 // O123sz-NEWPM: Running analysis: GlobalsAA
 // O123sz-NEWPM: Running analysis: CallGraphAnalysis
-// O123sz-NEWPM: Running pass: RequireAnalysisPass<llvm::ProfileSummaryAnalysis, llvm::Module>
-// O123sz-NEWPM: Running pass: ModuleToPostOrderCGSCCPassAdaptor<llvm::DevirtSCCRepeatedPass<llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&> > >
-// O123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::Module>
+// O123sz-NEWPM: Running pass: RequireAnalysisPass<llvm::ProfileSummaryAnalysis, llvm::Module, llvm::AnalysisManager<llvm::Module>>
+// O123sz-NEWPM: Running pass: ModuleToPostOrderCGSCCPassAdaptor<llvm::DevirtSCCRepeatedPass<llvm::PassManager<LazyCallGraph::SCC, llvm::CGSCCAnalysisManager, llvm::LazyCallGraph &, llvm::CGSCCUpdateResult &> > >
+// O123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::CGSCCAnalysisManager, llvm::Module>
 // O123sz-NEWPM: Running analysis: LazyCallGraphAnalysis
 // O123sz-NEWPM: Running analysis: FunctionAnalysisManagerCGSCCProxy on (foo)
 // O123sz-NEWPM: Running analysis: PassInstrumentationAnalysis on (foo)
-// O123sz-NEWPM: Running analysis: OuterAnalysisManagerProxy<llvm::AnalysisManager<llvm::Module>, llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&> on (foo)
+// O123sz-NEWPM: Running analysis: OuterAnalysisManagerProxy<llvm::ModuleAnalysisManager, LazyCallGraph::SCC, llvm::LazyCallGraph &>
 // O123sz-NEWPM: Starting CGSCC pass manager run.
 // O123sz-NEWPM: Running pass: InlinerPass on (foo)
 // O123sz-NEWPM: Running pass: PostOrderFunctionAttrsPass on (foo)
@@ -91,8 +91,8 @@
 // O23sz-NEWPM: Running pass: TailCallElimPass on foo
 // O123sz-NEWPM: Running pass: SimplifyCFGPass on foo
 // O123sz-NEWPM: Running pass: ReassociatePass on foo
-// O123sz-NEWPM: Running pass: RequireAnalysisPass<llvm::OptimizationRemarkEmitterAnalysis, llvm::Function> on foo
-// O123sz-NEWPM: Running pass: FunctionToLoopPassAdaptor<llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&> > on foo
+// O123sz-NEWPM: Running pass: RequireAnalysisPass<llvm::OptimizationRemarkEmitterAnalysis, llvm::Function, llvm::AnalysisManager<llvm::Function>>
+// O123sz-NEWPM: Running pass: FunctionToLoopPassAdaptor<llvm::PassManager<llvm::Loop, llvm::LoopAnalysisManager, llvm::LoopStandardAnalysisResults &, llvm::LPMUpdater &> >
 // O123sz-NEWPM: Starting llvm::Function pass manager run.
 // O123sz-NEWPM: Running pass: LoopSimplifyPass on foo
 // O123sz-NEWPM: Running analysis: LoopAnalysis on foo
@@ -100,7 +100,7 @@
 // O123sz-NEWPM: Finished llvm::Function pass manager run.
 // O123sz-NEWPM: Running pass: SimplifyCFGPass on foo
 // O123sz-NEWPM: Running pass: InstCombinePass on foo
-// O123sz-NEWPM: Running pass: FunctionToLoopPassAdaptor<llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&> > on foo
+// O123sz-NEWPM: Running pass: FunctionToLoopPassAdaptor<llvm::PassManager<llvm::Loop, llvm::LoopAnalysisManager, llvm::LoopStandardAnalysisResults &, llvm::LPMUpdater &> >
 // O123sz-NEWPM: Starting llvm::Function pass manager run.
 // O123sz-NEWPM: Running pass: LoopSimplifyPass on foo
 // O123sz-NEWPM: Running pass: LCSSAPass on foo
@@ -137,7 +137,7 @@
 // O123sz-NEWPM: Running pass: GlobalDCEPass
 // O123sz-NEWPM: Running pass: EliminateAvailableExternallyPass
 // O123sz-NEWPM: Running pass: ReversePostOrderFunctionAttrsPass
-// O123sz-NEWPM: Running pass: RequireAnalysisPass<llvm::GlobalsAA, llvm::Module>
+// O123sz-NEWPM: Running pass: RequireAnalysisPass<llvm::GlobalsAA, llvm::Module, llvm::AnalysisManager<llvm::Module>>
 // O123sz-NEWPM: Running pass: ModuleToFunctionPassAdaptor<llvm::PassManager<llvm::Function> >
 // O123sz-NEWPM: Starting llvm::Function pass manager run.
 // O123sz-NEWPM: Running pass: Float2IntPass on foo
@@ -149,7 +149,7 @@
 // O123sz-NEWPM: Finished llvm::Function pass manager run.
 // O123sz-NEWPM: Running pass: LoopDistributePass on foo
 // O123sz-NEWPM: Running analysis: ScalarEvolutionAnalysis on foo
-// O123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::Function> on foo
+// O123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::LoopAnalysisManager, llvm::Function>
 // O123sz-NEWPM: Running pass: LoopVectorizePass on foo
 // O123sz-NEWPM: Running analysis: BlockFrequencyAnalysis on foo
 // O123sz-NEWPM: Running analysis: BranchProbabilityAnalysis on foo
@@ -160,7 +160,7 @@
 // O123sz-NEWPM: Running pass: LoopUnrollPass on foo
 // O123sz-NEWPM: Running pass: WarnMissedTransformationsPass on foo
 // O123sz-NEWPM: Running pass: InstCombinePass on foo
-// O123sz-NEWPM: Running pass: RequireAnalysisPass<llvm::OptimizationRemarkEmitterAnalysis, llvm::Function> on foo
+// O123sz-NEWPM: Running pass: RequireAnalysisPass<llvm::OptimizationRemarkEmitterAnalysis, llvm::Function, llvm::AnalysisManager<llvm::Function>> on foo
 // O123sz-NEWPM: Running pass: FunctionToLoopPassAdaptor<llvm::LICMPass> on foo
 // O123sz-NEWPM: Starting llvm::Function pass manager run.
 // O123sz-NEWPM: Running pass: LoopSimplifyPass on foo

EDIT: Had to make more changes than I thought. Above passes the test.

ychen added a comment.Jan 14 2020, 2:30 PM

Unit tests: fail. 61858 tests passed, 1 failed and 781 were skipped.

failed: Clang.CodeGen/thinlto-debug-pm.c

I think that failure can be fixed with something like this:

diff --git a/clang/test/CodeGen/thinlto-debug-pm.c b/clang/test/CodeGen/thinlto-debug-pm.c
 index 5f449d493af..9d6d69afd13 100644
 --- a/clang/test/CodeGen/thinlto-debug-pm.c
 +++ b/clang/test/CodeGen/thinlto-debug-pm.c
 @@ -13,17 +13,17 @@
  // O0123sz-NEWPM: Running analysis: PassInstrumentationAnalysis
  // O0123sz-NEWPM: Starting llvm::Module pass manager run.
  // O0123sz-NEWPM: Running pass: WholeProgramDevirtPass
 -// O0123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::AnalysisManager<llvm::Function>, llvm::Module>
 +// O0123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::FunctionAnalysisManager, llvm::Module>
  // O0123sz-NEWPM: Running pass: LowerTypeTestsPass
  // O0123sz-NEWPM: Invalidating all non-preserved analyses for:
 -// O0123sz-NEWPM: Invalidating analysis: InnerAnalysisManagerProxy<llvm::AnalysisManager<llvm::Function>, llvm::Module>
 +// O0123sz-NEWPM: Invalidating analysis: InnerAnalysisManagerProxy<llvm::FunctionAnalysisManager, llvm::Module>
  // O123sz-NEWPM: Running pass: ForceFunctionAttrsPass
  // O123sz-NEWPM: Running pass: PassManager<llvm::Module>
  // O123sz-NEWPM: Starting llvm::Module pass manager run.
  // O123sz-NEWPM: Running pass: PGOIndirectCallPromotion
  // O123sz-NEWPM: Running analysis: ProfileSummaryAnalysis
  // O123sz-NEWPM: Running pass: InferFunctionAttrsPass
 -// O123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::AnalysisManager<llvm::Function>, llvm::Module>
 +// O123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::FunctionAnalysisManager, llvm::Module>
  // O123sz-NEWPM: Running pass: ModuleToFunctionPassAdaptor<llvm::PassManager<llvm::Function> >
  // O123sz-NEWPM: Running analysis: PassInstrumentationAnalysis on foo
  // O123sz-NEWPM: Starting llvm::Function pass manager run.
 @@ -41,9 +41,9 @@
  // O123sz-NEWPM: Running pass: CalledValuePropagationPass
  // O123sz-NEWPM: Running pass: GlobalOptPass
  // O123sz-NEWPM: Invalidating all non-preserved analyses for:
 -// O123sz-NEWPM: Invalidating analysis: InnerAnalysisManagerProxy<llvm::AnalysisManager<llvm::Function>, llvm::Module>
 +// O123sz-NEWPM: Invalidating analysis: InnerAnalysisManagerProxy<llvm::FunctionAnalysisManager, llvm::Module>
  // O123sz-NEWPM: Running pass: ModuleToFunctionPassAdaptor<llvm::PromotePass>
 -// O123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::AnalysisManager<llvm::Function>, llvm::Module>
 +// O123sz-NEWPM: Running analysis: InnerAnalysisManagerProxy<llvm::FunctionAnalysisManager, llvm::Module>
  // O123sz-NEWPM: Running analysis: DominatorTreeAnalysis on foo
  // O123sz-NEWPM: Running analysis: PassInstrumentationAnalysis on foo
  // O123sz-NEWPM: Running analysis: AssumptionAnalysis on foo
 @@ -57,7 +57,7 @@
  // O123sz-NEWPM: Running analysis: BasicAA on foo
  // O123sz-NEWPM: Running analysis: ScopedNoAliasAA on foo
  // O123sz-NEWPM: Running analysis: TypeBasedAA on foo
 -// O123sz-NEWPM: Running analysis: OuterAnalysisManagerProxy<llvm::AnalysisManager<llvm::Module>, llvm::Function> on foo
 +// O123sz-NEWPM: Running analysis: OuterAnalysisManagerProxy<llvm::ModuleAnalysisManager, llvm::Function> on foo
  // O123sz-NEWPM: Running pass: SimplifyCFGPass on foo
  // O123sz-NEWPM: Running analysis: TargetIRAnalysis on foo
  // O123sz-NEWPM: Finished llvm::Function pass manager run.
 @@ -70,7 +70,7 @@
  // O123sz-NEWPM: Running analysis: LazyCallGraphAnalysis
  // O123sz-NEWPM: Running analysis: FunctionAnalysisManagerCGSCCProxy on (foo)
  // O123sz-NEWPM: Running analysis: PassInstrumentationAnalysis on (foo)
 -// O123sz-NEWPM: Running analysis: OuterAnalysisManagerProxy<llvm::AnalysisManager<llvm::Module>, llvm::LazyCallGraph::SCC, llvm::LazyCallG>
 +// O123sz-NEWPM: Running analysis: OuterAnalysisManagerProxy<llvm::ModuleAnalysisManager, llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&> o>
  // O123sz-NEWPM: Starting CGSCC pass manager run.
  // O123sz-NEWPM: Running pass: InlinerPass on (foo)
  // O123sz-NEWPM: Running pass: PostOrderFunctionAttrsPass on (foo)

Thank you. It turns out that GCC&Clang disagree on __PRETTY_FUNCTION__ for type alias (using). will fix those.

ychen updated this revision to Diff 238142.Jan 14 2020, 4:50 PM
ychen edited the summary of this revision. (Show Details)
  • fix test when clang is the host compiler

Unit tests: pass. 61859 tests passed, 0 failed and 781 were skipped.

clang-tidy: unknown.

clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml