HomePhabricator

[DAGCombiner][X86][AArch64] Generalize `A-(A&B)`->`A&(~B)` fold (PR44448)

Authored by lebedev.ri on Jan 3 2020, 5:14 AM.

Description

[DAGCombiner][X86][AArch64] Generalize A-(A&B)->A&(~B) fold (PR44448)

The fold 'A - (A & (B - 1))' -> 'A & (0 - B)'
added in 8dab0a4a7d691f2704f1079538e0ef29548db159
is too specific. It should/can just be 'A - (A & B)' -> 'A & (~B)'

Even if we don't manage to fold ~ into B,
we have likely formed ANDN node.
Also, this way there's less similar-but-duplicate folds.

Name: X - (X & Y) -> X & (~Y)
%o = and i32 %X, %Y
%r = sub i32 %X, %o

=>

%n = xor i32 %Y, -1
%r = and i32 %X, %n

https://rise4fun.com/Alive/kOUl

See

https://bugs.llvm.org/show_bug.cgi?id=44448
https://reviews.llvm.org/D71499

Details

Committed
lebedev.riJan 3 2020, 6:55 AM
Parents
rG473deaf34bc9: [NFC][X86][AArch64] Add 'A - (A & B)' pattern tests (PR44448)
Branches
Unknown
Tags
Unknown