diff options
author | Amir Ayupov <aaupov@fb.com> | 2022-02-07 20:16:13 -0800 |
---|---|---|
committer | Amir Ayupov <aaupov@fb.com> | 2022-03-08 10:44:31 -0800 |
commit | 687e4af1c05ae36af88900d41150e260d8f273c0 (patch) | |
tree | 3e742ec4ac36a1daf0dfe7d19f43b2391331052d /bolt/lib/Rewrite/BinaryPassManager.cpp | |
parent | 151f809c558d3d7e67e4d4b7efe84218c3b8cfa7 (diff) | |
download | llvm-687e4af1c05ae36af88900d41150e260d8f273c0.zip llvm-687e4af1c05ae36af88900d41150e260d8f273c0.tar.gz llvm-687e4af1c05ae36af88900d41150e260d8f273c0.tar.bz2 |
[BOLT] CMOVConversion pass
Convert simple hammocks into cmov based on misprediction rate.
Test Plan:
- Assembly test: `cmov-conversion.s`
- Testing on a binary:
# Bootstrap clang with `-x86-cmov-converter-force-all` and `-Wl,--emit-relocs`
(Release build)
# Collect perf.data:
- `clang++ <opts> bolt/lib/Core/BinaryFunction.cpp -E > bf.cpp`
- `perf record -e cycles:u -j any,u -- clang-15 bf.cpp -O2 -std=c++14 -c -o bf.o`
# Optimize clang-15 with and w/o -cmov-conversion:
- `llvm-bolt clang-15 -p perf.data -o clang-15.bolt`
- `llvm-bolt clang-15 -p perf.data -cmov-conversion -o clang-15.bolt.cmovconv`
# Run perf experiment:
- test: `clang-15.bolt.cmovconv`,
- control: `clang-15.bolt`,
- workload (clang options): `bf.cpp -O2 -std=c++14 -c -o bf.o`
Results:
```
task-clock [delta: -360.21 ± 356.75, delta(%): -1.7760 ± 1.7589, p-value: 0.047951, balance: -6]
instructions [delta: 44061118 ± 13246382, delta(%): 0.0690 ± 0.0207, p-value: 0.000001, balance: 50]
icache-misses [delta: -5534468 ± 2779620, delta(%): -0.4331 ± 0.2175, p-value: 0.028014, balance: -28]
branch-misses [delta: -1624270 ± 1113244, delta(%): -0.3456 ± 0.2368, p-value: 0.030300, balance: -22]
```
Reviewed By: rafauler
Differential Revision: https://reviews.llvm.org/D120177
Diffstat (limited to 'bolt/lib/Rewrite/BinaryPassManager.cpp')
-rw-r--r-- | bolt/lib/Rewrite/BinaryPassManager.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/bolt/lib/Rewrite/BinaryPassManager.cpp b/bolt/lib/Rewrite/BinaryPassManager.cpp index 199ed5f..929b734 100644 --- a/bolt/lib/Rewrite/BinaryPassManager.cpp +++ b/bolt/lib/Rewrite/BinaryPassManager.cpp @@ -11,6 +11,7 @@ #include "bolt/Passes/Aligner.h" #include "bolt/Passes/AllocCombiner.h" #include "bolt/Passes/AsmDump.h" +#include "bolt/Passes/CMOVConversion.h" #include "bolt/Passes/FrameOptimizer.h" #include "bolt/Passes/IdenticalCodeFolding.h" #include "bolt/Passes/IndirectCallPromotion.h" @@ -247,6 +248,11 @@ ThreeWayBranchFlag("three-way-branch", cl::desc("reorder three way branches"), cl::ZeroOrMore, cl::ReallyHidden, cl::cat(BoltOptCategory)); +static cl::opt<bool> CMOVConversionFlag("cmov-conversion", + cl::desc("fold jcc+mov into cmov"), + cl::ZeroOrMore, cl::ReallyHidden, + cl::cat(BoltOptCategory)); + } // namespace opts namespace llvm { @@ -393,6 +399,9 @@ void BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) { Manager.registerPass(std::make_unique<TailDuplication>(), opts::TailDuplicationFlag); + Manager.registerPass(std::make_unique<CMOVConversion>(), + opts::CMOVConversionFlag); + // This pass syncs local branches with CFG. If any of the following // passes breaks the sync - they either need to re-run the pass or // fix branches consistency internally. |