InstCombine: Simplify (A ^ B) or/and (A ^ B ^ C)
authorDavid Majnemer <david.majnemer@gmail.com>
Wed, 30 Jul 2014 21:26:37 +0000 (21:26 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Wed, 30 Jul 2014 21:26:37 +0000 (21:26 +0000)
commit42af3601c29a521cec564c2c55e43f9751494b8e
treefeffa04ccfa985f458c4cd71aff9389119c8efcb
parent2aa09d4319ff20528806bbb85844559b22347294
InstCombine: Simplify (A ^ B) or/and (A ^ B ^ C)

While we can already transform A | (A ^ B) into A | B, things get bad
once we have (A ^ B) | (A ^ B ^ Cst) because reassociation will morph
this into (A ^ B) | ((A ^ Cst) ^ B).  Our existing patterns fail once
this happens.

To fix this, we add a new pattern which looks through the tree of xor
binary operators to see that, in fact, there exists a redundant xor
operation.

What follows bellow is a correctness proof of the transform using CVC3.

$ cat t.cvc
A, B, C : BITVECTOR(64);

QUERY BVXOR(A, B) | BVXOR(BVXOR(B, C), A) = BVXOR(A, B) | C;
QUERY BVXOR(BVXOR(A, C), B) | BVXOR(A, B) = BVXOR(A, B) | C;

QUERY BVXOR(A, B) & BVXOR(BVXOR(B, C), A) = BVXOR(A, B) & ~C;
QUERY BVXOR(BVXOR(A, C), B) & BVXOR(A, B) = BVXOR(A, B) & ~C;

$ cvc3 < t.cvc
Valid.
Valid.
Valid.
Valid.

llvm-svn: 214342
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/or-xor.ll
llvm/test/Transforms/InstCombine/xor2.ll