This is an archive of the discontinued LLVM Phabricator instance.

[CGP] Sink compare through freeze
Changes PlannedPublic

Authored by dmgreen on Feb 28 2022, 12:47 AM.

Details

Summary

CodeGenPrepare will sink most compares to the block that uses then, as an optimization to keep the compare and the branch/select/etc next to on another. This can be blocked by the presence of freeze, however. Usually freeze(icmp(x, C)) is converted to icmp(freeze(x), C)), allowing the cmp to be sunk. If there are multiple uses of the cmp though, this currently doesn't happen.

This patch relaxes that, as the cmp will already be duplicated to be sunk into a different block, we can more aggressively convert the icmp-freeze to freeze-icmp.

Diff Detail

Event Timeline

dmgreen created this revision.Feb 28 2022, 12:47 AM
dmgreen requested review of this revision.Feb 28 2022, 12:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 28 2022, 12:47 AM
aqjune added inline comments.Mar 1 2022, 12:07 AM
llvm/lib/CodeGen/CodeGenPrepare.cpp
7904

Should we factor out this and multiple condition registers check as a separate function so that the check can be shared with sinkCmpExpression?

7905

typo?

7911

Could you elaborate why this condition is necessary please?

llvm/test/Transforms/CodeGenPrepare/X86/freeze-brcond.ll
55

This extra freeze here should be removed - would a simple constant-ness check using Const0 and Const1 be enough?
A slightly more expensive check would be isGuaranteedNotToBeUndefOrPoison, not sure it is fine for CodeGenPrepare to call it.

Also, could you leave a link to Alive2 in the patch description showing that pushing freeze into icmp ops is safe when there are multiple users?

dmgreen planned changes to this revision.Mar 3 2022, 12:13 AM

Thanks for taking a look. I decided this might be better to sink the freeze more directly in sinkCmpExpression. According to alive that is still valid, even if it duplicates the freeze. I'll update when I have more details.

Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 12:13 AM