fixed_point_comparisons.c
18.1 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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNPADDED
// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,PADDED
// Fixed point against other fixed point
_Bool b_eq_true = 2.5hk == 2.5uhk; // CHECK-DAG: @b_eq_true = {{.*}}global i8 1, align 1
_Bool b_eq_false = 2.5hk == 2.4uhk; // CHECK-DAG: @b_eq_false = {{.*}}global i8 0, align 1
_Bool b_ne_true = 2.5hk != 2.4uhk; // CHECK-DAG: @b_ne_true = {{.*}}global i8 1, align 1
_Bool b_ne_false = 2.5hk != 2.5uhk; // CHECK-DAG: @b_ne_false = {{.*}}global i8 0, align 1
_Bool b_lt_true = 2.5hk < 2.75uhk; // CHECK-DAG: @b_lt_true = {{.*}}global i8 1, align 1
_Bool b_lt_false = 2.5hk < 2.5uhk; // CHECK-DAG: @b_lt_false = {{.*}}global i8 0, align 1
_Bool b_le_true = 2.5hk <= 2.75uhk; // CHECK-DAG: @b_le_true = {{.*}}global i8 1, align 1
_Bool b_le_true2 = 2.5hk <= 2.5uhk; // CHECK-DAG: @b_le_true2 = {{.*}}global i8 1, align 1
_Bool b_le_false = 2.5hk <= 2.4uhk; // CHECK-DAG: @b_le_false = {{.*}}global i8 0, align 1
_Bool b_gt_true = 2.75hk > 2.5uhk; // CHECK-DAG: @b_gt_true = {{.*}}global i8 1, align 1
_Bool b_gt_false = 2.75hk > 2.75uhk; // CHECK-DAG: @b_gt_false = {{.*}}global i8 0, align 1
_Bool b_ge_true = 2.75hk >= 2.5uhk; // CHECK-DAG: @b_ge_true = {{.*}}global i8 1, align 1
_Bool b_ge_true2 = 2.75hk >= 2.75uhk; // CHECK-DAG: @b_ge_true2 = {{.*}}global i8 1, align 1
_Bool b_ge_false = 2.5hk >= 2.75uhk; // CHECK-DAG: @b_ge_false = {{.*}}global i8 0, align 1
// Fixed point against int
_Bool b_ieq_true = 2.0hk == 2; // CHECK-DAG: @b_ieq_true = {{.*}}global i8 1, align 1
_Bool b_ieq_false = 2.0hk == 3; // CHECK-DAG: @b_ieq_false = {{.*}}global i8 0, align 1
_Bool b_ine_true = 2.0hk != 3; // CHECK-DAG: @b_ine_true = {{.*}}global i8 1, align 1
_Bool b_ine_false = 2.0hk != 2; // CHECK-DAG: @b_ine_false = {{.*}}global i8 0, align 1
_Bool b_ilt_true = 2.0hk < 3; // CHECK-DAG: @b_ilt_true = {{.*}}global i8 1, align 1
_Bool b_ilt_false = 2.0hk < 2; // CHECK-DAG: @b_ilt_false = {{.*}}global i8 0, align 1
_Bool b_ile_true = 2.0hk <= 3; // CHECK-DAG: @b_ile_true = {{.*}}global i8 1, align 1
_Bool b_ile_true2 = 2.0hk <= 2; // CHECK-DAG: @b_ile_true2 = {{.*}}global i8 1, align 1
_Bool b_ile_false = 2.0hk <= 1; // CHECK-DAG: @b_ile_false = {{.*}}global i8 0, align 1
_Bool b_igt_true = 2.0hk > 1; // CHECK-DAG: @b_igt_true = {{.*}}global i8 1, align 1
_Bool b_igt_false = 2.0hk > 2; // CHECK-DAG: @b_igt_false = {{.*}}global i8 0, align 1
_Bool b_ige_true = 2.0hk >= 1; // CHECK-DAG: @b_ige_true = {{.*}}global i8 1, align 1
_Bool b_ige_true2 = 2.0hk >= 2; // CHECK-DAG: @b_ige_true2 = {{.*}}global i8 1, align 1
_Bool b_ige_false = 2.0hk >= 3; // CHECK-DAG: @b_ige_false = {{.*}}global i8 0, align 1
// Different signage
// Since we can have different precisions, non powers of 2 fractions may have
// different actual values when being compared.
_Bool b_sne_true = 2.6hk != 2.6uhk;
// UNPADDED-DAG: @b_sne_true = {{.*}}global i8 1, align 1
// PADDED-DAG: @b_sne_true = {{.*}}global i8 0, align 1
_Bool b_seq_true = 2.0hk == 2u; // CHECK-DAG: @b_seq_true = {{.*}}global i8 1, align 1
_Bool b_seq_true2 = 2.0uhk == 2; // CHECK-DAG: @b_seq_true2 = {{.*}}global i8 1, align 1
void TestComparisons() {
short _Accum sa;
_Accum a;
unsigned short _Accum usa;
unsigned _Accum ua;
// Each of these should be a fixed point conversion followed by the actual
// comparison operation.
sa == a;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[A2:%[0-9]+]] = load i32, i32* %a, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i32
// CHECK-NEXT: [[UPSCALE_A:%[a-z0-9]+]] = shl i32 [[RESIZE_A]], 8
// CHECK-NEXT: {{.*}} = icmp eq i32 [[UPSCALE_A]], [[A2]]
sa != a;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[A2:%[0-9]+]] = load i32, i32* %a, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i32
// CHECK-NEXT: [[UPSCALE_A:%[a-z0-9]+]] = shl i32 [[RESIZE_A]], 8
// CHECK-NEXT: {{.*}} = icmp ne i32 [[UPSCALE_A]], [[A2]]
sa > a;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[A2:%[0-9]+]] = load i32, i32* %a, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i32
// CHECK-NEXT: [[UPSCALE_A:%[a-z0-9]+]] = shl i32 [[RESIZE_A]], 8
// CHECK-NEXT: {{.*}} = icmp sgt i32 [[UPSCALE_A]], [[A2]]
sa >= a;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[A2:%[0-9]+]] = load i32, i32* %a, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i32
// CHECK-NEXT: [[UPSCALE_A:%[a-z0-9]+]] = shl i32 [[RESIZE_A]], 8
// CHECK-NEXT: {{.*}} = icmp sge i32 [[UPSCALE_A]], [[A2]]
sa < a;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[A2:%[0-9]+]] = load i32, i32* %a, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i32
// CHECK-NEXT: [[UPSCALE_A:%[a-z0-9]+]] = shl i32 [[RESIZE_A]], 8
// CHECK-NEXT: {{.*}} = icmp slt i32 [[UPSCALE_A]], [[A2]]
sa <= a;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[A2:%[0-9]+]] = load i32, i32* %a, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i32
// CHECK-NEXT: [[UPSCALE_A:%[a-z0-9]+]] = shl i32 [[RESIZE_A]], 8
// CHECK-NEXT: {{.*}} = icmp sle i32 [[UPSCALE_A]], [[A2]]
usa > ua;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %usa, align 2
// CHECK-NEXT: [[A2:%[0-9]+]] = load i32, i32* %ua, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i32
// CHECK-NEXT: [[UPSCALE_A:%[a-z0-9]+]] = shl i32 [[RESIZE_A]], 8
// CHECK-NEXT: {{.*}} = icmp ugt i32 [[UPSCALE_A]], [[A2]]
usa >= ua;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %usa, align 2
// CHECK-NEXT: [[A2:%[0-9]+]] = load i32, i32* %ua, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i32
// CHECK-NEXT: [[UPSCALE_A:%[a-z0-9]+]] = shl i32 [[RESIZE_A]], 8
// CHECK-NEXT: {{.*}} = icmp uge i32 [[UPSCALE_A]], [[A2]]
usa < ua;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %usa, align 2
// CHECK-NEXT: [[A2:%[0-9]+]] = load i32, i32* %ua, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i32
// CHECK-NEXT: [[UPSCALE_A:%[a-z0-9]+]] = shl i32 [[RESIZE_A]], 8
// CHECK-NEXT: {{.*}} = icmp ult i32 [[UPSCALE_A]], [[A2]]
usa <= ua;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %usa, align 2
// CHECK-NEXT: [[A2:%[0-9]+]] = load i32, i32* %ua, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i32
// CHECK-NEXT: [[UPSCALE_A:%[a-z0-9]+]] = shl i32 [[RESIZE_A]], 8
// CHECK-NEXT: {{.*}} = icmp ule i32 [[UPSCALE_A]], [[A2]]
}
void TestIntComparisons() {
short _Accum sa;
unsigned short _Accum usa;
int i;
unsigned int ui;
_Bool b;
char c;
short s;
enum E {
A = 2
} e;
// These comparisons shouldn't be that different from comparing against fixed
// point types with other fixed point types.
sa == i;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[I:%[0-9]+]] = load i32, i32* %i, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i39
// CHECK-NEXT: [[RESIZE_I:%[a-z0-9]+]] = sext i32 [[I]] to i39
// CHECK-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i39 [[RESIZE_I]], 7
// CHECK-NEXT: {{.*}} = icmp eq i39 [[RESIZE_A]], [[UPSCALE_I]]
sa != i;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[I:%[0-9]+]] = load i32, i32* %i, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i39
// CHECK-NEXT: [[RESIZE_I:%[a-z0-9]+]] = sext i32 [[I]] to i39
// CHECK-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i39 [[RESIZE_I]], 7
// CHECK-NEXT: {{.*}} = icmp ne i39 [[RESIZE_A]], [[UPSCALE_I]]
sa > i;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[I:%[0-9]+]] = load i32, i32* %i, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i39
// CHECK-NEXT: [[RESIZE_I:%[a-z0-9]+]] = sext i32 [[I]] to i39
// CHECK-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i39 [[RESIZE_I]], 7
// CHECK-NEXT: {{.*}} = icmp sgt i39 [[RESIZE_A]], [[UPSCALE_I]]
sa >= i;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[I:%[0-9]+]] = load i32, i32* %i, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i39
// CHECK-NEXT: [[RESIZE_I:%[a-z0-9]+]] = sext i32 [[I]] to i39
// CHECK-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i39 [[RESIZE_I]], 7
// CHECK-NEXT: {{.*}} = icmp sge i39 [[RESIZE_A]], [[UPSCALE_I]]
sa < i;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[I:%[0-9]+]] = load i32, i32* %i, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i39
// CHECK-NEXT: [[RESIZE_I:%[a-z0-9]+]] = sext i32 [[I]] to i39
// CHECK-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i39 [[RESIZE_I]], 7
// CHECK-NEXT: {{.*}} = icmp slt i39 [[RESIZE_A]], [[UPSCALE_I]]
sa <= i;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[I:%[0-9]+]] = load i32, i32* %i, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i39
// CHECK-NEXT: [[RESIZE_I:%[a-z0-9]+]] = sext i32 [[I]] to i39
// CHECK-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i39 [[RESIZE_I]], 7
// CHECK-NEXT: {{.*}} = icmp sle i39 [[RESIZE_A]], [[UPSCALE_I]]
usa > ui;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %usa, align 2
// CHECK-NEXT: [[I:%[0-9]+]] = load i32, i32* %ui, align 4
// UNPADDED-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i40
// UNPADDED-NEXT: [[RESIZE_I:%[a-z0-9]+]] = zext i32 [[I]] to i40
// UNPADDED-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i40 [[RESIZE_I]], 8
// UNPADDED-NEXT: {{.*}} = icmp ugt i40 [[RESIZE_A]], [[UPSCALE_I]]
// PADDED-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i39
// PADDED-NEXT: [[RESIZE_I:%[a-z0-9]+]] = zext i32 [[I]] to i39
// PADDED-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i39 [[RESIZE_I]], 7
// PADDED-NEXT: {{.*}} = icmp ugt i39 [[RESIZE_A]], [[UPSCALE_I]]
usa >= ui;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %usa, align 2
// CHECK-NEXT: [[I:%[0-9]+]] = load i32, i32* %ui, align 4
// UNPADDED-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i40
// UNPADDED-NEXT: [[RESIZE_I:%[a-z0-9]+]] = zext i32 [[I]] to i40
// UNPADDED-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i40 [[RESIZE_I]], 8
// UNPADDED-NEXT: {{.*}} = icmp uge i40 [[RESIZE_A]], [[UPSCALE_I]]
// PADDED-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i39
// PADDED-NEXT: [[RESIZE_I:%[a-z0-9]+]] = zext i32 [[I]] to i39
// PADDED-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i39 [[RESIZE_I]], 7
// PADDED-NEXT: {{.*}} = icmp uge i39 [[RESIZE_A]], [[UPSCALE_I]]
usa < ui;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %usa, align 2
// CHECK-NEXT: [[I:%[0-9]+]] = load i32, i32* %ui, align 4
// UNPADDED-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i40
// UNPADDED-NEXT: [[RESIZE_I:%[a-z0-9]+]] = zext i32 [[I]] to i40
// UNPADDED-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i40 [[RESIZE_I]], 8
// UNPADDED-NEXT: {{.*}} = icmp ult i40 [[RESIZE_A]], [[UPSCALE_I]]
// PADDED-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i39
// PADDED-NEXT: [[RESIZE_I:%[a-z0-9]+]] = zext i32 [[I]] to i39
// PADDED-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i39 [[RESIZE_I]], 7
// PADDED-NEXT: {{.*}} = icmp ult i39 [[RESIZE_A]], [[UPSCALE_I]]
usa <= ui;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %usa, align 2
// CHECK-NEXT: [[I:%[0-9]+]] = load i32, i32* %ui, align 4
// UNPADDED-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i40
// UNPADDED-NEXT: [[RESIZE_I:%[a-z0-9]+]] = zext i32 [[I]] to i40
// UNPADDED-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i40 [[RESIZE_I]], 8
// UNPADDED-NEXT: {{.*}} = icmp ule i40 [[RESIZE_A]], [[UPSCALE_I]]
// PADDED-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i39
// PADDED-NEXT: [[RESIZE_I:%[a-z0-9]+]] = zext i32 [[I]] to i39
// PADDED-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i39 [[RESIZE_I]], 7
// PADDED-NEXT: {{.*}} = icmp ule i39 [[RESIZE_A]], [[UPSCALE_I]]
// Allow for comparisons with other int like types. These are no different
// from comparing to an int other than varying sizes. The integer types are
// still converted to ints or unsigned ints from UsualUnaryConversions().
sa == b;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[B:%[0-9]+]] = load i8, i8* %b, align 1
// CHECK-NEXT: %tobool = trunc i8 [[B]] to i1
// CHECK-NEXT: [[CONV_B:%[a-z0-9]+]] = zext i1 %tobool to i32
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i39
// CHECK-NEXT: [[RESIZE_B:%[a-z0-9]+]] = sext i32 [[CONV_B]] to i39
// CHECK-NEXT: [[UPSCALE_B:%[a-z0-9]+]] = shl i39 [[RESIZE_B]], 7
// CHECK-NEXT: {{.*}} = icmp eq i39 [[RESIZE_A]], [[UPSCALE_B]]
sa == c;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[C:%[0-9]+]] = load i8, i8* %c, align 1
// CHECK-NEXT: [[CONV_C:%[a-z0-9]+]] = sext i8 [[C]] to i32
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i39
// CHECK-NEXT: [[RESIZE_C:%[a-z0-9]+]] = sext i32 [[CONV_C]] to i39
// CHECK-NEXT: [[UPSCALE_C:%[a-z0-9]+]] = shl i39 [[RESIZE_C]], 7
// CHECK-NEXT: {{.*}} = icmp eq i39 [[RESIZE_A]], [[UPSCALE_C]]
sa == s;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[S:%[0-9]+]] = load i16, i16* %s, align 2
// CHECK-NEXT: [[CONV_S:%[a-z0-9]+]] = sext i16 [[S]] to i32
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i39
// CHECK-NEXT: [[RESIZE_S:%[a-z0-9]+]] = sext i32 [[CONV_S]] to i39
// CHECK-NEXT: [[UPSCALE_S:%[a-z0-9]+]] = shl i39 [[RESIZE_S]], 7
// CHECK-NEXT: {{.*}} = icmp eq i39 [[RESIZE_A]], [[UPSCALE_S]]
// An enum value is IntegralCast to an unsigned int.
usa == e;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %usa, align 2
// CHECK-NEXT: [[I:%[0-9]+]] = load i32, i32* %e, align 4
// UNPADDED-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i40
// UNPADDED-NEXT: [[RESIZE_I:%[a-z0-9]+]] = zext i32 [[I]] to i40
// UNPADDED-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i40 [[RESIZE_I]], 8
// UNPADDED-NEXT: {{.*}} = icmp eq i40 [[RESIZE_A]], [[UPSCALE_I]]
// PADDED-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i39
// PADDED-NEXT: [[RESIZE_I:%[a-z0-9]+]] = zext i32 [[I]] to i39
// PADDED-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i39 [[RESIZE_I]], 7
// PADDED-NEXT: {{.*}} = icmp eq i39 [[RESIZE_A]], [[UPSCALE_I]]
}
void TestComparisonSignage() {
short _Accum sa;
unsigned short _Accum usa;
int i;
unsigned int ui;
// Signed vs unsigned fixed point comparison
sa == usa;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[A2:%[0-9]+]] = load i16, i16* %usa, align 2
// UNPADDED-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i17
// UNPADDED-NEXT: [[UPSCALE_A:%[a-z0-9]+]] = shl i17 [[RESIZE_A]], 1
// UNPADDED-NEXT: [[RESIZE_A2:%[a-z0-9]+]] = zext i16 [[A2]] to i17
// UNPADDED-NEXT: {{.*}} = icmp eq i17 [[UPSCALE_A]], [[RESIZE_A2]]
// PADDED-NEXT: {{.*}} = icmp eq i16 [[A]], [[A2]]
// Signed int vs unsigned fixed point
sa == ui;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[I:%[0-9]+]] = load i32, i32* %ui, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i40
// CHECK-NEXT: [[RESIZE_I:%[a-z0-9]+]] = zext i32 [[I]] to i40
// CHECK-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i40 [[RESIZE_I]], 7
// CHECK-NEXT: {{.*}} = icmp eq i40 [[RESIZE_A]], [[UPSCALE_I]]
// Signed fixed point vs unsigned int
usa == i;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %usa, align 2
// CHECK-NEXT: [[I:%[0-9]+]] = load i32, i32* %i, align 4
// UNPADDED-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i40
// UNPADDED-NEXT: [[RESIZE_I:%[a-z0-9]+]] = sext i32 [[I]] to i40
// UNPADDED-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i40 [[RESIZE_I]], 8
// UNPADDED-NEXT: {{.*}} = icmp eq i40 [[RESIZE_A]], [[UPSCALE_I]]
// PADDED-NEXT: [[RESIZE_A:%[a-z0-9]+]] = zext i16 [[A]] to i39
// PADDED-NEXT: [[RESIZE_I:%[a-z0-9]+]] = sext i32 [[I]] to i39
// PADDED-NEXT: [[UPSCALE_I:%[a-z0-9]+]] = shl i39 [[RESIZE_I]], 7
// PADDED-NEXT: {{.*}} = icmp eq i39 [[RESIZE_A]], [[UPSCALE_I]]
}
void TestSaturationComparisons() {
short _Accum sa;
_Accum a;
_Sat short _Accum sat_sa;
_Sat _Accum sat_a;
_Sat unsigned short _Accum sat_usa;
// These are effectively the same as conversions with their non-saturating
// counterparts since when comparing, we convert both operands to a common
// type that should be able to hold both values.
sat_sa == sat_a;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sat_sa, align 2
// CHECK-NEXT: [[A2:%[0-9]+]] = load i32, i32* %sat_a, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i32
// CHECK-NEXT: [[UPSCALE_A:%[a-z0-9]+]] = shl i32 [[RESIZE_A]], 8
// CHECK-NEXT: {{.*}} = icmp eq i32 [[UPSCALE_A]], [[A2]]
sat_sa == a;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sat_sa, align 2
// CHECK-NEXT: [[A2:%[0-9]+]] = load i32, i32* %a, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i32
// CHECK-NEXT: [[UPSCALE_A:%[a-z0-9]+]] = shl i32 [[RESIZE_A]], 8
// CHECK-NEXT: {{.*}} = icmp eq i32 [[UPSCALE_A]], [[A2]]
sat_sa == sat_usa;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sat_sa, align 2
// CHECK-NEXT: [[A2:%[0-9]+]] = load i16, i16* %sat_usa, align 2
// UNPADDED-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i17
// UNPADDED-NEXT: [[UPSCALE_A:%[a-z0-9]+]] = shl i17 [[RESIZE_A]], 1
// UNPADDED-NEXT: [[RESIZE_A2:%[a-z0-9]+]] = zext i16 [[A2]] to i17
// UNPADDED-NEXT: {{.*}} = icmp eq i17 [[UPSCALE_A]], [[RESIZE_A2]]
// PADDED-NEXT: {{.*}} = icmp eq i16 [[A]], [[A2]]
}
void StoreBooleanResult() {
short _Accum sa;
_Accum a;
int res;
// Check that the result can properly be stored as an int.
res = sa == a;
// CHECK: [[A:%[0-9]+]] = load i16, i16* %sa, align 2
// CHECK-NEXT: [[A2:%[0-9]+]] = load i32, i32* %a, align 4
// CHECK-NEXT: [[RESIZE_A:%[a-z0-9]+]] = sext i16 [[A]] to i32
// CHECK-NEXT: [[UPSCALE_A:%[a-z0-9]+]] = shl i32 [[RESIZE_A]], 8
// CHECK-NEXT: [[RES:%[0-9]+]] = icmp eq i32 [[UPSCALE_A]], [[A2]]
// CHECK-NEXT: %conv = zext i1 [[RES]] to i32
// CHECK-NEXT: store i32 %conv, i32* %res, align 4
}