diff options
author | Hiroshi Yamauchi <yamauchi@google.com> | 2018-09-04 17:19:13 +0000 |
---|---|---|
committer | Hiroshi Yamauchi <yamauchi@google.com> | 2018-09-04 17:19:13 +0000 |
commit | 9775a620b0f6f5d3379eead8fdcfa3465782caf5 (patch) | |
tree | 1e7707069bcc7751811291f5c3448c90d15e8ed5 /llvm/lib/Passes/PassBuilder.cpp | |
parent | 24568789c4160182c44fa382138a19943f244083 (diff) | |
download | bcm5719-llvm-9775a620b0f6f5d3379eead8fdcfa3465782caf5.tar.gz bcm5719-llvm-9775a620b0f6f5d3379eead8fdcfa3465782caf5.zip |
[PGO] Control Height Reduction
Summary:
Control height reduction merges conditional blocks of code and reduces the
number of conditional branches in the hot path based on profiles.
if (hot_cond1) { // Likely true.
do_stg_hot1();
}
if (hot_cond2) { // Likely true.
do_stg_hot2();
}
->
if (hot_cond1 && hot_cond2) { // Hot path.
do_stg_hot1();
do_stg_hot2();
} else { // Cold path.
if (hot_cond1) {
do_stg_hot1();
}
if (hot_cond2) {
do_stg_hot2();
}
}
This speeds up some internal benchmarks up to ~30%.
Reviewers: davidxl
Reviewed By: davidxl
Subscribers: xbolva00, dmgreen, mehdi_amini, llvm-commits, mgorny
Differential Revision: https://reviews.llvm.org/D50591
llvm-svn: 341386
Diffstat (limited to 'llvm/lib/Passes/PassBuilder.cpp')
-rw-r--r-- | llvm/lib/Passes/PassBuilder.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index eb04dcc8b6e..d7b9dfca34a 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -87,6 +87,7 @@ #include "llvm/Transforms/IPO/WholeProgramDevirt.h" #include "llvm/Transforms/InstCombine/InstCombine.h" #include "llvm/Transforms/Instrumentation/BoundsChecking.h" +#include "llvm/Transforms/Instrumentation/ControlHeightReduction.h" #include "llvm/Transforms/Instrumentation/GCOVProfiler.h" #include "llvm/Transforms/Instrumentation/InstrProfiling.h" #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h" @@ -193,6 +194,10 @@ static cl::opt<bool> EnableSyntheticCounts( static Regex DefaultAliasRegex( "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$"); +static cl::opt<bool> + EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden, + cl::desc("Enable control height reduction optimization (CHR)")); + static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) { switch (Level) { case PassBuilder::O0: @@ -486,6 +491,10 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level, FPM.addPass(InstCombinePass()); invokePeepholeEPCallbacks(FPM, Level); + if (EnableCHR && Level == O3 && PGOOpt && + (!PGOOpt->ProfileUseFile.empty() || !PGOOpt->SampleProfileFile.empty())) + FPM.addPass(ControlHeightReductionPass()); + return FPM; } |