Skip to content

Commit b7ee463

Browse files
committed
Handle vector types
1 parent 1a85093 commit b7ee463

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3575,11 +3575,11 @@ Instruction *InstCombinerImpl::foldSelectToCmp(SelectInst &SI) {
35753575

35763576
// (x == y) ? 0 : (x > y ? 1 : -1)
35773577
ICmpInst::Predicate FalseBranchSelectPredicate;
3578-
ConstantInt *InnerTV, *InnerFV;
3578+
const APInt *InnerTV, *InnerFV;
35793579
if (Pred == ICmpInst::ICMP_EQ && match(TV, m_Zero()) &&
35803580
match(FV, m_Select(m_c_ICmp(FalseBranchSelectPredicate, m_Specific(LHS),
35813581
m_Specific(RHS)),
3582-
m_ConstantInt(InnerTV), m_ConstantInt(InnerFV)))) {
3582+
m_APInt(InnerTV), m_APInt(InnerFV)))) {
35833583
if (!ICmpInst::isGT(FalseBranchSelectPredicate)) {
35843584
FalseBranchSelectPredicate =
35853585
ICmpInst::getSwappedPredicate(FalseBranchSelectPredicate);
@@ -3592,7 +3592,7 @@ Instruction *InstCombinerImpl::foldSelectToCmp(SelectInst &SI) {
35923592
}
35933593

35943594
if (ICmpInst::isGT(FalseBranchSelectPredicate) && InnerTV->isOne() &&
3595-
InnerFV->isAllOnesValue()) {
3595+
InnerFV->isAllOnes()) {
35963596
IsSigned = ICmpInst::isSigned(FalseBranchSelectPredicate);
35973597
Replace = true;
35983598
}

llvm/test/Transforms/InstCombine/scmp.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,19 @@ define i8 @scmp_from_select_eq_and_gt(i32 %x, i32 %y) {
358358
ret i8 %r
359359
}
360360

361+
define <4 x i8> @scmp_from_select_eq_and_gt_vec(<4 x i32> %x, <4 x i32> %y) {
362+
; CHECK-LABEL: define <4 x i8> @scmp_from_select_eq_and_gt_vec(
363+
; CHECK-SAME: <4 x i32> [[X:%.*]], <4 x i32> [[Y:%.*]]) {
364+
; CHECK-NEXT: [[R:%.*]] = call <4 x i8> @llvm.scmp.v4i8.v4i32(<4 x i32> [[X]], <4 x i32> [[Y]])
365+
; CHECK-NEXT: ret <4 x i8> [[R]]
366+
;
367+
%eq = icmp eq <4 x i32> %x, %y
368+
%gt = icmp sgt <4 x i32> %x, %y
369+
%sel1 = select <4 x i1> %gt, <4 x i8> splat(i8 1), <4 x i8> splat(i8 -1)
370+
%r = select <4 x i1> %eq, <4 x i8> splat(i8 0), <4 x i8> %sel1
371+
ret <4 x i8> %r
372+
}
373+
361374
define i8 @scmp_from_select_eq_and_gt_commuted1(i32 %x, i32 %y) {
362375
; CHECK-LABEL: define i8 @scmp_from_select_eq_and_gt_commuted1(
363376
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {

0 commit comments

Comments
 (0)