[PATCH] D86395: [InstCombine] transform pattern "(~A & B) ^ A -> (A | B)" added
Jaydeep Chauhan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 11 08:52:21 PDT 2020
Jac1494 updated this revision to Diff 291230.
Jac1494 added a comment.
Addressed the review comments of @spatel and @xbolva00 .
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86395/new/
https://reviews.llvm.org/D86395
Files:
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/xor.ll
Index: llvm/test/Transforms/InstCombine/xor.ll
===================================================================
--- llvm/test/Transforms/InstCombine/xor.ll
+++ llvm/test/Transforms/InstCombine/xor.ll
@@ -1179,9 +1179,7 @@
; CHECK-LABEL: @test52(
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
-; CHECK-NEXT: [[O:%.*]] = xor i32 [[A]], -1
-; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[O]]
-; CHECK-NEXT: [[Z:%.*]] = xor i32 [[R]], [[A]]
+; CHECK-NEXT: [[Z:%.*]] = or i32 [[A]], [[B]]
; CHECK-NEXT: ret i32 [[Z]]
;
%a = udiv i32 42, %p1
@@ -1192,33 +1190,28 @@
ret i32 %z
}
-; (~B & A) ^ B --> (A | B)
-; The division ops are here to thwart complexity-based canonicalization: all ops are binops.
+; vector test for pattern (~A & B) ^ A --> (A | B)
-define i32 @test53(i32 %p1, i32 %p2) {
+define <4 x i32> @test53(<4 x i32> %p1, <4 x i32> %p2) {
; CHECK-LABEL: @test53(
-; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
-; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
-; CHECK-NEXT: [[O:%.*]] = xor i32 [[B]], -1
-; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], [[O]]
-; CHECK-NEXT: [[Z:%.*]] = xor i32 [[R]], [[B]]
-; CHECK-NEXT: ret i32 [[Z]]
+; CHECK-NEXT: [[A:%.*]] = udiv <4 x i32> <i32 42, i32 42, i32 42, i32 42>, [[P1:%.*]]
+; CHECK-NEXT: [[B:%.*]] = udiv <4 x i32> <i32 42, i32 42, i32 42, i32 42>, [[P2:%.*]]
+; CHECK-NEXT: [[Z:%.*]] = or <4 x i32> [[A]], [[B]]
+; CHECK-NEXT: ret <4 x i32> [[Z]]
;
- %a = udiv i32 42, %p1
- %b = udiv i32 42, %p2
- %o = xor i32 %b, -1
- %r = and i32 %o, %a
- %z = xor i32 %r, %b
- ret i32 %z
+ %a = udiv <4 x i32> <i32 42, i32 42, i32 42, i32 42>, %p1
+ %b = udiv <4 x i32> <i32 42, i32 42, i32 42, i32 42>, %p2
+ %o = xor <4 x i32> %a, <i32 -1, i32 -1, i32 -1, i32 -1>
+ %r = and <4 x i32> %o, %b
+ %z = xor <4 x i32> %r, %a
+ ret <4 x i32> %z
}
define i32 @test54(i32 %p1, i32 %p2) {
; CHECK-LABEL: @test54(
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
-; CHECK-NEXT: [[O:%.*]] = xor i32 [[A]], -1
-; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[O]]
-; CHECK-NEXT: [[Z:%.*]] = xor i32 [[R]], [[A]]
+; CHECK-NEXT: [[Z:%.*]] = or i32 [[A]], [[B]]
; CHECK-NEXT: ret i32 [[Z]]
;
%a = udiv i32 42, %p1
@@ -1233,9 +1226,7 @@
; CHECK-LABEL: @test55(
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
-; CHECK-NEXT: [[O:%.*]] = xor i32 [[A]], -1
-; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[O]]
-; CHECK-NEXT: [[Z:%.*]] = xor i32 [[A]], [[R]]
+; CHECK-NEXT: [[Z:%.*]] = or i32 [[A]], [[B]]
; CHECK-NEXT: ret i32 [[Z]]
;
%a = udiv i32 42, %p1
Index: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -3371,6 +3371,10 @@
match(Op1, m_Not(m_Specific(A))))
return BinaryOperator::CreateNot(Builder.CreateAnd(A, B));
+ // (~A & B) ^ A --> (A | B) -- There are 4 commuted variants.
+ if (match(&I, m_c_Xor(m_c_And(m_Not(m_Value(A)), m_Value(B)), m_Deferred(A))))
+ return BinaryOperator::CreateOr(A, B);
+
// (A | B) ^ (A | C) --> (B ^ C) & ~A -- There are 4 commuted variants.
// TODO: Loosen one-use restriction if common operand is a constant.
Value *D;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86395.291230.patch
Type: text/x-patch
Size: 3515 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200911/e319bd5f/attachment.bin>
More information about the llvm-commits
mailing list