1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=instcombine < %s | FileCheck %s
4 @g = external global i32
6 define i1 @smin(i32 %other) {
8 ; CHECK-NEXT: [[TEST:%.*]] = icmp sgt i32 [[OTHER:%.*]], 0
9 ; CHECK-NEXT: ret i1 [[TEST]]
11 %positive = load i32, ptr @g, !range !{i32 1, i32 2048}
12 %cmp = icmp slt i32 %positive, %other
13 %sel = select i1 %cmp, i32 %positive, i32 %other
14 %test = icmp sgt i32 %sel, 0
18 define i1 @smin_int(i32 %other) {
19 ; CHECK-LABEL: @smin_int(
20 ; CHECK-NEXT: [[TEST:%.*]] = icmp sgt i32 [[OTHER:%.*]], 0
21 ; CHECK-NEXT: ret i1 [[TEST]]
23 %positive = load i32, ptr @g, !range !{i32 1, i32 2048}
24 %smin = call i32 @llvm.smin.i32(i32 %positive, i32 %other)
25 %test = icmp sgt i32 %smin, 0
28 declare i32 @llvm.smin.i32(i32, i32)
30 ; Range metadata doesn't work for vectors, so find another way to trigger isKnownPositive().
32 define <2 x i1> @smin_vec(<2 x i32> %x, <2 x i32> %other) {
33 ; CHECK-LABEL: @smin_vec(
34 ; CHECK-NEXT: [[TEST:%.*]] = icmp sgt <2 x i32> [[OTHER:%.*]], zeroinitializer
35 ; CHECK-NEXT: ret <2 x i1> [[TEST]]
37 %notneg = and <2 x i32> %x, <i32 7, i32 7>
38 %positive = or <2 x i32> %notneg, <i32 1, i32 1>
39 %cmp = icmp slt <2 x i32> %positive, %other
40 %sel = select <2 x i1> %cmp, <2 x i32> %positive, <2 x i32> %other
41 %test = icmp sgt <2 x i32> %sel, zeroinitializer
45 define i1 @smin_commute(i32 %other) {
46 ; CHECK-LABEL: @smin_commute(
47 ; CHECK-NEXT: [[TEST:%.*]] = icmp sgt i32 [[OTHER:%.*]], 0
48 ; CHECK-NEXT: ret i1 [[TEST]]
50 %positive = load i32, ptr @g, !range !{i32 1, i32 2048}
51 %cmp = icmp slt i32 %other, %positive
52 %sel = select i1 %cmp, i32 %other, i32 %positive
53 %test = icmp sgt i32 %sel, 0
57 define <2 x i1> @smin_commute_vec(<2 x i32> %x, <2 x i32> %other) {
58 ; CHECK-LABEL: @smin_commute_vec(
59 ; CHECK-NEXT: [[TEST:%.*]] = icmp sgt <2 x i32> [[OTHER:%.*]], zeroinitializer
60 ; CHECK-NEXT: ret <2 x i1> [[TEST]]
62 %notneg = and <2 x i32> %x, <i32 7, i32 7>
63 %positive = or <2 x i32> %notneg, <i32 1, i32 1>
64 %cmp = icmp slt <2 x i32> %other, %positive
65 %sel = select <2 x i1> %cmp, <2 x i32> %other, <2 x i32> %positive
66 %test = icmp sgt <2 x i32> %sel, zeroinitializer
70 define <2 x i1> @smin_commute_vec_poison_elts(<2 x i32> %x, <2 x i32> %other) {
71 ; CHECK-LABEL: @smin_commute_vec_poison_elts(
72 ; CHECK-NEXT: [[TEST:%.*]] = icmp sgt <2 x i32> [[OTHER:%.*]], <i32 0, i32 poison>
73 ; CHECK-NEXT: ret <2 x i1> [[TEST]]
75 %notneg = and <2 x i32> %x, <i32 7, i32 7>
76 %positive = or <2 x i32> %notneg, <i32 1, i32 1>
77 %cmp = icmp slt <2 x i32> %other, %positive
78 %sel = select <2 x i1> %cmp, <2 x i32> %other, <2 x i32> %positive
79 %test = icmp sgt <2 x i32> %sel, <i32 0, i32 poison>
82 ; %positive might be zero
84 define i1 @maybe_not_positive(i32 %other) {
85 ; CHECK-LABEL: @maybe_not_positive(
86 ; CHECK-NEXT: [[POSITIVE:%.*]] = load i32, ptr @g, align 4, !range [[RNG0:![0-9]+]]
87 ; CHECK-NEXT: [[SEL:%.*]] = call i32 @llvm.smin.i32(i32 [[POSITIVE]], i32 [[OTHER:%.*]])
88 ; CHECK-NEXT: [[TEST:%.*]] = icmp sgt i32 [[SEL]], 0
89 ; CHECK-NEXT: ret i1 [[TEST]]
91 %positive = load i32, ptr @g, !range !{i32 0, i32 2048}
92 %cmp = icmp slt i32 %positive, %other
93 %sel = select i1 %cmp, i32 %positive, i32 %other
94 %test = icmp sgt i32 %sel, 0
98 define <2 x i1> @maybe_not_positive_vec(<2 x i32> %x, <2 x i32> %other) {
99 ; CHECK-LABEL: @maybe_not_positive_vec(
100 ; CHECK-NEXT: [[NOTNEG:%.*]] = and <2 x i32> [[X:%.*]], splat (i32 7)
101 ; CHECK-NEXT: [[SEL:%.*]] = call <2 x i32> @llvm.smin.v2i32(<2 x i32> [[NOTNEG]], <2 x i32> [[OTHER:%.*]])
102 ; CHECK-NEXT: [[TEST:%.*]] = icmp sgt <2 x i32> [[SEL]], zeroinitializer
103 ; CHECK-NEXT: ret <2 x i1> [[TEST]]
105 %notneg = and <2 x i32> %x, <i32 7, i32 7>
106 %cmp = icmp slt <2 x i32> %notneg, %other
107 %sel = select <2 x i1> %cmp, <2 x i32> %notneg, <2 x i32> %other
108 %test = icmp sgt <2 x i32> %sel, zeroinitializer