xref: /llvm-project/mlir/test/Dialect/Index/index-canonicalize.mlir (revision 795b4efad0259cbf03fc98e3045621916328ce57)
1// RUN: mlir-opt %s -canonicalize | FileCheck %s
2
3// CHECK-LABEL: @add
4func.func @add() -> (index, index) {
5  %0 = index.constant 1
6  %1 = index.constant 2100
7  %2 = index.constant 3000000001
8  %3 = index.constant 4000002100
9  // Folds normally.
10  %4 = index.add %0, %1
11  // Folds even though values exceed INT32_MAX.
12  %5 = index.add %2, %3
13
14  // CHECK-DAG: %[[A:.*]] = index.constant 2101
15  // CHECK-DAG: %[[B:.*]] = index.constant 7000002101
16  // CHECK: return %[[A]], %[[B]]
17  return %4, %5 : index, index
18}
19
20// CHECK-LABEL: @add_overflow
21func.func @add_overflow() -> (index, index) {
22  %0 = index.constant 2000000000
23  %1 = index.constant 8000000000000000000
24  // Folds normally.
25  %2 = index.add %0, %0
26  // Folds and overflows.
27  %3 = index.add %1, %1
28
29  // CHECK-DAG: %[[A:.*]] = index.constant 4{{0+}}
30  // CHECK-DAG: %[[B:.*]] = index.constant -2446{{[0-9]+}}
31  // CHECK: return %[[A]], %[[B]]
32  return %2, %3 : index, index
33}
34
35// CHECK-LABEL: @add_fold_constants
36func.func @add_fold_constants(%arg: index) -> (index) {
37  %0 = index.constant 1
38  %1 = index.constant 2
39  %2 = index.add %arg, %0
40  %3 = index.add %2, %1
41
42  // CHECK: [[C3:%.*]] = index.constant 3
43  // CHECK: [[V0:%.*]] = index.add %arg0, [[C3]]
44  // CHECK: return [[V0]]
45  return %3 : index
46}
47
48// CHECK-LABEL: @sub
49func.func @sub() -> index {
50  %0 = index.constant -2000000000
51  %1 = index.constant 3000000000
52  %2 = index.sub %0, %1
53  // CHECK: %[[A:.*]] = index.constant -5{{0+}}
54  // CHECK: return %[[A]]
55  return %2 : index
56}
57
58// CHECK-LABEL: @mul
59func.func @mul() -> index {
60  %0 = index.constant 8000000002000000000
61  %1 = index.constant 2
62  %2 = index.mul %0, %1
63  // CHECK: %[[A:.*]] = index.constant -2446{{[0-9]+}}
64  // CHECK: return %[[A]]
65  return %2 : index
66}
67
68// CHECK-LABEL: @mul_fold_constants
69func.func @mul_fold_constants(%arg: index) -> (index) {
70  %0 = index.constant 2
71  %1 = index.constant 3
72  %2 = index.mul %arg, %0
73  %3 = index.mul %2, %1
74
75  // CHECK: [[C6:%.*]] = index.constant 6
76  // CHECK: [[V0:%.*]] = index.mul %arg0, [[C6]]
77  // CHECK: return [[V0]]
78  return %3 : index
79}
80
81// CHECK-LABEL: @divs
82func.func @divs() -> index {
83  %0 = index.constant -2
84  %1 = index.constant 0x200000000
85  %2 = index.divs %1, %0
86  // CHECK: %[[A:.*]] = index.constant -429{{[0-9]+}}
87  // CHECK: return %[[A]]
88  return %2 : index
89}
90
91// CHECK-LABEL: @divs_nofold
92func.func @divs_nofold() -> (index, index) {
93  %0 = index.constant 0
94  %1 = index.constant 0x100000000
95  %2 = index.constant 2
96
97  // Divide by zero.
98  // CHECK: index.divs
99  %3 = index.divs %2, %0
100  // 32-bit result differs from 64-bit.
101  // CHECK: index.divs
102  %4 = index.divs %1, %2
103
104  return %3, %4 : index, index
105}
106
107// CHECK-LABEL: @divu
108func.func @divu() -> index {
109  %0 = index.constant -2
110  %1 = index.constant 0x200000000
111  %2 = index.divu %1, %0
112  // CHECK: %[[A:.*]] = index.constant 0
113  // CHECK: return %[[A]]
114  return %2 : index
115}
116
117// CHECK-LABEL: @divu_nofold
118func.func @divu_nofold() -> (index, index) {
119  %0 = index.constant 0
120  %1 = index.constant 0x100000000
121  %2 = index.constant 2
122
123  // Divide by zero.
124  // CHECK: index.divu
125  %3 = index.divu %2, %0
126  // 32-bit result differs from 64-bit.
127  // CHECK: index.divu
128  %4 = index.divu %1, %2
129
130  return %3, %4 : index, index
131}
132
133// CHECK-LABEL: @ceildivs
134func.func @ceildivs() -> (index, index, index) {
135  %c0 = index.constant 0
136  %c2 = index.constant 2
137  %c5 = index.constant 5
138
139  // CHECK-DAG: %[[A:.*]] = index.constant 0
140  %0 = index.ceildivs %c0, %c5
141
142  // CHECK-DAG: %[[B:.*]] = index.constant 1
143  %1 = index.ceildivs %c2, %c5
144
145  // CHECK-DAG: %[[C:.*]] = index.constant 3
146  %2 = index.ceildivs %c5, %c2
147
148  // CHECK: return %[[A]], %[[B]], %[[C]]
149  return %0, %1, %2 : index, index, index
150}
151
152// CHECK-LABEL: @ceildivs_neg
153func.func @ceildivs_neg() -> index {
154  %c5 = index.constant -5
155  %c2 = index.constant 2
156  // CHECK: %[[A:.*]] = index.constant -2
157  %0 = index.ceildivs %c5, %c2
158  // CHECK: return %[[A]]
159  return %0 : index
160}
161
162// CHECK-LABEL: @ceildivs_edge
163func.func @ceildivs_edge() -> (index, index) {
164  %cn1 = index.constant -1
165  %cIntMin = index.constant -2147483648
166  %cIntMax = index.constant 2147483647
167
168  // The result is 0 on 32-bit.
169  // CHECK-DAG: %[[A:.*]] = index.constant 2147483648
170  %0 = index.ceildivs %cIntMin, %cn1
171
172  // CHECK-DAG: %[[B:.*]] = index.constant -2147483647
173  %1 = index.ceildivs %cIntMax, %cn1
174
175  // CHECK: return %[[A]], %[[B]]
176  return %0, %1 : index, index
177}
178
179// CHECK-LABEL: @ceildivu
180func.func @ceildivu() -> index {
181  %0 = index.constant 0x200000001
182  %1 = index.constant 2
183  // CHECK: %[[A:.*]] = index.constant 429{{[0-9]+}}7
184  %2 = index.ceildivu %0, %1
185  // CHECK: return %[[A]]
186  return %2 : index
187}
188
189// CHECK-LABEL: @floordivs
190func.func @floordivs() -> index {
191  %0 = index.constant -5
192  %1 = index.constant 2
193  // CHECK: %[[A:.*]] = index.constant -3
194  %2 = index.floordivs %0, %1
195  // CHECK: return %[[A]]
196  return %2 : index
197}
198
199// CHECK-LABEL: @floordivs_edge
200func.func @floordivs_edge() -> (index, index) {
201  %cIntMin = index.constant -2147483648
202  %cIntMax = index.constant 2147483647
203  %n1 = index.constant -1
204  %p1 = index.constant 1
205
206  // CHECK-DAG: %[[A:.*]] = index.constant -2147483648
207  // CHECK-DAG: %[[B:.*]] = index.constant -2147483647
208  %0 = index.floordivs %cIntMin, %p1
209  %1 = index.floordivs %cIntMax, %n1
210
211  // CHECK: return %[[A]], %[[B]]
212  return %0, %1 : index, index
213}
214
215// CHECK-LABEL: @floordivs_nofold
216func.func @floordivs_nofold() -> index {
217  %lhs = index.constant 0x100000000
218  %c2 = index.constant 2
219
220  // 32-bit result differs from 64-bit.
221  // CHECK: index.floordivs
222  %0 = index.floordivs %lhs, %c2
223
224  return %0 : index
225}
226
227// CHECK-LABEL: @rems_zerodiv_nofold
228func.func @rems_zerodiv_nofold() -> index {
229  %lhs = index.constant 2
230  %rhs = index.constant 0
231  // CHECK: index.rems
232  %0 = index.rems %lhs, %rhs
233  return %0 : index
234}
235
236// CHECK-LABEL: @remu_zerodiv_nofold
237func.func @remu_zerodiv_nofold() -> index {
238  %lhs = index.constant 2
239  %rhs = index.constant 0
240  // CHECK: index.remu
241  %0 = index.remu %lhs, %rhs
242  return %0 : index
243}
244
245// CHECK-LABEL: @rems
246func.func @rems() -> index {
247  %lhs = index.constant -5
248  %rhs = index.constant 2
249  // CHECK: %[[A:.*]] = index.constant -1
250  %0 = index.rems %lhs, %rhs
251  // CHECK: return %[[A]]
252  return %0 : index
253}
254
255// CHECK-LABEL: @rems_nofold
256func.func @rems_nofold() -> index {
257  %lhs = index.constant 2
258  %rhs = index.constant 0x100000001
259  // 32-bit result differs from 64-bit.
260  // CHECK: index.rems
261  %0 = index.rems %lhs, %rhs
262  return %0 : index
263}
264
265// CHECK-LABEL: @remu
266func.func @remu() -> index {
267  %lhs = index.constant 2
268  %rhs = index.constant -1
269  // CHECK: %[[A:.*]] = index.constant 2
270  %0 = index.remu %lhs, %rhs
271  // CHECK: return %[[A]]
272  return %0 : index
273}
274
275// CHECK-LABEL: @remu_nofold
276func.func @remu_nofold() -> index {
277  %lhs = index.constant 2
278  %rhs = index.constant 0x100000001
279  // 32-bit result differs from 64-bit.
280  // CHECK: index.remu
281  %0 = index.remu %lhs, %rhs
282  return %0 : index
283}
284
285// CHECK-LABEL: @maxs
286func.func @maxs() -> index {
287  %lhs = index.constant -4
288  %rhs = index.constant 2
289  // CHECK: %[[A:.*]] = index.constant 2
290  %0 = index.maxs %lhs, %rhs
291  // CHECK: return %[[A]]
292  return %0 : index
293}
294
295// CHECK-LABEL: @maxs_nofold
296func.func @maxs_nofold() -> index {
297  %lhs = index.constant 1
298  %rhs = index.constant 0x100000000
299  // 32-bit result differs from 64-bit.
300  // CHECK: index.maxs
301  %0 = index.maxs %lhs, %rhs
302  return %0 : index
303}
304
305// CHECK-LABEL: @maxs_edge
306func.func @maxs_edge() -> index {
307  %lhs = index.constant 1
308  %rhs = index.constant 0x100000001
309  // Truncated 64-bit result is the same as 32-bit.
310  // CHECK: %[[A:.*]] = index.constant 429{{[0-9]+}}
311  %0 = index.maxs %lhs, %rhs
312  // CHECK: return %[[A]]
313  return %0 : index
314}
315
316// CHECK-LABEL: @maxs_fold_constants
317func.func @maxs_fold_constants(%arg: index) -> (index) {
318  %0 = index.constant -2
319  %1 = index.constant 3
320  %2 = index.maxs %arg, %0
321  %3 = index.maxs %2, %1
322
323  // CHECK: [[C3:%.*]] = index.constant 3
324  // CHECK: [[V0:%.*]] = index.maxs %arg0, [[C3]]
325  // CHECK: return [[V0]]
326  return %3 : index
327}
328
329// CHECK-LABEL: @maxu
330func.func @maxu() -> index {
331  %lhs = index.constant -1
332  %rhs = index.constant 1
333  // CHECK: %[[A:.*]] = index.constant -1
334  %0 = index.maxu %lhs, %rhs
335  // CHECK: return %[[A]]
336  return %0 : index
337}
338
339// CHECK-LABEL: @maxu_fold_constants
340func.func @maxu_fold_constants(%arg: index) -> (index) {
341  %0 = index.constant 2
342  %1 = index.constant 3
343  %2 = index.maxu %arg, %0
344  %3 = index.maxu %2, %1
345
346  // CHECK: [[C3:%.*]] = index.constant 3
347  // CHECK: [[V0:%.*]] = index.maxu %arg0, [[C3]]
348  // CHECK: return [[V0]]
349  return %3 : index
350}
351
352// CHECK-LABEL: @mins
353func.func @mins() -> index {
354  %lhs = index.constant -4
355  %rhs = index.constant 2
356  // CHECK: %[[A:.*]] = index.constant -4
357  %0 = index.mins %lhs, %rhs
358  // CHECK: return %[[A]]
359  return %0 : index
360}
361
362// CHECK-LABEL: @mins_nofold
363func.func @mins_nofold() -> index {
364  %lhs = index.constant 1
365  %rhs = index.constant 0x100000000
366  // 32-bit result differs from 64-bit.
367  // CHECK: index.mins
368  %0 = index.mins %lhs, %rhs
369  return %0 : index
370}
371
372// CHECK-LABEL: @mins_nofold_2
373func.func @mins_nofold_2() -> index {
374  %lhs = index.constant 0x7fffffff
375  %rhs = index.constant 0x80000000
376  // 32-bit result differs from 64-bit.
377  // CHECK: index.mins
378  %0 = index.mins %lhs, %rhs
379  return %0 : index
380}
381
382// CHECK-LABEL: @mins_fold_constants
383func.func @mins_fold_constants(%arg: index) -> (index) {
384  %0 = index.constant -2
385  %1 = index.constant 3
386  %2 = index.mins %arg, %0
387  %3 = index.mins %2, %1
388
389  // CHECK: [[C2:%.*]] = index.constant -2
390  // CHECK: [[V0:%.*]] = index.mins %arg0, [[C2]]
391  // CHECK: return [[V0]]
392  return %3 : index
393}
394
395// CHECK-LABEL: @minu
396func.func @minu() -> index {
397  %lhs = index.constant -1
398  %rhs = index.constant 1
399  // CHECK: %[[A:.*]] = index.constant 1
400  %0 = index.minu %lhs, %rhs
401  // CHECK: return %[[A]]
402  return %0 : index
403}
404
405// CHECK-LABEL: @minu_fold_constants
406func.func @minu_fold_constants(%arg: index) -> (index) {
407  %0 = index.constant 2
408  %1 = index.constant 3
409  %2 = index.minu %arg, %0
410  %3 = index.minu %2, %1
411
412  // CHECK: [[C2:%.*]] = index.constant 2
413  // CHECK: [[V0:%.*]] = index.minu %arg0, [[C2]]
414  // CHECK: return [[V0]]
415  return %3 : index
416}
417
418// CHECK-LABEL: @shl
419func.func @shl() -> index {
420  %lhs = index.constant 128
421  %rhs = index.constant 2
422  // CHECK: %[[A:.*]] = index.constant 512
423  %0 = index.shl %lhs, %rhs
424  // CHECK: return %[[A]]
425  return %0 : index
426}
427
428// CHECK-LABEL: @shl_32
429func.func @shl_32() -> index {
430  %lhs = index.constant 1
431  %rhs = index.constant 32
432  // CHECK: index.shl
433  %0 = index.shl %lhs, %rhs
434  return %0 : index
435}
436
437// CHECK-LABEL: @shl_edge
438func.func @shl_edge() -> index {
439  %lhs = index.constant 4000000000
440  %rhs = index.constant 31
441  // CHECK: %[[A:.*]] = index.constant 858{{[0-9]+}}
442  %0 = index.shl %lhs, %rhs
443  // CHECK: return %[[A]]
444  return %0 : index
445}
446
447// CHECK-LABEL: @shrs
448func.func @shrs() -> index {
449  %lhs = index.constant 128
450  %rhs = index.constant 2
451  // CHECK: %[[A:.*]] = index.constant 32
452  %0 = index.shrs %lhs, %rhs
453  // CHECK: return %[[A]]
454  return %0 : index
455}
456
457// CHECK-LABEL: @shrs_32
458func.func @shrs_32() -> index {
459  %lhs = index.constant 4000000000000
460  %rhs = index.constant 32
461  // CHECK: index.shrs
462  %0 = index.shrs %lhs, %rhs
463  return %0 : index
464}
465
466// CHECK-LABEL: @shrs_nofold
467func.func @shrs_nofold() -> index {
468  %lhs = index.constant 0x100000000
469  %rhs = index.constant 1
470  // CHECK: index.shrs
471  %0 = index.shrs %lhs, %rhs
472  return %0 : index
473}
474
475// CHECK-LABEL: @shrs_edge
476func.func @shrs_edge() -> index {
477  %lhs = index.constant 0x10000000000
478  %rhs = index.constant 3
479  // CHECK: %[[A:.*]] = index.constant 137{{[0-9]+}}
480  %0 = index.shrs %lhs, %rhs
481  // CHECK: return %[[A]]
482  return %0 : index
483}
484
485// CHECK-LABEL: @shru
486func.func @shru() -> index {
487  %lhs = index.constant 128
488  %rhs = index.constant 2
489  // CHECK: %[[A:.*]] = index.constant 32
490  %0 = index.shru %lhs, %rhs
491  // CHECK: return %[[A]]
492  return %0 : index
493}
494
495// CHECK-LABEL: @shru_32
496func.func @shru_32() -> index {
497  %lhs = index.constant 4000000000000
498  %rhs = index.constant 32
499  // CHECK: index.shru
500  %0 = index.shru %lhs, %rhs
501  return %0 : index
502}
503
504// CHECK-LABEL: @shru_nofold
505func.func @shru_nofold() -> index {
506  %lhs = index.constant 0x100000000
507  %rhs = index.constant 1
508  // CHECK: index.shru
509  %0 = index.shru %lhs, %rhs
510  return %0 : index
511}
512
513// CHECK-LABEL: @shru_edge
514func.func @shru_edge() -> index {
515  %lhs = index.constant 0x10000000000
516  %rhs = index.constant 3
517  // CHECK: %[[A:.*]] = index.constant 137{{[0-9]+}}
518  %0 = index.shru %lhs, %rhs
519  // CHECK: return %[[A]]
520  return %0 : index
521}
522
523// CHECK-LABEL: @and
524func.func @and() -> index {
525  %lhs = index.constant 5
526  %rhs = index.constant 1
527  // CHECK: %[[A:.*]] = index.constant 1
528  %0 = index.and %lhs, %rhs
529  // CHECK: return %[[A]]
530  return %0 : index
531}
532
533// CHECK-LABEL: @and_fold_constants
534func.func @and_fold_constants(%arg: index) -> (index) {
535  %0 = index.constant 5
536  %1 = index.constant 1
537  %2 = index.and %arg, %0
538  %3 = index.and %2, %1
539
540  // CHECK: [[C1:%.*]] = index.constant 1
541  // CHECK: [[V0:%.*]] = index.and %arg0, [[C1]]
542  // CHECK: return [[V0]]
543  return %3 : index
544}
545
546// CHECK-LABEL: @or
547func.func @or() -> index {
548  %lhs = index.constant 5
549  %rhs = index.constant 2
550  // CHECK: %[[A:.*]] = index.constant 7
551  %0 = index.or %lhs, %rhs
552  // CHECK: return %[[A]]
553  return %0 : index
554}
555
556// CHECK-LABEL: @or_fold_constants
557func.func @or_fold_constants(%arg: index) -> (index) {
558  %0 = index.constant 5
559  %1 = index.constant 1
560  %2 = index.or %arg, %0
561  %3 = index.or %2, %1
562
563  // CHECK: [[C5:%.*]] = index.constant 5
564  // CHECK: [[V0:%.*]] = index.or %arg0, [[C5]]
565  // CHECK: return [[V0]]
566  return %3 : index
567}
568
569// CHECK-LABEL: @xor
570func.func @xor() -> index {
571  %lhs = index.constant 5
572  %rhs = index.constant 1
573  // CHECK: %[[A:.*]] = index.constant 4
574  %0 = index.xor %lhs, %rhs
575  // CHECK: return %[[A]]
576  return %0 : index
577}
578
579// CHECK-LABEL: @xor_fold_constants
580func.func @xor_fold_constants(%arg: index) -> (index) {
581  %0 = index.constant 5
582  %1 = index.constant 1
583  %2 = index.xor %arg, %0
584  %3 = index.xor %2, %1
585
586  // CHECK: [[C4:%.*]] = index.constant 4
587  // CHECK: [[V0:%.*]] = index.xor %arg0, [[C4]]
588  // CHECK: return [[V0]]
589  return %3 : index
590}
591
592// CHECK-LABEL: @cmp
593func.func @cmp(%arg0: index) -> (i1, i1, i1, i1, i1, i1) {
594  %a = index.constant 0
595  %b = index.constant -1
596  %c = index.constant -2
597  %d = index.constant 4
598
599  %0 = index.cmp slt(%a, %b)
600  %1 = index.cmp ugt(%b, %a)
601  %2 = index.cmp ne(%d, %a)
602  %3 = index.cmp sgt(%b, %a)
603
604  %4 = index.sub %a, %arg0
605  %5 = index.cmp sgt(%4, %a)
606
607  %6 = index.sub %a, %arg0
608  %7 = index.cmp sgt(%a, %6)
609
610  // CHECK-DAG: %[[TRUE:.*]] = index.bool.constant true
611  // CHECK-DAG: %[[FALSE:.*]] = index.bool.constant false
612  // CHECK-DAG: [[IDX0:%.*]] = index.constant 0
613  // CHECK-DAG: [[V4:%.*]] = index.cmp sgt([[IDX0]], %arg0)
614  // CHECK-DAG: [[V5:%.*]] = index.cmp sgt(%arg0, [[IDX0]])
615  // CHECK: return %[[FALSE]], %[[TRUE]], %[[TRUE]], %[[FALSE]]
616  return %0, %1, %2, %3, %5, %7 : i1, i1, i1, i1, i1, i1
617}
618
619// CHECK-LABEL: @cmp_same_args
620func.func @cmp_same_args(%a: index) -> (i1, i1, i1, i1, i1, i1, i1, i1, i1, i1) {
621  %0 = index.cmp eq(%a, %a)
622  %1 = index.cmp sge(%a, %a)
623  %2 = index.cmp sle(%a, %a)
624  %3 = index.cmp uge(%a, %a)
625  %4 = index.cmp ule(%a, %a)
626  %5 = index.cmp ne(%a, %a)
627  %6 = index.cmp sgt(%a, %a)
628  %7 = index.cmp slt(%a, %a)
629  %8 = index.cmp ugt(%a, %a)
630  %9 = index.cmp ult(%a, %a)
631
632  // CHECK-DAG: %[[TRUE:.*]] = index.bool.constant true
633  // CHECK-DAG: %[[FALSE:.*]] = index.bool.constant false
634  // CHECK-NEXT: return %[[TRUE]], %[[TRUE]], %[[TRUE]], %[[TRUE]], %[[TRUE]],
635  // CHECK-SAME: %[[FALSE]], %[[FALSE]], %[[FALSE]], %[[FALSE]], %[[FALSE]]
636  return %0, %1, %2, %3, %4, %5, %6, %7, %8, %9 : i1, i1, i1, i1, i1, i1, i1, i1, i1, i1
637}
638
639// CHECK-LABEL: @cmp_nofold
640func.func @cmp_nofold() -> i1 {
641  %lhs = index.constant 1
642  %rhs = index.constant 0x100000000
643  // 32-bit result differs from 64-bit.
644  // CHECK: index.cmp slt
645  %0 = index.cmp slt(%lhs, %rhs)
646  return %0 : i1
647}
648
649// CHECK-LABEL: @cmp_edge
650func.func @cmp_edge() -> i1 {
651  %lhs = index.constant 1
652  %rhs = index.constant 0x100000002
653  // 64-bit result is the same as 32-bit.
654  // CHECK: %[[TRUE:.*]] = index.bool.constant true
655  %0 = index.cmp slt(%lhs, %rhs)
656  // CHECK: return %[[TRUE]]
657  return %0 : i1
658}
659
660// CHECK-LABEL: @cmp_maxs
661func.func @cmp_maxs(%arg0: index) -> (i1, i1) {
662  %idx0 = index.constant 0
663  %idx1 = index.constant 1
664  %0 = index.maxs %arg0, %idx1
665  %1 = index.cmp sgt(%0, %idx0)
666  %2 = index.cmp eq(%0, %idx0)
667  // CHECK: return %true, %false
668  return %1, %2 : i1, i1
669}
670
671// CHECK-LABEL: @mul_identity
672func.func @mul_identity(%arg0: index) -> (index, index) {
673  %idx0 = index.constant 0
674  %idx1 = index.constant 1
675  %0 = index.mul %arg0, %idx0
676  %1 = index.mul %arg0, %idx1
677  // CHECK: return %idx0, %arg0
678  return %0, %1 : index, index
679}
680
681// CHECK-LABEL: @add_identity
682func.func @add_identity(%arg0: index) -> index {
683  %idx0 = index.constant 0
684  %0 = index.add %arg0, %idx0
685  // CHECK-NEXT: return %arg0
686  return %0 : index
687}
688
689// CHECK-LABEL: @sub_identity
690func.func @sub_identity(%arg0: index) -> index {
691  %idx0 = index.constant 0
692  %0 = index.sub %arg0, %idx0
693  // CHECK-NEXT: return %arg0
694  return %0 : index
695}
696
697// CHECK-LABEL: @castu_to_index
698func.func @castu_to_index() -> index {
699  // CHECK: index.constant 8000000000000
700  %0 = arith.constant 8000000000000 : i48
701  %1 = index.castu %0 : i48 to index
702  return %1 : index
703}
704
705// CHECK-LABEL: @casts_to_index
706func.func @casts_to_index() -> index {
707  // CHECK: index.constant -1000
708  %0 = arith.constant -1000 : i48
709  %1 = index.casts %0 : i48 to index
710  return %1 : index
711}
712