[PATCH] D157312: [InstCombine] Add transforms for `(or/and (icmp eq/ne X,0),(icmp eq/ne X,Pow2OrZero))`

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 25 13:26:11 PDT 2023


nikic added a comment.

In D157312#4618198 <https://reviews.llvm.org/D157312#4618198>, @goldstein.w.n wrote:

> In D157312#4616620 <https://reviews.llvm.org/D157312#4616620>, @nikic wrote:
>
>> Not sure we should do this transform in IR. The original form seems to be a lot simpler to reason about than the new one -- e.g. if you have that as condition, it's obvious that %x can't be zero (as there's an explicit check for it). Afterwards, that would be fairly hard to determine.
>
> Really? We have a fair amount of logic for `X & Y eq/ne ...` and we do this fold already for constants (and similiar folds for non-constants). 
> Also since its an equivilency and only relies on `Pow2OrZero` being a pow2orzero, theres no information loss.

For constants this is turned into an `X & ~C eq 0` or `X & ~C ne 0` pattern. That //is// well understood due to the obvious KnownBits implications. `X & Y == X` not so much I think.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157312/new/

https://reviews.llvm.org/D157312



More information about the llvm-commits mailing list