[PATCH] D86395: [InstCombine] transform pattern "(~A & B) ^ A -> (A | B)" added
Jaydeep Chauhan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 11:57:15 PDT 2020
Jac1494 updated this revision to Diff 291045.
Jac1494 retitled this revision from "InstCombine transform pattern "(~A & B) ^ A -> (A | B)" added" to "[InstCombine] transform pattern "(~A & B) ^ A -> (A | B)" added".
Jac1494 added a comment.
Test cases are tested and updated.
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
@@ -1199,9 +1197,7 @@
; 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: [[Z:%.*]] = or i32 [[B]], [[A]]
; CHECK-NEXT: ret i32 [[Z]]
;
%a = udiv i32 42, %p1
@@ -1216,9 +1212,7 @@
; 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 +1227,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.291045.patch
Type: text/x-patch
Size: 2600 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200910/22910730/attachment.bin>
More information about the llvm-commits
mailing list