[PATCH] D159510: [InstCombine] Optimize 'xor-and-select' sequence to 'or' for bool
Qi Hu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 13 16:47:13 PDT 2023
Qi-Hu created this revision.
Qi-Hu added a reviewer: bryanpkc.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Qi-Hu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
xor-and-select -> or : https://alive2.llvm.org/ce/z/52ZT62
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D159510
Files:
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/fold-xor-and-select-i1.ll
Index: llvm/test/Transforms/InstCombine/fold-xor-and-select-i1.ll
===================================================================
--- llvm/test/Transforms/InstCombine/fold-xor-and-select-i1.ll
+++ llvm/test/Transforms/InstCombine/fold-xor-and-select-i1.ll
@@ -4,10 +4,8 @@
define i1 @max_if(i1 %a, i1 %b) {
; CHECK-LABEL: define i1 @max_if
; CHECK-SAME: (i1 [[A:%.*]], i1 [[B:%.*]]) {
-; CHECK-NEXT: [[TMP1:%.*]] = xor i1 [[B]], true
-; CHECK-NEXT: [[CMP:%.*]] = and i1 [[TMP1]], [[A]]
-; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[CMP]], i1 [[A]], i1 [[B]]
-; CHECK-NEXT: ret i1 [[TMP2]]
+; CHECK-NEXT: [[TMP1:%.*]] = or i1 [[A]], [[B]]
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%1 = xor i1 %b, true
%cmp = and i1 %1, %a
Index: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -3174,6 +3174,14 @@
}
}
+ // select (~b & a), a, b -> or a, b
+ // only for scalar types
+ if (match(CondVal, m_And(m_Not(m_Specific(FalseVal)), m_Specific(TrueVal))) &&
+ TrueVal->getType()->isIntegerTy(1) &&
+ FalseVal->getType()->isIntegerTy(1)) {
+ return BinaryOperator::CreateOr(TrueVal, FalseVal);
+ }
+
return nullptr;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159510.556733.patch
Type: text/x-patch
Size: 1351 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230913/257394d2/attachment.bin>
More information about the llvm-commits
mailing list