This is an archive of the discontinued LLVM Phabricator instance.

[X86] Introduce x86-cmov-converter-force-all
ClosedPublic

Authored by Amir on Feb 14 2022, 1:52 PM.

Details

Summary

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).

Diff Detail

Event Timeline

Amir created this revision.Feb 14 2022, 1:52 PM
Amir requested review of this revision.Feb 14 2022, 1:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 14 2022, 1:52 PM
skan added a comment.Feb 15 2022, 12:51 AM

Could you point out the document for -fno-if-conversion2?

Could you point out the document for -fno-if-conversion2?

It guess it's in https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

Amir added a comment.Feb 15 2022, 1:10 PM

Could you point out the document for -fno-if-conversion2?

It guess it's in https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

Yes, it's there, as -fif-conversion2

Could you point out the document for -fno-if-conversion2?

It guess it's in https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

Yes, it's there, as -fif-conversion2

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?

Amir added a comment.Feb 15 2022, 4:02 PM

Could you point out the document for -fno-if-conversion2?

It guess it's in https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

Yes, it's there, as -fif-conversion2

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:

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.

skan added inline comments.Feb 15 2022, 7:41 PM
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.

skan added a comment.Feb 15 2022, 7:41 PM

Please add at least one test file.

Amir added inline comments.Feb 15 2022, 11:19 PM
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.

skan added inline comments.Feb 15 2022, 11:33 PM
llvm/lib/Target/X86/X86CmovConversion.cpp
186–195

The code after line 203 should not be executed when ForceAll is enabled, right?

Amir updated this revision to Diff 409366.Feb 16 2022, 12:37 PM

Addressing feedback, added tests

Amir marked 2 inline comments as done.Feb 16 2022, 12:39 PM
Amir added inline comments.
llvm/lib/Target/X86/X86CmovConversion.cpp
186–195

Right, I see what you mean. Fixed in the updated rev.

Amir marked an inline comment as done.Feb 16 2022, 12:39 PM
skan added inline comments.Feb 16 2022, 6:55 PM
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.

Amir added a comment.Feb 17 2022, 10:33 AM

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!

skan accepted this revision.Feb 23 2022, 4:33 PM
This revision is now accepted and ready to land.Feb 23 2022, 4:33 PM
MaskRay accepted this revision.Feb 23 2022, 5:40 PM
This revision was landed with ongoing or failed builds.Feb 24 2022, 10:47 AM
This revision was automatically updated to reflect the committed changes.