• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -S -instcombine < %s | FileCheck %s
3
4@g = external global i32
5
6define i1 @smin(i32 %other) {
7; CHECK-LABEL: @smin(
8; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt i32 [[OTHER:%.*]], 0
9; CHECK-NEXT:    ret i1 [[TEST]]
10;
11  %positive = load i32, i32* @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
15  ret i1 %test
16}
17
18; Range metadata doesn't work for vectors, so find another way to trigger isKnownPositive().
19
20define <2 x i1> @smin_vec(<2 x i32> %x, <2 x i32> %other) {
21; CHECK-LABEL: @smin_vec(
22; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt <2 x i32> [[OTHER:%.*]], zeroinitializer
23; CHECK-NEXT:    ret <2 x i1> [[TEST]]
24;
25  %notneg = and <2 x i32> %x, <i32 7, i32 7>
26  %positive = or <2 x i32> %notneg, <i32 1, i32 1>
27  %cmp = icmp slt <2 x i32> %positive, %other
28  %sel = select <2 x i1> %cmp, <2 x i32> %positive, <2 x i32> %other
29  %test = icmp sgt <2 x i32> %sel, zeroinitializer
30  ret <2 x i1> %test
31}
32
33define i1 @smin_commute(i32 %other) {
34; CHECK-LABEL: @smin_commute(
35; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt i32 [[OTHER:%.*]], 0
36; CHECK-NEXT:    ret i1 [[TEST]]
37;
38  %positive = load i32, i32* @g, !range !{i32 1, i32 2048}
39  %cmp = icmp slt i32 %other, %positive
40  %sel = select i1 %cmp, i32 %other, i32 %positive
41  %test = icmp sgt i32 %sel, 0
42  ret i1 %test
43}
44
45define <2 x i1> @smin_commute_vec(<2 x i32> %x, <2 x i32> %other) {
46; CHECK-LABEL: @smin_commute_vec(
47; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt <2 x i32> [[OTHER:%.*]], zeroinitializer
48; CHECK-NEXT:    ret <2 x i1> [[TEST]]
49;
50  %notneg = and <2 x i32> %x, <i32 7, i32 7>
51  %positive = or <2 x i32> %notneg, <i32 1, i32 1>
52  %cmp = icmp slt <2 x i32> %other, %positive
53  %sel = select <2 x i1> %cmp, <2 x i32> %other, <2 x i32> %positive
54  %test = icmp sgt <2 x i32> %sel, zeroinitializer
55  ret <2 x i1> %test
56}
57
58define <2 x i1> @smin_commute_vec_undef_elts(<2 x i32> %x, <2 x i32> %other) {
59; CHECK-LABEL: @smin_commute_vec_undef_elts(
60; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt <2 x i32> [[OTHER:%.*]], <i32 0, i32 undef>
61; CHECK-NEXT:    ret <2 x i1> [[TEST]]
62;
63  %notneg = and <2 x i32> %x, <i32 7, i32 7>
64  %positive = or <2 x i32> %notneg, <i32 1, i32 1>
65  %cmp = icmp slt <2 x i32> %other, %positive
66  %sel = select <2 x i1> %cmp, <2 x i32> %other, <2 x i32> %positive
67  %test = icmp sgt <2 x i32> %sel, <i32 0, i32 undef>
68  ret <2 x i1> %test
69}
70; %positive might be zero
71
72define i1 @maybe_not_positive(i32 %other) {
73; CHECK-LABEL: @maybe_not_positive(
74; CHECK-NEXT:    [[POSITIVE:%.*]] = load i32, i32* @g, align 4, !range !0
75; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[POSITIVE]], [[OTHER:%.*]]
76; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i32 [[POSITIVE]], i32 [[OTHER]]
77; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt i32 [[SEL]], 0
78; CHECK-NEXT:    ret i1 [[TEST]]
79;
80  %positive = load i32, i32* @g, !range !{i32 0, i32 2048}
81  %cmp = icmp slt i32 %positive, %other
82  %sel = select i1 %cmp, i32 %positive, i32 %other
83  %test = icmp sgt i32 %sel, 0
84  ret i1 %test
85}
86
87define <2 x i1> @maybe_not_positive_vec(<2 x i32> %x, <2 x i32> %other) {
88; CHECK-LABEL: @maybe_not_positive_vec(
89; CHECK-NEXT:    [[NOTNEG:%.*]] = and <2 x i32> [[X:%.*]], <i32 7, i32 7>
90; CHECK-NEXT:    [[CMP:%.*]] = icmp slt <2 x i32> [[NOTNEG]], [[OTHER:%.*]]
91; CHECK-NEXT:    [[SEL:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[NOTNEG]], <2 x i32> [[OTHER]]
92; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt <2 x i32> [[SEL]], zeroinitializer
93; CHECK-NEXT:    ret <2 x i1> [[TEST]]
94;
95  %notneg = and <2 x i32> %x, <i32 7, i32 7>
96  %cmp = icmp slt <2 x i32> %notneg, %other
97  %sel = select <2 x i1> %cmp, <2 x i32> %notneg, <2 x i32> %other
98  %test = icmp sgt <2 x i32> %sel, zeroinitializer
99  ret <2 x i1> %test
100}
101
102