This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Simplify more cases of logical ops of masked icmps.
AbandonedPublic

Authored by shawnl on Apr 11 2019, 2:59 PM.

Details

Summary

Example:

(A & 14) != 0 and (A & 1) != 0 => ((cttz (A ^ 8)) - 1) > 3

Diff Detail

Event Timeline

shawnl created this revision.Apr 11 2019, 2:59 PM
shawnl updated this revision to Diff 194773.Apr 11 2019, 3:03 PM

increase context (-U9999)

Herald added a project: Restricted Project. · View Herald TranscriptApr 11 2019, 3:03 PM
shawnl retitled this revision from Simplify more cases of logical ops of masked icmps. to InstCombine: Simplify more cases of logical ops of masked icmps..Apr 11 2019, 3:05 PM
lebedev.ri retitled this revision from InstCombine: Simplify more cases of logical ops of masked icmps. to [InstCombine] Simplify more cases of logical ops of masked icmps..Apr 11 2019, 3:10 PM
lebedev.ri added reviewers: spatel, lebedev.ri.
shawnl planned changes to this revision.Apr 11 2019, 3:18 PM

Fix test case.

shawnl updated this revision to Diff 194777.Apr 11 2019, 3:48 PM

Fix patch after initial test case did not actually exercise code.

lebedev.ri requested changes to this revision.Apr 11 2019, 4:03 PM

As discussed in IRC, this needs a bit of work (tests are miscompiled)

This revision now requires changes to proceed.Apr 11 2019, 4:03 PM
shawnl updated this revision to Diff 194794.Apr 11 2019, 5:43 PM
shawnl edited the summary of this revision. (Show Details)

Note to self: If you get the logic reversed in the example, you will get it reversed in the code.

Remove dead code.

shawnl edited the summary of this revision. (Show Details)Apr 11 2019, 5:46 PM
shawnl planned changes to this revision.Apr 11 2019, 6:54 PM
nikic added a subscriber: nikic.Apr 12 2019, 4:45 AM

Could you please upload the diff with more context? This is done by passing -U99999 to git diff or whichever command you're using.

shawnl updated this revision to Diff 194908.Apr 12 2019, 9:45 AM
shawnl retitled this revision from [InstCombine] Simplify more cases of logical ops of masked icmps. to [InstCombine] Add DCE to VisitAnd.
shawnl edited the summary of this revision. (Show Details)

There is a bunch of work to be done here, but here is a patch to get started

shawnl updated this revision to Diff 194909.Apr 12 2019, 9:49 AM

fix bug and additional test

nikic added inline comments.Apr 12 2019, 9:53 AM
test/Transforms/InstCombine/and-or-icmps.ll
263 ↗(On Diff #194909)

This transform already happens prior to your changes (-instsimplify is sufficient).

277 ↗(On Diff #194909)

This transform already happens prior to your changes (-instcombine).

shawnl planned changes to this revision.Apr 12 2019, 10:25 AM
shawnl updated this revision to Diff 194986.Apr 12 2019, 4:59 PM

[InstCombine] Simplify more cases of logical ops of masked icmps.

Generalizing the work by Hiroshi Yamauchi in
b80dd9b569808cd1d4e672fde77500890edfe446
https://reviews.llvm.org/D43835

Example:

(A & 3) == 3 and (A & 4) == 0 => (A & 7) == 3

shawnl retitled this revision from [InstCombine] Add DCE to VisitAnd to [InstCombine] Simplify more cases of logical ops of masked icmps..Apr 12 2019, 5:00 PM
shawnl edited the summary of this revision. (Show Details)
shawnl planned changes to this revision.Apr 12 2019, 5:26 PM
shawnl marked 2 inline comments as done.

handle or properly

shawnl updated this revision to Diff 195027.Apr 13 2019, 11:41 AM
shawnl edited the summary of this revision. (Show Details)

fshl/fshr and cttz/ctlz need alot of work

nikic added inline comments.Apr 13 2019, 11:54 AM
lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
768

This transform doesn't make any sense to me. (icmp eq (A & 3), 0) && (icmp ne (A & 4), 0) is the same as (icmp eq (A & 7) == 4). Which is exactly the expansion we produce for a cttz equality check in https://github.com/llvm-mirror/llvm/blob/3f5d54bc7b3a850a2df14a6f7b7d8661423d824f/lib/Transforms/InstCombine/InstCombineCompares.cpp#L2851-L2866. Using a mask is more efficient and analyzable than using cttz.

shawnl abandoned this revision.Apr 13 2019, 12:17 PM
shawnl marked an inline comment as done.
shawnl added inline comments.
lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
768

Yes, it only makes sense when the range being matched is !=, or the condition is an or.