[PATCH] D138744: [InstSimplify] Fold more Select with Or pattern
Liao Chunyu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 26 05:29:46 PST 2022
liaolucy created this revision.
liaolucy added a reviewer: spatel.
Herald added a subscriber: hiraditya.
Herald added a project: All.
liaolucy requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Issue: #59196
https://alive2.llvm.org/ce/z/Li-Eqq
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138744
Files:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/select-or-cmp.ll
Index: llvm/test/Transforms/InstSimplify/select-or-cmp.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/select-or-cmp.ll
+++ llvm/test/Transforms/InstSimplify/select-or-cmp.ll
@@ -337,3 +337,21 @@
%D = select i1 %C, i32 %x, i32 %k
ret i32 %D
}
+
+define i1 @select_or_return_true(i1 %x, i1 %y) {
+; CHECK-LABEL: @select_or_return_true(
+; CHECK-NEXT: ret i1 [[Y:%.*]]
+;
+ %C = or i1 %x, %y
+ %D = select i1 %C, i1 %y, i1 %x
+ ret i1 %D
+}
+
+define <2 x i1> @select_or_return_true1(<2 x i1> %x, <2 x i1> %y) {
+; CHECK-LABEL: @select_or_return_true1(
+; CHECK-NEXT: ret <2 x i1> [[Y:%.*]]
+;
+ %C = or <2 x i1> %x, %y
+ %D = select <2 x i1> %C, <2 x i1> %y, <2 x i1> %x
+ ret <2 x i1> %D
+}
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -82,6 +82,14 @@
else
return nullptr;
+ // %C = or %FV, %TV
+ // %D = select %C, %TV, %FV
+ // -->
+ // %TV
+ if (BinOpCode == BinaryOperator::Or &&
+ match(Cond, m_LogicalOr(m_Specific(FalseVal), m_Specific(TrueVal))))
+ return TrueVal;
+
CmpInst::Predicate ExpectedPred, Pred1, Pred2;
if (BinOpCode == BinaryOperator::Or) {
ExpectedPred = ICmpInst::ICMP_NE;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138744.478052.patch
Type: text/x-patch
Size: 1378 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221126/0aeb331f/attachment.bin>
More information about the llvm-commits
mailing list