[PATCH] D114996: Add logic `or` fold
Mehrnoosh Heidarpour via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 3 07:45:33 PST 2021
MehrHeidar updated this revision to Diff 391646.
MehrHeidar added reviewers: spatel, foad.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114996/new/
https://reviews.llvm.org/D114996
Files:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/or.ll
Index: llvm/test/Transforms/InstSimplify/or.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/or.ll
+++ llvm/test/Transforms/InstSimplify/or.ll
@@ -845,11 +845,7 @@
define i4 @or_xor_not_op_or(i4 %a, i4 %b){
; CHECK-LABEL: @or_xor_not_op_or(
-; CHECK-NEXT: [[XOR:%.*]] = xor i4 [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT: [[NOTA:%.*]] = xor i4 [[A]], -1
-; CHECK-NEXT: [[OR:%.*]] = or i4 [[NOTA]], [[B]]
-; CHECK-NEXT: [[R:%.*]] = or i4 [[XOR]], [[OR]]
-; CHECK-NEXT: ret i4 [[R]]
+; CHECK-NEXT: ret i4 -1
;
%xor = xor i4 %a, %b
%nota = xor i4 %a, -1
@@ -862,11 +858,7 @@
define i71 @or_xor_not_op_or_commute1(i71 %a, i71 %b){
; CHECK-LABEL: @or_xor_not_op_or_commute1(
-; CHECK-NEXT: [[XOR:%.*]] = xor i71 [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT: [[NOTB:%.*]] = xor i71 [[B]], -1
-; CHECK-NEXT: [[OR:%.*]] = or i71 [[NOTB]], [[A]]
-; CHECK-NEXT: [[R:%.*]] = or i71 [[XOR]], [[OR]]
-; CHECK-NEXT: ret i71 [[R]]
+; CHECK-NEXT: ret i71 -1
;
%xor = xor i71 %a, %b
%notb = xor i71 %b, -1
@@ -879,11 +871,7 @@
define i32 @or_xor_not_op_or_commute2(i32 %a, i32 %b){
; CHECK-LABEL: @or_xor_not_op_or_commute2(
-; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT: [[NOTA:%.*]] = xor i32 [[A]], -1
-; CHECK-NEXT: [[OR:%.*]] = or i32 [[NOTA]], [[B]]
-; CHECK-NEXT: [[R:%.*]] = or i32 [[OR]], [[XOR]]
-; CHECK-NEXT: ret i32 [[R]]
+; CHECK-NEXT: ret i32 -1
;
%xor = xor i32 %a, %b
%nota = xor i32 %a, -1
@@ -894,11 +882,7 @@
define <2 x i4> @or_xor_not_op_or_undef_elt(<2 x i4> %a, <2 x i4> %b) {
; CHECK-LABEL: @or_xor_not_op_or_undef_elt(
-; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i4> [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT: [[NOTA:%.*]] = xor <2 x i4> [[A]], <i4 -1, i4 undef>
-; CHECK-NEXT: [[OR:%.*]] = or <2 x i4> [[NOTA]], [[B]]
-; CHECK-NEXT: [[R:%.*]] = or <2 x i4> [[XOR]], [[OR]]
-; CHECK-NEXT: ret <2 x i4> [[R]]
+; CHECK-NEXT: ret <2 x i4> <i4 -1, i4 -1>
;
%xor = xor <2 x i4> %a, %b
%nota = xor <2 x i4> %a, <i4 -1, i4 undef>
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -2226,6 +2226,12 @@
match(Y, m_c_Or(m_Specific(A), m_Specific(B))))
return ConstantInt::getAllOnesValue(Ty);
+ // (A ^ B) | (~A | B) --> -1
+ // (A ^ B) | (~B | A) --> -1
+ if (match(X, m_c_Or(m_Not(m_Value(A)), m_Value(B))) &&
+ match(Y, m_c_Xor(m_Specific(A), m_Specific(B))))
+ return ConstantInt::getAllOnesValue(Ty);
+
return nullptr;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114996.391646.patch
Type: text/x-patch
Size: 2691 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211203/d60bf50b/attachment.bin>
More information about the llvm-commits
mailing list