[PATCH] D145157: [InstCombine] Implement "A & (~A | B) --> A & B" for boolean vectors.
Paul Walker via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 2 07:36:01 PST 2023
paulwalker-arm updated this revision to Diff 501865.
paulwalker-arm added a comment.
Updated to include correct handling of poison.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145157/new/
https://reviews.llvm.org/D145157
Files:
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/logical-select.ll
Index: llvm/test/Transforms/InstCombine/logical-select.ll
===================================================================
--- llvm/test/Transforms/InstCombine/logical-select.ll
+++ llvm/test/Transforms/InstCombine/logical-select.ll
@@ -1121,3 +1121,27 @@
call void @use1(i1 %and1)
ret i1 %r
}
+
+; A & (~A | B) --> A & B
+define <2 x i1> @and_commute1(<2 x i1> %a, <2 x i1> %b) {
+; CHECK-LABEL: @and_commute1(
+; CHECK-NEXT: [[AND:%.*]] = select <2 x i1> [[A:%.*]], <2 x i1> [[B:%.*]], <2 x i1> zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[AND]]
+;
+ %not = xor <2 x i1> %a, <i1 true, i1 true>
+ %or = or <2 x i1> %b, %not
+ %and = select <2 x i1> %a, <2 x i1> %or, <2 x i1> zeroinitializer
+ ret <2 x i1> %and
+}
+
+; A & (~A | B) --> A & B
+define <2 x i1> @and_commute2(<2 x i1> %a, <2 x i1> %b) {
+; CHECK-LABEL: @and_commute2(
+; CHECK-NEXT: [[AND:%.*]] = select <2 x i1> [[A:%.*]], <2 x i1> [[B:%.*]], <2 x i1> zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[AND]]
+;
+ %not = xor <2 x i1> %a, <i1 true, i1 true>
+ %or = select <2 x i1> %not, <2 x i1> <i1 true, i1 true>, <2 x i1> %b
+ %and = select <2 x i1> %a, <2 x i1> %or, <2 x i1> zeroinitializer
+ ret <2 x i1> %and
+}
Index: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -2984,6 +2984,10 @@
if (match(CondVal, m_Select(m_Value(A), m_Value(B), m_Zero())) &&
match(TrueVal, m_Specific(B)) && match(FalseVal, m_Zero()))
return replaceOperand(SI, 0, A);
+ // select a, (select ~a, true, b), false -> select a, b, false
+ if (match(TrueVal, m_c_LogicalOr(m_Not(m_Specific(CondVal)), m_Value(B))) &&
+ match(FalseVal, m_Zero()))
+ return replaceOperand(SI, 1, B);
// ~(A & B) & (A | B) --> A ^ B
if (match(&SI, m_c_LogicalAnd(m_Not(m_LogicalAnd(m_Value(A), m_Value(B))),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145157.501865.patch
Type: text/x-patch
Size: 1987 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230302/3ff118bd/attachment.bin>
More information about the llvm-commits
mailing list