[PATCH] InstCombine ((x | ~y) ^ (~x ^ y)) to (x & ~y)
Anton Korobeynikov
anton at korobeynikov.info
Sat Aug 16 12:04:48 PDT 2014
I'm really curios - how often such patterns happen in real world code?
On Sat, Aug 16, 2014 at 12:14 PM, Mayur Pandey <mayur.p at samsung.com> wrote:
> Hi majnemer,
>
> Hi David,
>
> Another small patch in instcombine. Can you please review the patch.
>
> Proof:
> $ cat t.cvc
> A, B : BITVECTOR(32);
> QUERY BVXOR((A | ~B),BVXOR(~A,B)) = (A & ~B);
> $ cvc3 t.cvc
> Valid.
>
> Thanks,
> Mayur
>
> http://reviews.llvm.org/D4940
>
> Files:
> lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
> test/Transforms/InstCombine/or-xor.ll
>
> Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
> ===================================================================
> --- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
> +++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
> @@ -2542,6 +2542,14 @@
> if (match(Op0I, m_Xor(m_Value(A), m_Value(B))) &&
> match(Op1I, m_And(m_Specific(A), m_Specific(B))))
> return BinaryOperator::CreateOr(A, B);
> + // (A | ~B) ^ (~A ^ B) -> A & ~B
> + if (match(Op0I, m_Or(m_Value(A), m_Not(m_Value(B)))) &&
> + match(Op1I, m_Xor(m_Not(m_Specific(A)), m_Specific(B))))
> + return BinaryOperator::CreateAnd(A, Builder->CreateNot(B));
> + // (B ^ ~A) ^ (~B | A) -> A & ~B
> + if (match(Op0I, m_Xor(m_Value(B), m_Not(m_Value(A)))) &&
> + match(Op1I, m_Or(m_Not(m_Specific(B)), m_Specific(A))))
> + return BinaryOperator::CreateAnd(A, Builder->CreateNot(B));
> }
>
> // (A | B)^(~A) -> (A | ~B)
> Index: test/Transforms/InstCombine/or-xor.ll
> ===================================================================
> --- test/Transforms/InstCombine/or-xor.ll
> +++ test/Transforms/InstCombine/or-xor.ll
> @@ -160,3 +160,17 @@
> ; CHECK-NEXT: %xor = xor i32 %x, %y
> ; CHECK-NEXT: ret i32 %xor
> }
> +
> +; ((x | ~y) ^ (~x ^ y)) -> (x & ~y)
> +define i32 @test18(i32 %x, i32 %y) {
> + %noty = xor i32 %y, -1
> + %or = or i32 %x, %noty
> + %notx = xor i32 %x, -1
> + %xor1 = xor i32 %notx, %y
> + %xor2 = xor i32 %or, %xor1
> + ret i32 %xor2
> +; CHECK-LABEL: @test18(
> +; CHECK-NEXT: %1 = xor i32 %y, -1
> +; CHECK-NEXT: %xor2 = and i32 %x, %1
> +; CHECK-NEXT: ret i32 %xor2
> +}
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
--
With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University
More information about the llvm-commits
mailing list