This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Canonicalize `(icmp eq/ne (and x, C), x)` -> `(icmp eq/ne (and x, ~C), 0)`
ClosedPublic

Authored by goldstein.w.n on Jun 28 2023, 2:16 PM.

Details

Summary

This increases the likelyhood x is single-use and is typically
easier to analyze.

Proofs: https://alive2.llvm.org/ce/z/8ZpS2W

Diff Detail

Event Timeline

goldstein.w.n created this revision.Jun 28 2023, 2:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2023, 2:16 PM
goldstein.w.n requested review of this revision.Jun 28 2023, 2:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2023, 2:16 PM
nikic accepted this revision.Jun 29 2023, 12:25 AM

LGTM. Note that there is a conjugate or fold (same but with -1 instead of 0) that should be implemented for symmetry as well.

This revision is now accepted and ready to land.Jun 29 2023, 12:25 AM

LGTM. Note that there is a conjugate or fold (same but with -1 instead of 0) that should be implemented for symmetry as well.

Or better yet (icmp eq/ne (or x, C), x) -> (icmp eq/ne (and x, C), C): https://alive2.llvm.org/ce/z/m2R2jo
Then we get to reuse C instead of creating a new constant (and and is typically the easiest to analyze).

Works generically as well (I actually have it implemented in: D144610).
If you think this is enough motivation for D144610 I can rebase the series, otherwise I'll just implement here along side the current and code. LMK.