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).
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
The description for -fif-conversion2 reads as if it is enabling an optimization pass and that -fno-if-conversion2 just doesn't run that optimization pass. It doesn't read like -fno-if-conversion2 would expand cmovs. Is my understanding correct?
Yes, it's correct. My understanding is that GCC handles cmov's the opposite way compared to LLVM:
- GCC's IR has if-then-else constructs and cmov's are inserted by if-conversion pass (https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/ifcvt.cc;hb=3d8d8e34f796fefda53be9a6cec7c6c950856a14#l5782).
- In LLVM, select is lowered into cmov which is expanded into if-then-else by X86CmovConversion pass.
The two approaches are not equivalent, but to keep cmov opportunities until after the compiler, one would need -fno-if-conversion2 in GCC and -x86-cmov-converter-force-all in LLVM.
llvm/lib/Target/X86/X86CmovConversion.cpp | ||
---|---|---|
186–195 | We should at least have a quick return for ForceAll here b/c there is no more CMOV. |
llvm/lib/Target/X86/X86CmovConversion.cpp | ||
---|---|---|
186–195 | What do you mean by "there's no more CMOV"? ForceAll would have to similarly collect all blocks, then collectCmovCandidates and iterate over AllCmovGroups. I don't see an early return option. |
llvm/lib/Target/X86/X86CmovConversion.cpp | ||
---|---|---|
186–195 | The code after line 203 should not be executed when ForceAll is enabled, right? |
llvm/lib/Target/X86/X86CmovConversion.cpp | ||
---|---|---|
186–195 | Right, I see what you mean. Fixed in the updated rev. |
llvm/lib/Target/X86/X86CmovConversion.cpp | ||
---|---|---|
101–104 | LGTM in general. Please reformat this. |
Note Amir that the plan as outlined and discussed in the RFC that @MaskRay linked is to enable a new target-agnostic and profile-guided pass for cmov/branch decision-making and disable this profile-agnostic and x86-specific pass when profile information are available. Initially, the new pass will only be enabled for instr-FDO. But the next step is to enable it for Sample-FDO and as discussed with @modimo, this will take advantage of LBR data for computing misprediction rates. For the time being I am fine with enabling this option here but be aware that this x86 pass might be disabled in the near future.
Hi Sotiris,
Sounds good to me. The option added here is for experimentation ATM. Hoping to see the new pass with LBR data available soon!
LGTM in general. Please reformat this.