[PATCH] Added InstCombine Transformation for (A^B)^((~A)&B) -> A&(~B)

Anton Korobeynikov anton at korobeynikov.info
Sat Aug 23 11:08:24 PDT 2014


Again, it will be really nice if you'll provide examples in the
real-world programs which would require and benefit such matching
patterns.

On Sat, Aug 23, 2014 at 10:42 AM, Ankur Garg <ankur29.garg at samsung.com> wrote:
> Hi David,
> Thank you for the comments.
> I have made the changes as you suggested. Please review the updated revision.
>
>
> Updated Transformation:
> (A ^ B) ^ ((A ^ C) & B) -> (C ^ (B | (A ^ C))
>
> New Z3 Link: http://rise4fun.com/Z3/KmnV7
>
> Thanks,
> Ankur Garg
>
> http://reviews.llvm.org/D5002
>
> 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
> @@ -2552,6 +2552,10 @@
>      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 ^ C) & B) -> (C ^ (B | (A ^ C)))
> +    if (match(Op0I, m_Xor(m_Value(A), m_Value(B))) &&
> +        match(Op1I, m_And(m_Xor(m_Specific(A), m_Value(C)), m_Specific(B))))
> +      return BinaryOperator::CreateXor(C, Builder->CreateOr(B, Builder->CreateXor(A, C)));
>    }
>
>    // (A | B)^(~A) -> (A | ~B)
> Index: test/Transforms/InstCombine/xor2.ll
> ===================================================================
> --- test/Transforms/InstCombine/xor2.ll
> +++ test/Transforms/InstCombine/xor2.ll
> @@ -167,3 +167,28 @@
>  ; CHECK-NEXT: %1 = and i32 %a, %b
>  ; CHECK-NEXT: %xor = xor i32 %1, -1
>  }
> +
> +define i32 @test15(i32 %a, i32 %b) {
> +; CHECK-LABEL: test15(
> +; CHECK-NEXT: %1 = xor i32 %b, -1
> +; CHECK-NEXT: %xor2 = and i32 %a, %1
> +; CHECK-NEXT: ret i32 %xor2
> + %xor1 = xor i32 %a, %b
> + %not = xor i32 %a, -1
> + %and = and i32 %not, %b
> + %xor2 = xor i32 %xor1, %and
> + ret i32 %xor2
> +}
> +
> +define i32 @test16(i32 %a, i32 %b, i32 %c) {
> +; CHECK-LABEL: test16(
> +; CHECK-NEXT: %1 = xor i32 %a, %c
> +; CHECK-NEXT: %2 = or i32 %1, %b
> +; CHECK-NEXT: %xor2 = xor i32 %2, %c
> +; CHECK-NEXT: ret i32 %xor2
> + %xor1 = xor i32 %a, %b
> + %not = xor i32 %a, %c
> + %and = and i32 %not, %b
> + %xor2 = xor i32 %xor1, %and
> + 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