[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 11:33:29 PDT 2020
Jac1494 updated this revision to Diff 291286.
Jac1494 added a comment.
test53 and test55 has been removed.
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,11 @@
ret i32 %z
}
-; (~B & A) ^ B --> (A | B)
-; The division ops are here to thwart complexity-based canonicalization: all ops are binops.
-
define i32 @test53(i32 %p1, 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]]
-;
- %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
-}
-
-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
@@ -1228,20 +1204,3 @@
%z = xor i32 %r, %a
ret i32 %z
}
-
-define i32 @test55(i32 %p1, i32 %p2) {
-; 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: ret i32 [[Z]]
-;
- %a = udiv i32 42, %p1
- %b = udiv i32 42, %p2
- %o = xor i32 %a, -1
- %r = and i32 %o, %b
- %z = xor i32 %a, %r
- ret i32 %z
-}
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.291286.patch
Type: text/x-patch
Size: 3013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200911/f0892e45/attachment.bin>
More information about the llvm-commits
mailing list