This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Transform `(icmp ult/uge (and X, Y), X)` -> `(icmp ne/eq (and X, Y), X)`
ClosedPublic

Authored by goldstein.w.n on Mar 6 2023, 2:16 PM.

Diff Detail

Event Timeline

goldstein.w.n created this revision.Mar 6 2023, 2:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 6 2023, 2:16 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
goldstein.w.n requested review of this revision.Mar 6 2023, 2:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 6 2023, 2:16 PM
nikic accepted this revision.May 28 2023, 3:40 AM

LGTM

This revision is now accepted and ready to land.May 28 2023, 3:40 AM
nikic added inline comments.Aug 12 2023, 1:05 PM
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
4449

For symmetry with the or fold, I think we want X & Y == Y to X | ~Y == -1 for freely invertible Y (https://alive2.llvm.org/ce/z/wt3Cg6).

nikic added inline comments.Aug 27 2023, 11:38 AM
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
4449

And X & Y == Y to ~X & Y == 0 as well, based on what the final version of D144610 implemented.

IIRC one of those folds also got implemented for constants previously, so we can drop that then.

goldstein.w.n edited the summary of this revision. (Show Details)Aug 27 2023, 3:24 PM
goldstein.w.n edited the summary of this revision. (Show Details)Aug 27 2023, 3:36 PM
goldstein.w.n marked an inline comment as done.
goldstein.w.n edited the summary of this revision. (Show Details)

Rebase

goldstein.w.n added inline comments.Aug 28 2023, 9:37 PM
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
4449

Done, although (as you can see from the stack) that actually had fairly large implications for: foldICmpWithLowBitMaskedVal so added patches for that as well.

But the logic is there in: D159059

goldstein.w.n added inline comments.Aug 28 2023, 10:12 PM
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
4449

Also note just about no compile time blowback for any of the changes (was a bit concerned as implemented two recursive functions):
https://llvm-compile-time-tracker.com/compare.php?from=692344d87357ded619d216b265a9375f4326d8fb&to=facaede5ae43806d3123c18823cc173a4b3970ec&stat=instructions%3Au

This revision was landed with ongoing or failed builds.Sep 13 2023, 1:50 PM
This revision was automatically updated to reflect the committed changes.