[llvm] [InstCombine] Fold icmp in select to smin (PR #87157)
Krishna Narayanan via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 12 10:21:42 PDT 2024
https://github.com/Krishna-13-cyber updated https://github.com/llvm/llvm-project/pull/87157
>From 394befb5213028ce41aecf94e7e9725e7c22a7a5 Mon Sep 17 00:00:00 2001
From: Krishna-13-cyber <krishnanarayanan132002 at gmail.com>
Date: Sat, 30 Mar 2024 20:21:29 +0530
Subject: [PATCH 1/4] Fold icmp in select to smin
---
.../InstCombine/InstCombineSelect.cpp | 22 +++++++++++++++++++
.../Transforms/InstCombine/icmp-select.ll | 13 +++++++++++
2 files changed, 35 insertions(+)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 9ab2bd8f70aa15..4e58ba5f01df1c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -1687,6 +1687,25 @@ static Value *foldSelectInstWithICmpConst(SelectInst &SI, ICmpInst *ICI,
return nullptr;
}
+static Value *foldSelectInstWithICmpOr(SelectInst &SI, ICmpInst *ICI,
+ InstCombiner::BuilderTy &Builder) {
+ /* a > -1 ? 1 : (a | 3) --> smin(1, a | 3) */
+ Type *Ty = SI.getType();
+ Value *TVal = SI.getTrueValue();
+ Value *FVal = SI.getFalseValue();
+ Constant *One = ConstantInt::get(Ty, 1);
+ CmpInst::Predicate Pred = ICI->getPredicate();
+ Value *A = ICI->getOperand(0);
+ const APInt *Cmp;
+
+ if (!match(TVal, m_One()) || !match(FVal, m_Or(m_Value(A), m_SpecificInt(3))))
+ return nullptr;
+
+ if (Pred == ICmpInst::ICMP_SGT && *Cmp == -1 && match(TVal, m_One()) &&
+ match(FVal, m_Or(m_Value(A), m_SpecificInt(3))))
+ return Builder.CreateBinaryIntrinsic(Intrinsic::smin, One, FVal);
+}
+
/// Visit a SelectInst that has an ICmpInst as its first operand.
Instruction *InstCombinerImpl::foldSelectInstWithICmp(SelectInst &SI,
ICmpInst *ICI) {
@@ -1700,6 +1719,9 @@ Instruction *InstCombinerImpl::foldSelectInstWithICmp(SelectInst &SI,
if (Value *V = foldSelectInstWithICmpConst(SI, ICI, Builder))
return replaceInstUsesWith(SI, V);
+ if (Value *V = foldSelectInstWithICmpOr(SI, ICI, Builder))
+ return replaceInstUsesWith(SI, V);
+
if (Value *V = canonicalizeClampLike(SI, *ICI, Builder))
return replaceInstUsesWith(SI, V);
diff --git a/llvm/test/Transforms/InstCombine/icmp-select.ll b/llvm/test/Transforms/InstCombine/icmp-select.ll
index 59d2a1b165c0f8..80341278b58f3a 100644
--- a/llvm/test/Transforms/InstCombine/icmp-select.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-select.ll
@@ -628,3 +628,16 @@ define i1 @icmp_slt_select(i1 %cond, i32 %a, i32 %b) {
%res = icmp slt i32 %lhs, %rhs
ret i1 %res
}
+
+define i8 @icmp_slt_select_or(i8 %inl) {
+; CHECK-LABEL: @icmp_slt_select_or(
+; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], 3
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[INL]], -1
+; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 1, i8 [[OR]]
+; CHECK-NEXT: ret i8 [[S]]
+;
+ %or = or i8 %inl, 3
+ %cmp = icmp sgt i8 %inl, -1
+ %s = select i1 %cmp, i8 1, i8 %or
+ ret i8 %s
+}
>From bf96ccc14d711c5083dac748005d6ca846d01662 Mon Sep 17 00:00:00 2001
From: Krishna-13-cyber <krishnanarayanan132002 at gmail.com>
Date: Sat, 30 Mar 2024 20:26:46 +0530
Subject: [PATCH 2/4] Update test diffs
---
llvm/test/Transforms/InstCombine/icmp-select.ll | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/test/Transforms/InstCombine/icmp-select.ll b/llvm/test/Transforms/InstCombine/icmp-select.ll
index 80341278b58f3a..3c1a7adcc463f1 100644
--- a/llvm/test/Transforms/InstCombine/icmp-select.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-select.ll
@@ -632,8 +632,7 @@ define i1 @icmp_slt_select(i1 %cond, i32 %a, i32 %b) {
define i8 @icmp_slt_select_or(i8 %inl) {
; CHECK-LABEL: @icmp_slt_select_or(
; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], 3
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[INL]], -1
-; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 1, i8 [[OR]]
+; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[OR]], i8 1)
; CHECK-NEXT: ret i8 [[S]]
;
%or = or i8 %inl, 3
>From 54ab631c418f9d05e86999c9a593102d3fbd0488 Mon Sep 17 00:00:00 2001
From: Krishna-13-cyber <krishnanarayanan132002 at gmail.com>
Date: Wed, 3 Apr 2024 23:25:48 +0530
Subject: [PATCH 3/4] Update with test cases
---
.../InstCombine/InstCombineSelect.cpp | 33 ++++++--
.../Transforms/InstCombine/icmp-select.ll | 77 ++++++++++++++++++-
2 files changed, 100 insertions(+), 10 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 4e58ba5f01df1c..004d92eeea11c5 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -1689,21 +1689,40 @@ static Value *foldSelectInstWithICmpConst(SelectInst &SI, ICmpInst *ICI,
static Value *foldSelectInstWithICmpOr(SelectInst &SI, ICmpInst *ICI,
InstCombiner::BuilderTy &Builder) {
- /* a > -1 ? 1 : (a | 3) --> smin(1, a | 3) */
+
+ // a > -1 ? 1 : (a | value) --> smin(1, a | value)
+ // a >= 0 ? 1 : (a | value) --> smin(1, a | value)
+ const APInt *Cmp;
+ Value *A = ICI->getOperand(0);
+ Value *B = ICI->getOperand(1);
Type *Ty = SI.getType();
Value *TVal = SI.getTrueValue();
Value *FVal = SI.getFalseValue();
Constant *One = ConstantInt::get(Ty, 1);
+ Constant *NegOne = ConstantInt::get(Ty, -1);
+ Constant *Zero = Constant::getNullValue(Ty);
CmpInst::Predicate Pred = ICI->getPredicate();
- Value *A = ICI->getOperand(0);
- const APInt *Cmp;
- if (!match(TVal, m_One()) || !match(FVal, m_Or(m_Value(A), m_SpecificInt(3))))
+ if (!match(B, m_APIntAllowUndef(Cmp)))
+ return nullptr;
+
+ // Swap TVal, FVal for Inverse
+ if (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SLE)
+ std::swap(TVal, FVal);
+
+ if (!(match(TVal, m_One()) || match(TVal, m_Zero()) ||
+ match(TVal, m_AllOnes())) ||
+ !match(FVal, m_Or(m_Value(A), m_StrictlyPositive())))
return nullptr;
- if (Pred == ICmpInst::ICMP_SGT && *Cmp == -1 && match(TVal, m_One()) &&
- match(FVal, m_Or(m_Value(A), m_SpecificInt(3))))
- return Builder.CreateBinaryIntrinsic(Intrinsic::smin, One, FVal);
+ if (((Pred == ICmpInst::ICMP_SGT && *Cmp == -1) ||
+ (Pred == ICmpInst::ICMP_SGE && *Cmp == 0)))
+ if (match(TVal, m_One()))
+ return Builder.CreateBinaryIntrinsic(Intrinsic::smin, One, FVal);
+ if (match(TVal, m_Zero()))
+ return Builder.CreateBinaryIntrinsic(Intrinsic::smin, Zero, FVal);
+ if (match(TVal, m_AllOnes()))
+ return Builder.CreateBinaryIntrinsic(Intrinsic::smin, NegOne, FVal);
}
/// Visit a SelectInst that has an ICmpInst as its first operand.
diff --git a/llvm/test/Transforms/InstCombine/icmp-select.ll b/llvm/test/Transforms/InstCombine/icmp-select.ll
index 3c1a7adcc463f1..ec82418969c0da 100644
--- a/llvm/test/Transforms/InstCombine/icmp-select.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-select.ll
@@ -629,10 +629,10 @@ define i1 @icmp_slt_select(i1 %cond, i32 %a, i32 %b) {
ret i1 %res
}
-define i8 @icmp_slt_select_or(i8 %inl) {
-; CHECK-LABEL: @icmp_slt_select_or(
+define i8 @icmp_one_sgt_select_or(i8 %inl) {
+; CHECK-LABEL: @icmp_one_sgt_select_or(
; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], 3
-; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[OR]], i8 1)
+; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[OR]], i8 -1)
; CHECK-NEXT: ret i8 [[S]]
;
%or = or i8 %inl, 3
@@ -640,3 +640,74 @@ define i8 @icmp_slt_select_or(i8 %inl) {
%s = select i1 %cmp, i8 1, i8 %or
ret i8 %s
}
+
+define i8 @icmp_sge_select_or(i8 %inl) {
+; CHECK-LABEL: @icmp_sge_select_or(
+; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], 3
+; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[OR]], i8 -1)
+; CHECK-NEXT: ret i8 [[S]]
+;
+ %or = or i8 %inl, 3
+ %cmp = icmp sge i8 %inl, 0
+ %s = select i1 %cmp, i8 -1, i8 %or
+ ret i8 %s
+}
+
+define i8 @icmp_negone_sgt_select_or(i8 %inl) {
+; CHECK-LABEL: @icmp_negone_sgt_select_or(
+; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], 3
+; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[OR]], i8 -1)
+; CHECK-NEXT: ret i8 [[S]]
+;
+ %or = or i8 %inl, 3
+ %cmp = icmp sgt i8 %inl, -1
+ %s = select i1 %cmp, i8 -1, i8 %or
+ ret i8 %s
+}
+
+define i8 @icmp_zero_sgt_select_or(i8 %inl) {
+; CHECK-LABEL: @icmp_zero_sgt_select_or(
+; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], 34
+; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[OR]], i8 0)
+; CHECK-NEXT: ret i8 [[S]]
+;
+ %or = or i8 %inl, 34
+ %cmp = icmp sgt i8 %inl, -1
+ %s = select i1 %cmp, i8 0, i8 %or
+ ret i8 %s
+}
+
+define i8 @icmp_zero_sgt_select_or_2(i8 %inl) {
+; CHECK-LABEL: @icmp_zero_sgt_select_or_2(
+; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[INL:%.*]], i8 0)
+; CHECK-NEXT: ret i8 [[S]]
+;
+ %or = or i8 %inl, 0
+ %cmp = icmp sgt i8 %inl, -1
+ %s = select i1 %cmp, i8 0, i8 %or
+ ret i8 %s
+}
+
+define i8 @icmp_slt_select_or(i8 %inl) {
+; CHECK-LABEL: @icmp_slt_select_or(
+; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], 7
+; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[OR]], i8 -1)
+; CHECK-NEXT: ret i8 [[S]]
+;
+ %or = or i8 %inl, 7
+ %cmp = icmp slt i8 %inl, -1
+ %s = select i1 %cmp, i8 %or, i8 -1
+ ret i8 %s
+}
+
+define i8 @icmp_sle_select_or(i8 %inl) {
+; CHECK-LABEL: @icmp_sle_select_or(
+; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], 10
+; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[OR]], i8 -1)
+; CHECK-NEXT: ret i8 [[S]]
+;
+ %or = or i8 %inl, 10
+ %cmp = icmp sle i8 %inl, 0
+ %s = select i1 %cmp, i8 %or, i8 -1
+ ret i8 %s
+}
>From 9532982f7e8300e634e914ec316e3da24aa39a0b Mon Sep 17 00:00:00 2001
From: Krishna-13-cyber <krishnanarayanan132002 at gmail.com>
Date: Fri, 12 Apr 2024 22:50:51 +0530
Subject: [PATCH 4/4] Update with review and tests
---
.../InstCombine/InstCombineSelect.cpp | 35 +++----
.../Transforms/InstCombine/icmp-select.ll | 95 +++++++------------
2 files changed, 48 insertions(+), 82 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 004d92eeea11c5..755e44c3838e25 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -1689,40 +1689,35 @@ static Value *foldSelectInstWithICmpConst(SelectInst &SI, ICmpInst *ICI,
static Value *foldSelectInstWithICmpOr(SelectInst &SI, ICmpInst *ICI,
InstCombiner::BuilderTy &Builder) {
-
- // a > -1 ? 1 : (a | value) --> smin(1, a | value)
- // a >= 0 ? 1 : (a | value) --> smin(1, a | value)
+ // a > -1 ? 1 : ( a | (+ve)value) --> smin(1, a | (+ve)value)
+ // a < -1 ? ( a | (+ve)value) : 1 --> smin(1, a | (+ve)value)
+ Value *C;
const APInt *Cmp;
Value *A = ICI->getOperand(0);
Value *B = ICI->getOperand(1);
- Type *Ty = SI.getType();
Value *TVal = SI.getTrueValue();
Value *FVal = SI.getFalseValue();
- Constant *One = ConstantInt::get(Ty, 1);
- Constant *NegOne = ConstantInt::get(Ty, -1);
- Constant *Zero = Constant::getNullValue(Ty);
- CmpInst::Predicate Pred = ICI->getPredicate();
+ ICmpInst::Predicate Pred = ICI->getPredicate();
- if (!match(B, m_APIntAllowUndef(Cmp)))
+ if (!match(B, m_APInt(Cmp)))
return nullptr;
- // Swap TVal, FVal for Inverse
- if (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SLE)
+ if (Pred == ICmpInst::ICMP_SLT)
std::swap(TVal, FVal);
if (!(match(TVal, m_One()) || match(TVal, m_Zero()) ||
match(TVal, m_AllOnes())) ||
- !match(FVal, m_Or(m_Value(A), m_StrictlyPositive())))
+ !(match(FVal, m_Or(m_Value(A), m_Value(C)))))
+ return nullptr;
+
+ if (!match(C, m_StrictlyPositive()))
return nullptr;
- if (((Pred == ICmpInst::ICMP_SGT && *Cmp == -1) ||
- (Pred == ICmpInst::ICMP_SGE && *Cmp == 0)))
- if (match(TVal, m_One()))
- return Builder.CreateBinaryIntrinsic(Intrinsic::smin, One, FVal);
- if (match(TVal, m_Zero()))
- return Builder.CreateBinaryIntrinsic(Intrinsic::smin, Zero, FVal);
- if (match(TVal, m_AllOnes()))
- return Builder.CreateBinaryIntrinsic(Intrinsic::smin, NegOne, FVal);
+ if ((Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SGT))
+ if ((match(TVal, m_One()) || match(TVal, m_Zero()) ||
+ match(TVal, m_AllOnes())) &&
+ (Cmp->isAllOnes() || Cmp->isZero()))
+ return Builder.CreateBinaryIntrinsic(Intrinsic::smin, TVal, FVal);
}
/// Visit a SelectInst that has an ICmpInst as its first operand.
diff --git a/llvm/test/Transforms/InstCombine/icmp-select.ll b/llvm/test/Transforms/InstCombine/icmp-select.ll
index ec82418969c0da..a30868b53f7213 100644
--- a/llvm/test/Transforms/InstCombine/icmp-select.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-select.ll
@@ -629,85 +629,56 @@ define i1 @icmp_slt_select(i1 %cond, i32 %a, i32 %b) {
ret i1 %res
}
-define i8 @icmp_one_sgt_select_or(i8 %inl) {
-; CHECK-LABEL: @icmp_one_sgt_select_or(
-; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], 3
-; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[OR]], i8 -1)
+define i8 @icmp_pos_sgt_select_or(i8 %inl, i8 %y) {
+; CHECK-LABEL: @icmp_pos_sgt_select_or(
+; CHECK-NEXT: [[POS:%.*]] = icmp sgt i8 [[Y:%.*]], 0
+; CHECK-NEXT: call void @llvm.assume(i1 [[POS]])
+; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], [[Y]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[INL]], -1
+; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 1, i8 [[OR]]
; CHECK-NEXT: ret i8 [[S]]
;
- %or = or i8 %inl, 3
+ %pos = icmp sgt i8 %y, 0
+ call void @llvm.assume(i1 %pos)
+
+ %or = or i8 %inl, %y
%cmp = icmp sgt i8 %inl, -1
%s = select i1 %cmp, i8 1, i8 %or
ret i8 %s
}
-define i8 @icmp_sge_select_or(i8 %inl) {
-; CHECK-LABEL: @icmp_sge_select_or(
-; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], 3
-; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[OR]], i8 -1)
+define i8 @icmp_neg_sgt_select_or(i8 %inl, i8 %y) {
+; CHECK-LABEL: @icmp_neg_sgt_select_or(
+; CHECK-NEXT: [[NEG:%.*]] = icmp slt i8 [[Y:%.*]], 0
+; CHECK-NEXT: call void @llvm.assume(i1 [[NEG]])
+; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], [[Y]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[INL]], -1
+; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 1, i8 [[OR]]
; CHECK-NEXT: ret i8 [[S]]
;
- %or = or i8 %inl, 3
- %cmp = icmp sge i8 %inl, 0
- %s = select i1 %cmp, i8 -1, i8 %or
- ret i8 %s
-}
+ %neg = icmp slt i8 %y, 0
+ call void @llvm.assume(i1 %neg)
-define i8 @icmp_negone_sgt_select_or(i8 %inl) {
-; CHECK-LABEL: @icmp_negone_sgt_select_or(
-; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], 3
-; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[OR]], i8 -1)
-; CHECK-NEXT: ret i8 [[S]]
-;
- %or = or i8 %inl, 3
+ %or = or i8 %inl, %y
%cmp = icmp sgt i8 %inl, -1
- %s = select i1 %cmp, i8 -1, i8 %or
+ %s = select i1 %cmp, i8 1, i8 %or
ret i8 %s
}
-define i8 @icmp_zero_sgt_select_or(i8 %inl) {
-; CHECK-LABEL: @icmp_zero_sgt_select_or(
-; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], 34
-; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[OR]], i8 0)
+define i8 @icmp_nonneg_sgt_select_or(i8 %inl, i8 %y) {
+; CHECK-LABEL: @icmp_nonneg_sgt_select_or(
+; CHECK-NEXT: [[NNEG:%.*]] = icmp sgt i8 [[Y:%.*]], -1
+; CHECK-NEXT: call void @llvm.assume(i1 [[NNEG]])
+; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], [[Y]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[INL]], -1
+; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 1, i8 [[OR]]
; CHECK-NEXT: ret i8 [[S]]
;
- %or = or i8 %inl, 34
- %cmp = icmp sgt i8 %inl, -1
- %s = select i1 %cmp, i8 0, i8 %or
- ret i8 %s
-}
+ %nneg = icmp sgt i8 %y, -1
+ call void @llvm.assume(i1 %nneg)
-define i8 @icmp_zero_sgt_select_or_2(i8 %inl) {
-; CHECK-LABEL: @icmp_zero_sgt_select_or_2(
-; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[INL:%.*]], i8 0)
-; CHECK-NEXT: ret i8 [[S]]
-;
- %or = or i8 %inl, 0
+ %or = or i8 %inl, %y
%cmp = icmp sgt i8 %inl, -1
- %s = select i1 %cmp, i8 0, i8 %or
- ret i8 %s
-}
-
-define i8 @icmp_slt_select_or(i8 %inl) {
-; CHECK-LABEL: @icmp_slt_select_or(
-; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], 7
-; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[OR]], i8 -1)
-; CHECK-NEXT: ret i8 [[S]]
-;
- %or = or i8 %inl, 7
- %cmp = icmp slt i8 %inl, -1
- %s = select i1 %cmp, i8 %or, i8 -1
- ret i8 %s
-}
-
-define i8 @icmp_sle_select_or(i8 %inl) {
-; CHECK-LABEL: @icmp_sle_select_or(
-; CHECK-NEXT: [[OR:%.*]] = or i8 [[INL:%.*]], 10
-; CHECK-NEXT: [[S:%.*]] = call i8 @llvm.smin.i8(i8 [[OR]], i8 -1)
-; CHECK-NEXT: ret i8 [[S]]
-;
- %or = or i8 %inl, 10
- %cmp = icmp sle i8 %inl, 0
- %s = select i1 %cmp, i8 %or, i8 -1
+ %s = select i1 %cmp, i8 1, i8 %or
ret i8 %s
}
More information about the llvm-commits
mailing list