range-check.ll
3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
; RUN: opt < %s -instcombine -S | FileCheck %s
; Check simplification of
; (icmp sgt x, -1) & (icmp sgt/sge n, x) --> icmp ugt/uge n, x
; CHECK-LABEL: define i1 @test_and1
; CHECK: [[R:%[0-9]+]] = icmp ugt i32 %nn, %x
; CHECK: ret i1 [[R]]
define i1 @test_and1(i32 %x, i32 %n) {
%nn = and i32 %n, 2147483647
%a = icmp sge i32 %x, 0
%b = icmp slt i32 %x, %nn
%c = and i1 %a, %b
ret i1 %c
}
; CHECK-LABEL: define i1 @test_and2
; CHECK: [[R:%[0-9]+]] = icmp uge i32 %nn, %x
; CHECK: ret i1 [[R]]
define i1 @test_and2(i32 %x, i32 %n) {
%nn = and i32 %n, 2147483647
%a = icmp sgt i32 %x, -1
%b = icmp sle i32 %x, %nn
%c = and i1 %a, %b
ret i1 %c
}
; CHECK-LABEL: define i1 @test_and3
; CHECK: [[R:%[0-9]+]] = icmp ugt i32 %nn, %x
; CHECK: ret i1 [[R]]
define i1 @test_and3(i32 %x, i32 %n) {
%nn = and i32 %n, 2147483647
%a = icmp sgt i32 %nn, %x
%b = icmp sge i32 %x, 0
%c = and i1 %a, %b
ret i1 %c
}
; CHECK-LABEL: define i1 @test_and4
; CHECK: [[R:%[0-9]+]] = icmp uge i32 %nn, %x
; CHECK: ret i1 [[R]]
define i1 @test_and4(i32 %x, i32 %n) {
%nn = and i32 %n, 2147483647
%a = icmp sge i32 %nn, %x
%b = icmp sge i32 %x, 0
%c = and i1 %a, %b
ret i1 %c
}
; CHECK-LABEL: define i1 @test_or1
; CHECK: [[R:%[0-9]+]] = icmp ule i32 %nn, %x
; CHECK: ret i1 [[R]]
define i1 @test_or1(i32 %x, i32 %n) {
%nn = and i32 %n, 2147483647
%a = icmp slt i32 %x, 0
%b = icmp sge i32 %x, %nn
%c = or i1 %a, %b
ret i1 %c
}
; CHECK-LABEL: define i1 @test_or2
; CHECK: [[R:%[0-9]+]] = icmp ult i32 %nn, %x
; CHECK: ret i1 [[R]]
define i1 @test_or2(i32 %x, i32 %n) {
%nn = and i32 %n, 2147483647
%a = icmp sle i32 %x, -1
%b = icmp sgt i32 %x, %nn
%c = or i1 %a, %b
ret i1 %c
}
; CHECK-LABEL: define i1 @test_or3
; CHECK: [[R:%[0-9]+]] = icmp ule i32 %nn, %x
; CHECK: ret i1 [[R]]
define i1 @test_or3(i32 %x, i32 %n) {
%nn = and i32 %n, 2147483647
%a = icmp sle i32 %nn, %x
%b = icmp slt i32 %x, 0
%c = or i1 %a, %b
ret i1 %c
}
; CHECK-LABEL: define i1 @test_or4
; CHECK: [[R:%[0-9]+]] = icmp ult i32 %nn, %x
; CHECK: ret i1 [[R]]
define i1 @test_or4(i32 %x, i32 %n) {
%nn = and i32 %n, 2147483647
%a = icmp slt i32 %nn, %x
%b = icmp slt i32 %x, 0
%c = or i1 %a, %b
ret i1 %c
}
; Negative tests
; CHECK-LABEL: define i1 @negative1
; CHECK: %a = icmp
; CHECK: %b = icmp
; CHECK: %c = and i1 %a, %b
; CHECK: ret i1 %c
define i1 @negative1(i32 %x, i32 %n) {
%nn = and i32 %n, 2147483647
%a = icmp slt i32 %x, %nn
%b = icmp sgt i32 %x, 0 ; should be: icmp sge
%c = and i1 %a, %b
ret i1 %c
}
; CHECK-LABEL: define i1 @negative2
; CHECK: %a = icmp
; CHECK: %b = icmp
; CHECK: %c = and i1 %a, %b
; CHECK: ret i1 %c
define i1 @negative2(i32 %x, i32 %n) {
%a = icmp slt i32 %x, %n ; n can be negative
%b = icmp sge i32 %x, 0
%c = and i1 %a, %b
ret i1 %c
}
; CHECK-LABEL: define i1 @negative3
; CHECK: %a = icmp
; CHECK: %b = icmp
; CHECK: %c = and i1 %a, %b
; CHECK: ret i1 %c
define i1 @negative3(i32 %x, i32 %y, i32 %n) {
%nn = and i32 %n, 2147483647
%a = icmp slt i32 %x, %nn
%b = icmp sge i32 %y, 0 ; should compare %x and not %y
%c = and i1 %a, %b
ret i1 %c
}
; CHECK-LABEL: define i1 @negative4
; CHECK: %a = icmp
; CHECK: %b = icmp
; CHECK: %c = and i1 %a, %b
; CHECK: ret i1 %c
define i1 @negative4(i32 %x, i32 %n) {
%nn = and i32 %n, 2147483647
%a = icmp ne i32 %x, %nn ; should be: icmp slt/sle
%b = icmp sge i32 %x, 0
%c = and i1 %a, %b
ret i1 %c
}
; CHECK-LABEL: define i1 @negative5
; CHECK: %a = icmp
; CHECK: %b = icmp
; CHECK: %c = or i1 %a, %b
; CHECK: ret i1 %c
define i1 @negative5(i32 %x, i32 %n) {
%nn = and i32 %n, 2147483647
%a = icmp slt i32 %x, %nn
%b = icmp sge i32 %x, 0
%c = or i1 %a, %b ; should be: and
ret i1 %c
}