This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] fold more icmp + select patterns by distributive laws
ClosedPublic

Authored by bcl5980 on Dec 3 2022, 1:49 AM.

Details

Summary

follow up D139076, add icmp with not only eq/ne, but also gt/lt/ge/le.

Diff Detail

Event Timeline

bcl5980 created this revision.Dec 3 2022, 1:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 3 2022, 1:49 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
bcl5980 requested review of this revision.Dec 3 2022, 1:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 3 2022, 1:49 AM

I will pre-commit baseline tests after review.

bcl5980 updated this revision to Diff 479901.Dec 4 2022, 12:41 AM

update tests and fix two bugs.

spatel added a comment.Dec 5 2022, 7:13 AM

It would be easier to review if you pre-commit the tests. You can add ; negative test comments in this patch to make it clear when a test is not intended to change.
Why are there changes in test files that do contain the patterns that are matched in this patch?

llvm/test/Transforms/InstCombine/select-cmp.ll
298

This is not correct.

spatel added a comment.Dec 5 2022, 7:15 AM

Also, maybe we should handle all matching predicates without trying to swap as a first step. Then, add swap logic to deal with patterns that have swapped predicates in a follow-up patch. That way, we can be sure there are no bugs.

bcl5980 added inline comments.Dec 5 2022, 7:55 AM
llvm/test/Transforms/InstCombine/select-cmp.ll
298

Ah, Thanks for finding the case.

298

Can I ask you how could you find that? Local alive2?

spatel added inline comments.Dec 5 2022, 8:10 AM
llvm/test/Transforms/InstCombine/select-cmp.ll
298

I just noticed that the predicate changed, but the common operand position did not.
I did paste it into Alive2 after that to make sure I saw it correctly. :)

bcl5980 updated this revision to Diff 480116.Dec 5 2022, 8:19 AM

fix bug for the case with the same predicate but not eq/ne

bcl5980 added inline comments.Dec 5 2022, 8:20 AM
llvm/test/Transforms/InstCombine/select-cmp.ll
298

Should be correct now. Sorry for the wrong code.

bcl5980 updated this revision to Diff 480479.Dec 6 2022, 7:07 AM

rebase code

spatel added inline comments.Dec 6 2022, 7:47 AM
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
340

This deserves a code comment to explain the logic. Something like:

// If we are allowing commute or swap of operands, then
// allow a cross-operand match. In that case, MatchIsOpZero
// means that TI's operand 0 (FI's operand 1) is the common op.
bcl5980 updated this revision to Diff 480724.Dec 6 2022, 6:04 PM

address comments.

spatel accepted this revision.Dec 7 2022, 6:21 AM

LGTM

This revision is now accepted and ready to land.Dec 7 2022, 6:21 AM
This revision was landed with ongoing or failed builds.Dec 7 2022, 7:56 AM
This revision was automatically updated to reflect the committed changes.