[PATCH] Added InstCombine transform for pattern "(A | B) ^ (~A) = (~A) ^ (A | B) -> (A | ~B)"
Duncan P. N. Exon Smith
dexonsmith at apple.com
Mon Jul 21 16:41:58 PDT 2014
> On 2014-Jul-18, at 12:16, suyog <suyog.sarda at samsung.com> wrote:
>
> Hi nicholas, rafael, dexonsmith,
>
> This patch implements transform for pattern "(A | B) ^ (~A) = (~A) ^ (A | B) -> (A | ~B)"
>
> Please help in reviewing the same.
>
> Thanks,
> Suyog
>
> http://reviews.llvm.org/D4588
>
LGTM with a minor comment change.
> Files:
> lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
> test/Transforms/InstCombine/xor2.ll
>
> Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
> ===================================================================
> --- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
> +++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
> @@ -2446,6 +2446,12 @@
> }
> }
>
> + // (A | B)^(~A) = (~A)^(A | B) -> (A | ~B)
I found the `=` confusing here. I think this should just be:
// (A | B)^(~A) -> (A | ~B)
> + Value *A = nullptr, *B = nullptr;
> + if (match(Op0, m_Or(m_Value(A), m_Value(B))) &&
> + match(Op1, m_Not(m_Specific(A))))
> + return BinaryOperator::CreateOr(A, Builder->CreateNot(B));
> +
> // (icmp1 A, B) ^ (icmp2 A, B) --> (icmp3 A, B)
> if (ICmpInst *RHS = dyn_cast<ICmpInst>(I.getOperand(1)))
> if (ICmpInst *LHS = dyn_cast<ICmpInst>(I.getOperand(0)))
> Index: test/Transforms/InstCombine/xor2.ll
> ===================================================================
> --- test/Transforms/InstCombine/xor2.ll
> +++ test/Transforms/InstCombine/xor2.ll
> @@ -82,3 +82,25 @@
> ; CHECK: lshr i32 %x, 16
> ; CHECK: ret
> }
> +
> +; (A | B) ^ (~A) -> (A | ~B)
> +define i32 @test7(i32 %a, i32 %b) #0 {
> + %or = or i32 %a, %b
> + %neg = xor i32 %a, -1
> + %xor = xor i32 %or, %neg
> + ret i32 %xor
> +; CHECK-LABEL: @test7(
> +; CHECK-NEXT: %1 = xor i32 %b, -1
> +; CHECK-NEXT: %xor = or i32 %a, %1
> +}
> +
> +; (~A) ^ (A | B) -> (A | ~B)
> +define i32 @test8(i32 %a, i32 %b) #0 {
> + %neg = xor i32 %a, -1
> + %or = or i32 %a, %b
> + %xor = xor i32 %neg, %or
> + ret i32 %xor
> +; CHECK-LABEL: @test8(
> +; CHECK-NEXT: %1 = xor i32 %b, -1
> +; CHECK-NEXT: %xor = or i32 %a, %1
> +}
> <D4588.11657.patch>_______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list