[PATCH] D119777: [X86] Introduce x86-cmov-converter-force-all
Amir Ayupov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 14 13:52:26 PST 2022
Amir created this revision.
Herald added subscribers: pengfei, hiraditya.
Amir requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Introduce an option to expand all CMOV groups into hammocks, matching GCC's
`-fno-if-conversion2` flag. The motivation is to leave CMOV conversion
opportunities to a binary optimizer that can make the decision based on branch
misprediction rate (available e.g. in Intel's LBR).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D119777
Files:
llvm/lib/Target/X86/X86CmovConversion.cpp
Index: llvm/lib/Target/X86/X86CmovConversion.cpp
===================================================================
--- llvm/lib/Target/X86/X86CmovConversion.cpp
+++ llvm/lib/Target/X86/X86CmovConversion.cpp
@@ -97,6 +97,11 @@
cl::desc("Convert cmovs to branches whenever they have memory operands."),
cl::init(true), cl::Hidden);
+static cl::opt<bool> ForceAll(
+ "x86-cmov-converter-force-all",
+ cl::desc("Convert all cmovs to branches."),
+ cl::init(false), cl::Hidden);
+
namespace {
/// Converts X86 cmov instructions into branches when profitable.
@@ -174,11 +179,11 @@
TSchedModel.init(&STI);
// Before we handle the more subtle cases of register-register CMOVs inside
- // of potentially hot loops, we want to quickly remove all CMOVs with
- // a memory operand. The CMOV will risk a stall waiting for the load to
- // complete that speculative execution behind a branch is better suited to
- // handle on modern x86 chips.
- if (ForceMemOperand) {
+ // of potentially hot loops, we want to quickly remove all CMOVs (ForceAll) or
+ // the ones with a memory operand (ForceMemOperand option). The latter CMOV
+ // will risk a stall waiting for the load to complete that speculative
+ // execution behind a branch is better suited to handle on modern x86 chips.
+ if (ForceMemOperand || ForceAll) {
CmovGroups AllCmovGroups;
SmallVector<MachineBasicBlock *, 4> Blocks;
for (auto &MBB : MF)
@@ -186,7 +191,8 @@
if (collectCmovCandidates(Blocks, AllCmovGroups, /*IncludeLoads*/ true)) {
for (auto &Group : AllCmovGroups) {
// Skip any group that doesn't do at least one memory operand cmov.
- if (llvm::none_of(Group, [&](MachineInstr *I) { return I->mayLoad(); }))
+ if (ForceMemOperand &&
+ llvm::none_of(Group, [&](MachineInstr *I) { return I->mayLoad(); }))
continue;
// For CMOV groups which we can rewrite and which contain a memory load,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119777.408606.patch
Type: text/x-patch
Size: 1977 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220214/d791e8d0/attachment.bin>
More information about the llvm-commits
mailing list