[llvm] r215524 - InstCombine: Combine (xor (or %a, %b) (xor %a, %b)) to (add %a, %b)

David Majnemer david.majnemer at gmail.com
Wed Aug 13 16:05:10 PDT 2014


On Tue, Aug 12, 2014 at 10:13 PM, Karthik Bhat <kv.bhat at samsung.com> wrote:

> Author: karthik
> Date: Wed Aug 13 00:13:14 2014
> New Revision: 215524
>
> URL: http://llvm.org/viewvc/llvm-project?rev=215524&view=rev
> Log:
> InstCombine: Combine (xor (or %a, %b) (xor %a, %b)) to (add %a, %b)
>
> Correctness proof of the transform using CVC3-
>
> $ cat t.cvc
> A, B : BITVECTOR(32);
> QUERY BVXOR(A | B, BVXOR(A,B) ) = A & B;
>
> $ cvc3 t.cvc
> Valid.
>
>
> Modified:
>     llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
>     llvm/trunk/test/Transforms/InstCombine/or-xor.ll
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=215524&r1=215523&r2=215524&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
> (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Wed Aug
> 13 00:13:14 2014
> @@ -2508,6 +2508,18 @@ Instruction *InstCombiner::visitXor(Bina
>        if ((A == C && B == D) || (A == D && B == C))
>          return BinaryOperator::CreateXor(A, B);
>      }
> +    // (A ^ B)^(A | B) -> A & B
> +    if (match(Op0I, m_Xor(m_Value(A), m_Value(B))) &&
> +        match(Op1I, m_Or(m_Value(C), m_Value(D)))) {
> +      if ((A == C && B == D) || (A == D && B == C))
> +        return BinaryOperator::CreateAnd(A, B);
> +    }
> +    // (A | B)^(A ^ B) -> A & B
> +    if (match(Op0I, m_Or(m_Value(A), m_Value(B))) &&
> +        match(Op1I, m_Xor(m_Value(C), m_Value(D)))) {
> +      if ((A == C && B == D) || (A == D && B == C))
> +        return BinaryOperator::CreateAnd(A, B);
> +    }
>      // (A & B) ^ (A ^ B) -> (A | B)
>      if (match(Op0I, m_And(m_Value(A), m_Value(B))) &&
>          match(Op1I, m_Xor(m_Specific(A), m_Specific(B))))
>
> Modified: llvm/trunk/test/Transforms/InstCombine/or-xor.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/or-xor.ll?rev=215524&r1=215523&r2=215524&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/or-xor.ll (original)
> +++ llvm/trunk/test/Transforms/InstCombine/or-xor.ll Wed Aug 13 00:13:14
> 2014
> @@ -136,3 +136,14 @@ define i32 @test13(i32 %x, i32 %y) {
>  ; CHECK-NEXT: %and = and i32 %x, %y
>  ; CHECK-NEXT: ret i32 %and
>  }
> +
> +; ((x | y) ^ (x ^ y)) -> (x & y)
> +define i32 @test15(i32 %x, i32 %y) {
> +  %1 = xor i32 %y, %x
> +  %2 = or i32 %y, %x
> +  %3 = xor i32 %2, %1
> +  ret i32 %3
> +; CHECK-LABEL: @test15(
> +; CHECK-NEXT: %1 = and i32 %y, %x
> +; CHECK-NEXT: ret i32 %1
>

I LGTM'd this differential under the understanding that you would clean up
the variable names used: http://reviews.llvm.org/D4866#inline-40056

Please fix test15.


> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140813/3e4a0866/attachment.html>


More information about the llvm-commits mailing list