This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] fold icmp + select pattern by distributive laws
ClosedPublic

Authored by bcl5980 on Nov 30 2022, 10:43 PM.

Details

Summary

C ? (Y != X) : (Z != X) --> (C ? Y : Z) != X
C ? (Y == X) : (Z == X) --> (C ? Y : Z) == X

https://alive2.llvm.org/ce/z/-frXfs

Diff Detail

Event Timeline

bcl5980 created this revision.Nov 30 2022, 10:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 30 2022, 10:43 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
bcl5980 requested review of this revision.Nov 30 2022, 10:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 30 2022, 10:43 PM
bcl5980 updated this revision to Diff 479288.Dec 1 2022, 7:13 AM

rebase code

bcl5980 updated this revision to Diff 479506.Dec 1 2022, 7:14 PM

rebase code

spatel added a comment.Dec 2 2022, 8:23 AM

Nice!

But we can handle any pair of matching predicates (in follow-up patches is fine)? We just need to make sure the common operand is in the right position for non-commutative predicates:
https://alive2.llvm.org/ce/z/xgx4eh

spatel added a comment.Dec 2 2022, 8:28 AM

Please pre-commit baseline tests.

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
387–388

Can shorten this:

if (TPred == FPred && ICmpInst::isEquality(TPred))
bcl5980 updated this revision to Diff 479668.Dec 2 2022, 10:04 AM

rebase code and shorten the condition by comments.

Nice!

But we can handle any pair of matching predicates (in follow-up patches is fine)? We just need to make sure the common operand is in the right position for non-commutative predicates:
https://alive2.llvm.org/ce/z/xgx4eh

Thanks for the suggestion. I can add them in follow-up patches.

spatel accepted this revision.Dec 2 2022, 10:55 AM

LGTM

This revision is now accepted and ready to land.Dec 2 2022, 10:55 AM