[PATCH] D86363: InstCombine transform pattern "(A ^ B) | ~(A | B) -> ~(A & B)" added
Jaydeep Chauhan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 21 12:35:39 PDT 2020
Jac1494 created this revision.
Jac1494 added reviewers: silvas, dexonsmith, majnemer, nicholas.
Jac1494 added a project: LLVM.
Herald added a subscriber: hiraditya.
Jac1494 requested review of this revision.
This patch implements transform for pattern "(A ^ B) | ~(A | B) -> ~(A & B)".
And this pattern is already implemented in gcc.
https://reviews.llvm.org/D86363
Files:
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/or-and.ll
Index: llvm/test/Transforms/InstCombine/or-and.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/or-and.ll
@@ -0,0 +1,14 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+; (A ^ B) | ~(A | B) -> ~(A & B)
+define i32 @test1(i32 %0, i32 %1) {
+; CHECK-LABEL: @test1(
+; CHECK-NEXT: %3 = and i32 %0, %1
+; CHECK-NEXT: %4 = xor i32 %3, -1
+; CHECK-NEXT: ret i32 %4
+ %3 = xor i32 %0, %1
+ %4 = or i32 %0, %1
+ %5 = xor i32 %4, -1
+ %6 = or i32 %3, %5
+ ret i32 %6
+}
Index: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2694,6 +2694,11 @@
}
}
+ // (A ^ B) | ~(A | B) -> ~(A & B)
+ if (match(Op0, m_Xor(m_Value(A), m_Value(B))))
+ if (match(Op1, m_Not(m_Or(m_Value(A), m_Value(B)))))
+ return BinaryOperator::CreateNot(Builder.CreateAnd(A, B));
+
// (A ^ B) | ((B ^ C) ^ A) -> (A ^ B) | C
if (match(Op0, m_Xor(m_Value(A), m_Value(B))))
if (match(Op1, m_Xor(m_Xor(m_Specific(B), m_Value(C)), m_Specific(A))))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86363.287084.patch
Type: text/x-patch
Size: 1217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200821/ba4820dc/attachment.bin>
More information about the llvm-commits
mailing list