[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 06:21:54 PST 2023
paulwalker-arm created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
paulwalker-arm requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
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,15 @@
call void @use1(i1 %and1)
ret i1 %r
}
+
+; A & (~A | B) --> A & B
+define <2 x i1> @and_commute(<2 x i1> %a, <2 x i1> %b) {
+; CHECK-LABEL: @and_commute(
+; CHECK-NEXT: [[AND:%.*]] = and <2 x i1> [[A:%.*]], [[B:%.*]]
+; 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
@@ -2990,6 +2990,11 @@
m_c_LogicalOr(m_Deferred(A), m_Deferred(B)))))
return BinaryOperator::CreateXor(A, B);
+ // A & (~A | B) --> A & B
+ if (match(&SI, m_c_LogicalAnd(m_Value(A), m_c_LogicalOr(m_Not(m_Deferred(A)),
+ m_Value(B)))))
+ return BinaryOperator::CreateAnd(A, B);
+
// select (~a | c), a, b -> and a, (or c, freeze(b))
if (match(CondVal, m_c_Or(m_Not(m_Specific(TrueVal)), m_Value(C))) &&
CondVal->hasOneUse()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145157.501846.patch
Type: text/x-patch
Size: 1525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230302/1788e5b0/attachment.bin>
More information about the llvm-commits
mailing list