[PATCH] Added InstCombine Transform for pattern "((~A & B) | A) -> (A | B)"
Duncan P. N. Exon Smith
dexonsmith at apple.com
Mon Jul 21 14:55:15 PDT 2014
> On 2014-Jul-18, at 12:59, suyog <suyog.sarda at samsung.com> wrote:
>
> Hi nicholas, rafael, dexonsmith,
>
> This patch implements transform for pattern "((~A & B) | A) -> (A | B)"
>
> Please help in reviewing this patch.
>
> http://reviews.llvm.org/D4591
>
> Files:
> lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
> test/Transforms/InstCombine/or.ll
>
This looks good, but I think you should handle this (essentially
equivalent) transformation as well:
((A & B) | ~A) -> (~A | B)
I'm not sure if there's a way to share logic, but it would be great if
there is.
> Index: test/Transforms/InstCombine/or.ll
> ===================================================================
> --- test/Transforms/InstCombine/or.ll
> +++ test/Transforms/InstCombine/or.ll
> @@ -408,3 +408,12 @@
> %or = or i32 %x, %sext
> ret i32 %or
> }
> +
> +define i32 @test39(i32 %a, i32 %b) {
> +; CHECK-LABEL: test39(
> +; CHECK-NEXT: %or = or i32 %a, %b
> + %xor = xor i32 %a, -1
> + %and = and i32 %xor, %b
> + %or = or i32 %and, %a
> + ret i32 %or
> +}
> Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
> ===================================================================
> --- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
> +++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
> @@ -1988,6 +1988,11 @@
> return BinaryOperator::CreateXor(NOr, C1);
> }
>
> + // ((~A & B) | A) -> (A | B)
> + if (match(Op0, m_And(m_Not(m_Value(A)), m_Value(B))) &&
> + match(Op1, m_Specific(A)))
> + return BinaryOperator::CreateOr(A, B);
> +
> // (A & C)|(B & D)
> Value *C = nullptr, *D = nullptr;
> if (match(Op0, m_And(m_Value(A), m_Value(C))) &&
> <D4591.11666.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