[PATCH] D101807: [InstCombine] Fold select x_inv, true, (select y, x, false)
Juneyoung Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 3 18:17:45 PDT 2021
aqjune created this revision.
aqjune added reviewers: nikic, spatel, lebedev.ri.
Herald added a subscriber: hiraditya.
aqjune requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This is a simple folding that optimizes
select x_inv, true, (select y, x, false)
to
select x_inv, true, y
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D101807
Files:
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/select-safe-transforms.ll
Index: llvm/test/Transforms/InstCombine/select-safe-transforms.ll
===================================================================
--- llvm/test/Transforms/InstCombine/select-safe-transforms.ll
+++ llvm/test/Transforms/InstCombine/select-safe-transforms.ll
@@ -181,10 +181,8 @@
define i1 @orn_and_cmp_1_logical(i37 %a, i37 %b, i1 %y) {
; CHECK-LABEL: @orn_and_cmp_1_logical(
-; CHECK-NEXT: [[X:%.*]] = icmp sgt i37 [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT: [[X_INV:%.*]] = icmp sle i37 [[A]], [[B]]
-; CHECK-NEXT: [[AND:%.*]] = select i1 [[Y:%.*]], i1 [[X]], i1 false
-; CHECK-NEXT: [[OR:%.*]] = select i1 [[X_INV]], i1 true, i1 [[AND]]
+; CHECK-NEXT: [[X_INV:%.*]] = icmp sle i37 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[OR:%.*]] = select i1 [[X_INV]], i1 true, i1 [[Y:%.*]]
; CHECK-NEXT: ret i1 [[OR]]
;
%x = icmp sgt i37 %a, %b
Index: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -2773,6 +2773,14 @@
if (Res && *Res == false)
return replaceOperand(SI, 1, A);
}
+ // select c, true, (select a, b, false) -> select c, true, a
+ // if c = false implies that b = true
+ if (match(TrueVal, m_One()) &&
+ match(FalseVal, m_Select(m_Value(A), m_Value(B), m_Zero()))) {
+ Optional<bool> Res = isImpliedCondition(CondVal, B, DL, false);
+ if (Res && *Res == true)
+ return replaceOperand(SI, 2, A);
+ }
// sel (sel c, a, false), true, (sel !c, b, false) -> sel c, a, b
// sel (sel !c, a, false), true, (sel c, b, false) -> sel c, b, a
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101807.342616.patch
Type: text/x-patch
Size: 1721 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210504/8054255c/attachment.bin>
More information about the llvm-commits
mailing list