2016-09-15 23:48:53 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
2016-03-10 05:05:07 +08:00
|
|
|
; RUN: opt -S -instcombine < %s | FileCheck %s
|
|
|
|
|
|
|
|
@g = external global i32
|
|
|
|
|
2016-09-16 00:13:41 +08:00
|
|
|
define i1 @smin(i32 %other) {
|
|
|
|
; CHECK-LABEL: @smin(
|
2018-04-22 22:19:37 +08:00
|
|
|
; CHECK-NEXT: [[TEST:%.*]] = icmp sgt i32 [[OTHER:%.*]], 0
|
2016-09-15 23:48:53 +08:00
|
|
|
; CHECK-NEXT: ret i1 [[TEST]]
|
|
|
|
;
|
2016-03-10 05:05:07 +08:00
|
|
|
%positive = load i32, i32* @g, !range !{i32 1, i32 2048}
|
|
|
|
%cmp = icmp slt i32 %positive, %other
|
|
|
|
%sel = select i1 %cmp, i32 %positive, i32 %other
|
|
|
|
%test = icmp sgt i32 %sel, 0
|
|
|
|
ret i1 %test
|
|
|
|
}
|
|
|
|
|
2016-09-16 00:13:41 +08:00
|
|
|
; Range metadata doesn't work for vectors, so find another way to trigger isKnownPositive().
|
|
|
|
|
|
|
|
define <2 x i1> @smin_vec(<2 x i32> %x, <2 x i32> %other) {
|
|
|
|
; CHECK-LABEL: @smin_vec(
|
2018-04-22 22:19:37 +08:00
|
|
|
; CHECK-NEXT: [[TEST:%.*]] = icmp sgt <2 x i32> [[OTHER:%.*]], zeroinitializer
|
2016-09-16 00:13:41 +08:00
|
|
|
; CHECK-NEXT: ret <2 x i1> [[TEST]]
|
|
|
|
;
|
|
|
|
%notneg = and <2 x i32> %x, <i32 7, i32 7>
|
|
|
|
%positive = or <2 x i32> %notneg, <i32 1, i32 1>
|
|
|
|
%cmp = icmp slt <2 x i32> %positive, %other
|
|
|
|
%sel = select <2 x i1> %cmp, <2 x i32> %positive, <2 x i32> %other
|
|
|
|
%test = icmp sgt <2 x i32> %sel, zeroinitializer
|
|
|
|
ret <2 x i1> %test
|
|
|
|
}
|
|
|
|
|
|
|
|
define i1 @smin_commute(i32 %other) {
|
|
|
|
; CHECK-LABEL: @smin_commute(
|
2018-04-22 22:19:37 +08:00
|
|
|
; CHECK-NEXT: [[TEST:%.*]] = icmp sgt i32 [[OTHER:%.*]], 0
|
2016-09-15 23:48:53 +08:00
|
|
|
; CHECK-NEXT: ret i1 [[TEST]]
|
|
|
|
;
|
2016-03-10 05:05:07 +08:00
|
|
|
%positive = load i32, i32* @g, !range !{i32 1, i32 2048}
|
|
|
|
%cmp = icmp slt i32 %other, %positive
|
|
|
|
%sel = select i1 %cmp, i32 %other, i32 %positive
|
|
|
|
%test = icmp sgt i32 %sel, 0
|
|
|
|
ret i1 %test
|
|
|
|
}
|
|
|
|
|
2016-09-16 00:13:41 +08:00
|
|
|
define <2 x i1> @smin_commute_vec(<2 x i32> %x, <2 x i32> %other) {
|
|
|
|
; CHECK-LABEL: @smin_commute_vec(
|
2018-04-22 22:19:37 +08:00
|
|
|
; CHECK-NEXT: [[TEST:%.*]] = icmp sgt <2 x i32> [[OTHER:%.*]], zeroinitializer
|
2016-09-16 00:13:41 +08:00
|
|
|
; CHECK-NEXT: ret <2 x i1> [[TEST]]
|
|
|
|
;
|
|
|
|
%notneg = and <2 x i32> %x, <i32 7, i32 7>
|
|
|
|
%positive = or <2 x i32> %notneg, <i32 1, i32 1>
|
2016-09-16 00:23:20 +08:00
|
|
|
%cmp = icmp slt <2 x i32> %other, %positive
|
2016-09-16 00:13:41 +08:00
|
|
|
%sel = select <2 x i1> %cmp, <2 x i32> %other, <2 x i32> %positive
|
|
|
|
%test = icmp sgt <2 x i32> %sel, zeroinitializer
|
|
|
|
ret <2 x i1> %test
|
|
|
|
}
|
|
|
|
|
2018-04-22 22:19:37 +08:00
|
|
|
define <2 x i1> @smin_commute_vec_undef_elts(<2 x i32> %x, <2 x i32> %other) {
|
|
|
|
; CHECK-LABEL: @smin_commute_vec_undef_elts(
|
2018-04-23 01:07:44 +08:00
|
|
|
; CHECK-NEXT: [[TEST:%.*]] = icmp sgt <2 x i32> [[OTHER:%.*]], <i32 0, i32 undef>
|
2018-04-22 22:19:37 +08:00
|
|
|
; CHECK-NEXT: ret <2 x i1> [[TEST]]
|
|
|
|
;
|
|
|
|
%notneg = and <2 x i32> %x, <i32 7, i32 7>
|
|
|
|
%positive = or <2 x i32> %notneg, <i32 1, i32 1>
|
|
|
|
%cmp = icmp slt <2 x i32> %other, %positive
|
|
|
|
%sel = select <2 x i1> %cmp, <2 x i32> %other, <2 x i32> %positive
|
|
|
|
%test = icmp sgt <2 x i32> %sel, <i32 0, i32 undef>
|
|
|
|
ret <2 x i1> %test
|
|
|
|
}
|
2016-03-10 05:05:07 +08:00
|
|
|
; %positive might be zero
|
2016-09-16 00:13:41 +08:00
|
|
|
|
|
|
|
define i1 @maybe_not_positive(i32 %other) {
|
|
|
|
; CHECK-LABEL: @maybe_not_positive(
|
2016-09-15 23:48:53 +08:00
|
|
|
; CHECK-NEXT: [[POSITIVE:%.*]] = load i32, i32* @g, align 4, !range !0
|
2018-04-22 22:19:37 +08:00
|
|
|
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[POSITIVE]], [[OTHER:%.*]]
|
|
|
|
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[POSITIVE]], i32 [[OTHER]]
|
2016-09-15 23:48:53 +08:00
|
|
|
; CHECK-NEXT: [[TEST:%.*]] = icmp sgt i32 [[SEL]], 0
|
|
|
|
; CHECK-NEXT: ret i1 [[TEST]]
|
|
|
|
;
|
2016-03-10 05:05:07 +08:00
|
|
|
%positive = load i32, i32* @g, !range !{i32 0, i32 2048}
|
|
|
|
%cmp = icmp slt i32 %positive, %other
|
|
|
|
%sel = select i1 %cmp, i32 %positive, i32 %other
|
|
|
|
%test = icmp sgt i32 %sel, 0
|
|
|
|
ret i1 %test
|
|
|
|
}
|
2016-09-16 00:13:41 +08:00
|
|
|
|
|
|
|
define <2 x i1> @maybe_not_positive_vec(<2 x i32> %x, <2 x i32> %other) {
|
|
|
|
; CHECK-LABEL: @maybe_not_positive_vec(
|
2018-04-22 22:19:37 +08:00
|
|
|
; CHECK-NEXT: [[NOTNEG:%.*]] = and <2 x i32> [[X:%.*]], <i32 7, i32 7>
|
|
|
|
; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[NOTNEG]], [[OTHER:%.*]]
|
|
|
|
; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[NOTNEG]], <2 x i32> [[OTHER]]
|
2016-09-16 00:13:41 +08:00
|
|
|
; CHECK-NEXT: [[TEST:%.*]] = icmp sgt <2 x i32> [[SEL]], zeroinitializer
|
|
|
|
; CHECK-NEXT: ret <2 x i1> [[TEST]]
|
|
|
|
;
|
|
|
|
%notneg = and <2 x i32> %x, <i32 7, i32 7>
|
|
|
|
%cmp = icmp slt <2 x i32> %notneg, %other
|
|
|
|
%sel = select <2 x i1> %cmp, <2 x i32> %notneg, <2 x i32> %other
|
|
|
|
%test = icmp sgt <2 x i32> %sel, zeroinitializer
|
|
|
|
ret <2 x i1> %test
|
|
|
|
}
|
|
|
|
|