[PATCH] D137435: [InstSimplify] (~A & B) | ~(A | B) --> ~A with logical and
Dave Green via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 4 09:24:07 PDT 2022
dmgreen updated this revision to Diff 473260.
dmgreen added a comment.
Use LogicalOr
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137435/new/
https://reviews.llvm.org/D137435
Files:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstCombine/or.ll
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
@@ -458,11 +458,7 @@
define i1 @and_or_not_or_logical(i1 %A, i1 %B) {
; CHECK-LABEL: @and_or_not_or_logical(
; CHECK-NEXT: [[V:%.*]] = xor i1 [[A:%.*]], true
-; CHECK-NEXT: [[X:%.*]] = select i1 [[V]], i1 [[B:%.*]], i1 false
-; CHECK-NEXT: [[W:%.*]] = or i1 [[B]], [[A]]
-; CHECK-NEXT: [[Y:%.*]] = xor i1 [[W]], true
-; CHECK-NEXT: [[Z:%.*]] = or i1 [[X]], [[Y]]
-; CHECK-NEXT: ret i1 [[Z]]
+; CHECK-NEXT: ret i1 [[V]]
;
%V = xor i1 %A, true
%X = select i1 %V, i1 %B, i1 false
@@ -476,11 +472,7 @@
define i1 @and_or_not_or_logical_rev(i1 %A, i1 %B) {
; CHECK-LABEL: @and_or_not_or_logical_rev(
; CHECK-NEXT: [[V:%.*]] = xor i1 [[A:%.*]], true
-; CHECK-NEXT: [[X:%.*]] = select i1 [[B:%.*]], i1 [[V]], i1 false
-; CHECK-NEXT: [[W:%.*]] = or i1 [[B]], [[A]]
-; CHECK-NEXT: [[Y:%.*]] = xor i1 [[W]], true
-; CHECK-NEXT: [[Z:%.*]] = or i1 [[X]], [[Y]]
-; CHECK-NEXT: ret i1 [[Z]]
+; CHECK-NEXT: ret i1 [[V]]
;
%V = xor i1 %A, true
%X = select i1 %B, i1 %V, i1 false
@@ -494,11 +486,7 @@
define i1 @and_or_not_logical_or_logical_rev(i1 %A, i1 %B) {
; CHECK-LABEL: @and_or_not_logical_or_logical_rev(
; CHECK-NEXT: [[V:%.*]] = xor i1 [[A:%.*]], true
-; CHECK-NEXT: [[X:%.*]] = select i1 [[B:%.*]], i1 [[V]], i1 false
-; CHECK-NEXT: [[W:%.*]] = select i1 [[B]], i1 true, i1 [[A]]
-; CHECK-NEXT: [[Y:%.*]] = xor i1 [[W]], true
-; CHECK-NEXT: [[Z:%.*]] = or i1 [[X]], [[Y]]
-; CHECK-NEXT: ret i1 [[Z]]
+; CHECK-NEXT: ret i1 [[V]]
;
%V = xor i1 %A, true
%X = select i1 %B, i1 %V, i1 false
Index: llvm/test/Transforms/InstCombine/or.ll
===================================================================
--- llvm/test/Transforms/InstCombine/or.ll
+++ llvm/test/Transforms/InstCombine/or.ll
@@ -1564,14 +1564,8 @@
define <4 x i1> @and_or_not_or_logical_vec(<4 x i32> %ap, <4 x i32> %bp) {
; CHECK-LABEL: @and_or_not_or_logical_vec(
-; CHECK-NEXT: [[A:%.*]] = icmp eq <4 x i32> [[AP:%.*]], zeroinitializer
-; CHECK-NEXT: [[B:%.*]] = icmp eq <4 x i32> [[BP:%.*]], zeroinitializer
-; CHECK-NEXT: [[V:%.*]] = xor <4 x i1> [[A]], <i1 true, i1 true, i1 true, i1 true>
-; CHECK-NEXT: [[X:%.*]] = select <4 x i1> [[B]], <4 x i1> [[V]], <4 x i1> zeroinitializer
-; CHECK-NEXT: [[W:%.*]] = or <4 x i1> [[B]], [[A]]
-; CHECK-NEXT: [[Y:%.*]] = xor <4 x i1> [[W]], <i1 true, i1 true, i1 true, i1 true>
-; CHECK-NEXT: [[Z:%.*]] = or <4 x i1> [[X]], [[Y]]
-; CHECK-NEXT: ret <4 x i1> [[Z]]
+; CHECK-NEXT: [[A:%.*]] = icmp ne <4 x i32> [[AP:%.*]], zeroinitializer
+; CHECK-NEXT: ret <4 x i1> [[A]]
;
%A = icmp eq <4 x i32> %ap, zeroinitializer
%B = icmp eq <4 x i32> %bp, zeroinitializer
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -2262,6 +2262,12 @@
m_Value(B))) &&
match(Y, m_Not(m_c_Or(m_Specific(A), m_Specific(B)))))
return NotA;
+ // The same is true of Logical And
+ if (match(X, m_c_LogicalAnd(
+ m_CombineAnd(m_Value(NotA), m_NotForbidUndef(m_Value(A))),
+ m_Value(B))) &&
+ match(Y, m_Not(m_c_LogicalOr(m_Specific(A), m_Specific(B)))))
+ return NotA;
// ~(A ^ B) | (A & B) --> ~(A ^ B)
// ~(A ^ B) | (B & A) --> ~(A ^ B)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137435.473260.patch
Type: text/x-patch
Size: 3596 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221104/77667bf1/attachment.bin>
More information about the llvm-commits
mailing list