This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Canonicalize (A & B_Pow2) eq/ne B_Pow2 patterns
ClosedPublic

Authored by goldstein.w.n on Jan 5 2023, 2:25 PM.

Details

Summary
  1. A & B_Pow2 != B_Pow2 -> A & B_Pow2 == 0 https://alive2.llvm.org/ce/z/KVUej4
  1. A & B_Pow2 == B_Pow2 -> A & B_Pow2 != 0 https://alive2.llvm.org/ce/z/PVv9FR

This allows the patterns to more easily be analyzed elsewhere.

Diff Detail

Event Timeline

goldstein.w.n created this revision.Jan 5 2023, 2:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2023, 2:25 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
goldstein.w.n requested review of this revision.Jan 5 2023, 2:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2023, 2:25 PM
nikic accepted this revision.Jan 6 2023, 1:08 AM

LGTM

Simpler proof: https://alive2.llvm.org/ce/z/JQMH7m Canonical pattern for pow2 check is ctpop==1.

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
4791
This revision is now accepted and ready to land.Jan 6 2023, 1:08 AM
spatel accepted this revision.Jan 6 2023, 6:02 AM
spatel added inline comments.
llvm/test/Transforms/InstCombine/icmp-and-shift.ll
511

I like to have "negative test" comments on examples like these, so it's clear that if they somehow do change in the future, that wasn't supposed to happen.

The transform could be extended to at least some non-equality predicates in a follow-up patch:
https://alive2.llvm.org/ce/z/eig49D

goldstein.w.n marked an inline comment as done.

Make non-zero more clean

llvm/test/Transforms/InstCombine/icmp-and-shift.ll
511

I like to have "negative test" comments on examples like these, so it's clear that if they somehow do change in the future, that wasn't supposed to happen.

The transform could be extended to at least some non-equality predicates in a follow-up patch:
https://alive2.llvm.org/ce/z/eig49D

Agreed, also makes it easier to make future improvements as getting new test deps through is a pain

LGTM

Simpler proof: https://alive2.llvm.org/ce/z/JQMH7m Canonical pattern for pow2 check is ctpop==1.

LGTM

Simpler proof: https://alive2.llvm.org/ce/z/JQMH7m Canonical pattern for pow2 check is ctpop==1.

Do you want me to update the commit message with link to this proof instead?

This revision was automatically updated to reflect the committed changes.