This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Optimize (icmp slt (1 << Y), 1) -> (icmp eq Y, BitWidth-1).
ClosedPublic

Authored by craig.topper on Jan 14 2023, 12:47 AM.

Details

Summary

The code tried to do this for (icmp sle (1 << Y), 0), but that is
canonicalized to sgt before we get there.

Simplify the code by removing the unreachable SGE and SLE handling.

Also remove the (1 << Y) >=u 2147483648 and (1 << Y) <u 2147483648
handling since those are canonicalized to (1 << Y) <s 0 and
(1 << Y) >=s 0 before we get there.

Diff Detail

Event Timeline

craig.topper created this revision.Jan 14 2023, 12:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 14 2023, 12:47 AM
craig.topper requested review of this revision.Jan 14 2023, 12:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 14 2023, 12:47 AM

It's good cleanup and seems correct, but it can be generalized even more (could make it another patch if you prefer):
https://alive2.llvm.org/ce/z/3YB2vs

Need more tests like this:
https://alive2.llvm.org/ce/z/hVNnPJ

It's good cleanup and seems correct, but it can be generalized even more (could make it another patch if you prefer):
https://alive2.llvm.org/ce/z/3YB2vs

Need more tests like this:
https://alive2.llvm.org/ce/z/hVNnPJ

I'd prefer to make it another patch. I haven't observed this in the wild. I was looking in the file for something else and just happened to notice the asymmetry. Then I looked at the line coverage report and saw the untested lines.

spatel accepted this revision.Jan 14 2023, 10:36 AM

LGTM - please add a todo comment if you aren’t planning to do the follow up patch immediately.

This revision is now accepted and ready to land.Jan 14 2023, 10:36 AM
This revision was landed with ongoing or failed builds.Jan 14 2023, 11:19 AM
This revision was automatically updated to reflect the committed changes.