This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] Add fold for `(and/or (icmp ne/eq X,0),(icmp ne/eq X,NegPow2))`
Needs ReviewPublic

Authored by goldstein.w.n on Aug 9 2023, 8:36 PM.

Details

Reviewers
RKSimon
pengfei
Summary

Add new fold for:

`(and/or (icmp ne/eq X,0),(icmp ne/eq X,NegPow2))`
    ->
`(icmp ne/eq (and -X, ~(-NegPow2)), 0)`

This is really an extension of the generic pattern we already support:

`(and/or (icmp ne/eq X,C0),(icmp ne/eq X,C1))`
    -> iff `absdif(C0, C1).ispow2`
`(icmp ne/eq (and (sub X, smin(C0, C1)), ~absdif(C0, C1)), 0)`

But negation can be faster than adding a constant, especially for
vectors where creating a zero constant can be meaningfully faster.

Proof: https://alive2.llvm.org/ce/z/edg2N2

Diff Detail