sat-to-bitop.ll
9.05 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=arm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM
; RUN: llc -mtriple=thumb-eabi %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-T
; RUN: llc -mtriple=thumb-eabi -mcpu=arm1156t2-s -mattr=+thumb2 %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-T2
; Check for clipping against 0 that should result in bic
;
; Base tests with different bit widths
; x < 0 ? 0 : x
; 32-bit base test
define i32 @sat0_base_32bit(i32 %x) #0 {
; CHECK-ARM-LABEL: sat0_base_32bit:
; CHECK-ARM: @ %bb.0: @ %entry
; CHECK-ARM-NEXT: bic r0, r0, r0, asr #31
; CHECK-ARM-NEXT: mov pc, lr
;
; CHECK-T-LABEL: sat0_base_32bit:
; CHECK-T: @ %bb.0: @ %entry
; CHECK-T-NEXT: asrs r1, r0, #31
; CHECK-T-NEXT: bics r0, r1
; CHECK-T-NEXT: bx lr
;
; CHECK-T2-LABEL: sat0_base_32bit:
; CHECK-T2: @ %bb.0: @ %entry
; CHECK-T2-NEXT: bic.w r0, r0, r0, asr #31
; CHECK-T2-NEXT: bx lr
entry:
%cmpLow = icmp slt i32 %x, 0
%saturateLow = select i1 %cmpLow, i32 0, i32 %x
ret i32 %saturateLow
}
; x < 0 ? 0 : x
; 16-bit base test
define i16 @sat0_base_16bit(i16 %x) #0 {
; CHECK-ARM-LABEL: sat0_base_16bit:
; CHECK-ARM: @ %bb.0: @ %entry
; CHECK-ARM-NEXT: lsl r1, r0, #16
; CHECK-ARM-NEXT: asr r1, r1, #16
; CHECK-ARM-NEXT: cmp r1, #0
; CHECK-ARM-NEXT: movmi r0, #0
; CHECK-ARM-NEXT: mov pc, lr
;
; CHECK-T-LABEL: sat0_base_16bit:
; CHECK-T: @ %bb.0: @ %entry
; CHECK-T-NEXT: lsls r1, r0, #16
; CHECK-T-NEXT: asrs r1, r1, #16
; CHECK-T-NEXT: bpl .LBB1_2
; CHECK-T-NEXT: @ %bb.1:
; CHECK-T-NEXT: movs r0, #0
; CHECK-T-NEXT: .LBB1_2: @ %entry
; CHECK-T-NEXT: bx lr
;
; CHECK-T2-LABEL: sat0_base_16bit:
; CHECK-T2: @ %bb.0: @ %entry
; CHECK-T2-NEXT: sxth r1, r0
; CHECK-T2-NEXT: cmp r1, #0
; CHECK-T2-NEXT: it mi
; CHECK-T2-NEXT: movmi r0, #0
; CHECK-T2-NEXT: bx lr
entry:
%cmpLow = icmp slt i16 %x, 0
%saturateLow = select i1 %cmpLow, i16 0, i16 %x
ret i16 %saturateLow
}
; x < 0 ? 0 : x
; 8-bit base test
define i8 @sat0_base_8bit(i8 %x) #0 {
; CHECK-ARM-LABEL: sat0_base_8bit:
; CHECK-ARM: @ %bb.0: @ %entry
; CHECK-ARM-NEXT: lsl r1, r0, #24
; CHECK-ARM-NEXT: asr r1, r1, #24
; CHECK-ARM-NEXT: cmp r1, #0
; CHECK-ARM-NEXT: movmi r0, #0
; CHECK-ARM-NEXT: mov pc, lr
;
; CHECK-T-LABEL: sat0_base_8bit:
; CHECK-T: @ %bb.0: @ %entry
; CHECK-T-NEXT: lsls r1, r0, #24
; CHECK-T-NEXT: asrs r1, r1, #24
; CHECK-T-NEXT: bpl .LBB2_2
; CHECK-T-NEXT: @ %bb.1:
; CHECK-T-NEXT: movs r0, #0
; CHECK-T-NEXT: .LBB2_2: @ %entry
; CHECK-T-NEXT: bx lr
;
; CHECK-T2-LABEL: sat0_base_8bit:
; CHECK-T2: @ %bb.0: @ %entry
; CHECK-T2-NEXT: sxtb r1, r0
; CHECK-T2-NEXT: cmp r1, #0
; CHECK-T2-NEXT: it mi
; CHECK-T2-NEXT: movmi r0, #0
; CHECK-T2-NEXT: bx lr
entry:
%cmpLow = icmp slt i8 %x, 0
%saturateLow = select i1 %cmpLow, i8 0, i8 %x
ret i8 %saturateLow
}
; Test where the conditional is formed in a different way
; x > 0 ? x : 0
define i32 @sat0_lower_1(i32 %x) #0 {
; CHECK-ARM-LABEL: sat0_lower_1:
; CHECK-ARM: @ %bb.0: @ %entry
; CHECK-ARM-NEXT: bic r0, r0, r0, asr #31
; CHECK-ARM-NEXT: mov pc, lr
;
; CHECK-T-LABEL: sat0_lower_1:
; CHECK-T: @ %bb.0: @ %entry
; CHECK-T-NEXT: asrs r1, r0, #31
; CHECK-T-NEXT: bics r0, r1
; CHECK-T-NEXT: bx lr
;
; CHECK-T2-LABEL: sat0_lower_1:
; CHECK-T2: @ %bb.0: @ %entry
; CHECK-T2-NEXT: bic.w r0, r0, r0, asr #31
; CHECK-T2-NEXT: bx lr
entry:
%cmpGt = icmp sgt i32 %x, 0
%saturateLow = select i1 %cmpGt, i32 %x, i32 0
ret i32 %saturateLow
}
; Check for clipping against -1 that should result in orr
;
; Base tests with different bit widths
;
; x < -1 ? -1 : x
; 32-bit base test
define i32 @sat1_base_32bit(i32 %x) #0 {
; CHECK-ARM-LABEL: sat1_base_32bit:
; CHECK-ARM: @ %bb.0: @ %entry
; CHECK-ARM-NEXT: orr r0, r0, r0, asr #31
; CHECK-ARM-NEXT: mov pc, lr
;
; CHECK-T-LABEL: sat1_base_32bit:
; CHECK-T: @ %bb.0: @ %entry
; CHECK-T-NEXT: asrs r1, r0, #31
; CHECK-T-NEXT: orrs r0, r1
; CHECK-T-NEXT: bx lr
;
; CHECK-T2-LABEL: sat1_base_32bit:
; CHECK-T2: @ %bb.0: @ %entry
; CHECK-T2-NEXT: orr.w r0, r0, r0, asr #31
; CHECK-T2-NEXT: bx lr
entry:
%cmpLow = icmp slt i32 %x, -1
%saturateLow = select i1 %cmpLow, i32 -1, i32 %x
ret i32 %saturateLow
}
; x < -1 ? -1 : x
; 16-bit base test
define i16 @sat1_base_16bit(i16 %x) #0 {
; CHECK-ARM-LABEL: sat1_base_16bit:
; CHECK-ARM: @ %bb.0: @ %entry
; CHECK-ARM-NEXT: lsl r1, r0, #16
; CHECK-ARM-NEXT: asr r1, r1, #16
; CHECK-ARM-NEXT: cmn r1, #1
; CHECK-ARM-NEXT: mvnlt r0, #0
; CHECK-ARM-NEXT: mov pc, lr
;
; CHECK-T-LABEL: sat1_base_16bit:
; CHECK-T: @ %bb.0: @ %entry
; CHECK-T-NEXT: movs r1, #0
; CHECK-T-NEXT: mvns r1, r1
; CHECK-T-NEXT: lsls r2, r0, #16
; CHECK-T-NEXT: asrs r2, r2, #16
; CHECK-T-NEXT: cmp r2, r1
; CHECK-T-NEXT: blt .LBB5_2
; CHECK-T-NEXT: @ %bb.1: @ %entry
; CHECK-T-NEXT: movs r1, r0
; CHECK-T-NEXT: .LBB5_2: @ %entry
; CHECK-T-NEXT: movs r0, r1
; CHECK-T-NEXT: bx lr
;
; CHECK-T2-LABEL: sat1_base_16bit:
; CHECK-T2: @ %bb.0: @ %entry
; CHECK-T2-NEXT: sxth r1, r0
; CHECK-T2-NEXT: cmp.w r1, #-1
; CHECK-T2-NEXT: it lt
; CHECK-T2-NEXT: movlt.w r0, #-1
; CHECK-T2-NEXT: bx lr
entry:
%cmpLow = icmp slt i16 %x, -1
%saturateLow = select i1 %cmpLow, i16 -1, i16 %x
ret i16 %saturateLow
}
; x < -1 ? -1 : x
; 8-bit base test
define i8 @sat1_base_8bit(i8 %x) #0 {
; CHECK-ARM-LABEL: sat1_base_8bit:
; CHECK-ARM: @ %bb.0: @ %entry
; CHECK-ARM-NEXT: lsl r1, r0, #24
; CHECK-ARM-NEXT: asr r1, r1, #24
; CHECK-ARM-NEXT: cmn r1, #1
; CHECK-ARM-NEXT: mvnlt r0, #0
; CHECK-ARM-NEXT: mov pc, lr
;
; CHECK-T-LABEL: sat1_base_8bit:
; CHECK-T: @ %bb.0: @ %entry
; CHECK-T-NEXT: movs r1, #0
; CHECK-T-NEXT: mvns r1, r1
; CHECK-T-NEXT: lsls r2, r0, #24
; CHECK-T-NEXT: asrs r2, r2, #24
; CHECK-T-NEXT: cmp r2, r1
; CHECK-T-NEXT: blt .LBB6_2
; CHECK-T-NEXT: @ %bb.1: @ %entry
; CHECK-T-NEXT: movs r1, r0
; CHECK-T-NEXT: .LBB6_2: @ %entry
; CHECK-T-NEXT: movs r0, r1
; CHECK-T-NEXT: bx lr
;
; CHECK-T2-LABEL: sat1_base_8bit:
; CHECK-T2: @ %bb.0: @ %entry
; CHECK-T2-NEXT: sxtb r1, r0
; CHECK-T2-NEXT: cmp.w r1, #-1
; CHECK-T2-NEXT: it lt
; CHECK-T2-NEXT: movlt.w r0, #-1
; CHECK-T2-NEXT: bx lr
entry:
%cmpLow = icmp slt i8 %x, -1
%saturateLow = select i1 %cmpLow, i8 -1, i8 %x
ret i8 %saturateLow
}
; Test where the conditional is formed in a different way
; x > -1 ? x : -1
define i32 @sat1_lower_1(i32 %x) #0 {
; CHECK-ARM-LABEL: sat1_lower_1:
; CHECK-ARM: @ %bb.0: @ %entry
; CHECK-ARM-NEXT: orr r0, r0, r0, asr #31
; CHECK-ARM-NEXT: mov pc, lr
;
; CHECK-T-LABEL: sat1_lower_1:
; CHECK-T: @ %bb.0: @ %entry
; CHECK-T-NEXT: asrs r1, r0, #31
; CHECK-T-NEXT: orrs r0, r1
; CHECK-T-NEXT: bx lr
;
; CHECK-T2-LABEL: sat1_lower_1:
; CHECK-T2: @ %bb.0: @ %entry
; CHECK-T2-NEXT: orr.w r0, r0, r0, asr #31
; CHECK-T2-NEXT: bx lr
entry:
%cmpGt = icmp sgt i32 %x, -1
%saturateLow = select i1 %cmpGt, i32 %x, i32 -1
ret i32 %saturateLow
}
; The following tests for patterns that should not transform into bitops
; but that are similar enough that could confuse the selector.
; x < 0 ? 0 : y where x and y does not properly match
define i32 @no_sat0_incorrect_variable(i32 %x, i32 %y) #0 {
; CHECK-ARM-LABEL: no_sat0_incorrect_variable:
; CHECK-ARM: @ %bb.0: @ %entry
; CHECK-ARM-NEXT: cmp r0, #0
; CHECK-ARM-NEXT: movmi r1, #0
; CHECK-ARM-NEXT: mov r0, r1
; CHECK-ARM-NEXT: mov pc, lr
;
; CHECK-T-LABEL: no_sat0_incorrect_variable:
; CHECK-T: @ %bb.0: @ %entry
; CHECK-T-NEXT: cmp r0, #0
; CHECK-T-NEXT: bpl .LBB8_2
; CHECK-T-NEXT: @ %bb.1:
; CHECK-T-NEXT: movs r1, #0
; CHECK-T-NEXT: .LBB8_2: @ %entry
; CHECK-T-NEXT: movs r0, r1
; CHECK-T-NEXT: bx lr
;
; CHECK-T2-LABEL: no_sat0_incorrect_variable:
; CHECK-T2: @ %bb.0: @ %entry
; CHECK-T2-NEXT: cmp r0, #0
; CHECK-T2-NEXT: it mi
; CHECK-T2-NEXT: movmi r1, #0
; CHECK-T2-NEXT: mov r0, r1
; CHECK-T2-NEXT: bx lr
entry:
%cmpLow = icmp slt i32 %x, 0
%saturateLow = select i1 %cmpLow, i32 0, i32 %y
ret i32 %saturateLow
}
; x < 0 ? -1 : x
define i32 @no_sat0_incorrect_constant(i32 %x) {
; CHECK-ARM-LABEL: no_sat0_incorrect_constant:
; CHECK-ARM: @ %bb.0: @ %entry
; CHECK-ARM-NEXT: cmp r0, #0
; CHECK-ARM-NEXT: mvnmi r0, #0
; CHECK-ARM-NEXT: mov pc, lr
;
; CHECK-T-LABEL: no_sat0_incorrect_constant:
; CHECK-T: @ %bb.0: @ %entry
; CHECK-T-NEXT: cmp r0, #0
; CHECK-T-NEXT: bpl .LBB9_2
; CHECK-T-NEXT: @ %bb.1:
; CHECK-T-NEXT: movs r0, #0
; CHECK-T-NEXT: mvns r0, r0
; CHECK-T-NEXT: .LBB9_2: @ %entry
; CHECK-T-NEXT: bx lr
;
; CHECK-T2-LABEL: no_sat0_incorrect_constant:
; CHECK-T2: @ %bb.0: @ %entry
; CHECK-T2-NEXT: cmp r0, #0
; CHECK-T2-NEXT: it mi
; CHECK-T2-NEXT: movmi.w r0, #-1
; CHECK-T2-NEXT: bx lr
entry:
%cmpLow = icmp slt i32 %x, 0
%saturateLow = select i1 %cmpLow, i32 -1, i32 %x
ret i32 %saturateLow
}