xref: /llvm-project/mlir/test/Dialect/Vector/int-range-interface.mlir (revision 441b82b20bf3a622155354e17ae66e0ccff50796)
1// RUN: mlir-opt -int-range-optimizations -canonicalize %s | FileCheck %s
2
3
4// CHECK-LABEL: func @constant_vec
5// CHECK: test.reflect_bounds {smax = 7 : index, smin = 0 : index, umax = 7 : index, umin = 0 : index}
6func.func @constant_vec() -> vector<8xindex> {
7  %0 = arith.constant dense<[0, 1, 2, 3, 4, 5, 6, 7]> : vector<8xindex>
8  %1 = test.reflect_bounds %0 : vector<8xindex>
9  func.return %1 : vector<8xindex>
10}
11
12// CHECK-LABEL: func @constant_splat
13// CHECK: test.reflect_bounds {smax = 3 : si32, smin = 3 : si32, umax = 3 : ui32, umin = 3 : ui32}
14func.func @constant_splat() -> vector<8xi32> {
15  %0 = arith.constant dense<3> : vector<8xi32>
16  %1 = test.reflect_bounds %0 : vector<8xi32>
17  func.return %1 : vector<8xi32>
18}
19
20// CHECK-LABEL: func @float_constant_splat
21// Don't crash on splat floats.
22func.func @float_constant_splat() -> vector<8xf32> {
23  %0 = arith.constant dense<3.0> : vector<8xf32>
24  func.return %0: vector<8xf32>
25}
26
27// CHECK-LABEL: func @vector_splat
28// CHECK: test.reflect_bounds {smax = 5 : index, smin = 4 : index, umax = 5 : index, umin = 4 : index}
29func.func @vector_splat() -> vector<4xindex> {
30  %0 = test.with_bounds { umin = 4 : index, umax = 5 : index, smin = 4 : index, smax = 5 : index } : index
31  %1 = vector.splat %0 : vector<4xindex>
32  %2 = test.reflect_bounds %1 : vector<4xindex>
33  func.return %2 : vector<4xindex>
34}
35
36// CHECK-LABEL: func @vector_broadcast
37// CHECK: test.reflect_bounds {smax = 5 : index, smin = 4 : index, umax = 5 : index, umin = 4 : index}
38func.func @vector_broadcast() -> vector<4x16xindex> {
39  %0 = test.with_bounds { umin = 4 : index, umax = 5 : index, smin = 4 : index, smax = 5 : index } : vector<16xindex>
40  %1 = vector.broadcast %0 : vector<16xindex> to vector<4x16xindex>
41  %2 = test.reflect_bounds %1 : vector<4x16xindex>
42  func.return %2 : vector<4x16xindex>
43}
44
45// CHECK-LABEL: func @vector_shape_cast
46// CHECK: test.reflect_bounds {smax = 5 : index, smin = 4 : index, umax = 5 : index, umin = 4 : index}
47func.func @vector_shape_cast() -> vector<4x4xindex> {
48  %0 = test.with_bounds { umin = 4 : index, umax = 5 : index, smin = 4 : index, smax = 5 : index } : vector<16xindex>
49  %1 = vector.shape_cast %0 : vector<16xindex> to vector<4x4xindex>
50  %2 = test.reflect_bounds %1 : vector<4x4xindex>
51  func.return %2 : vector<4x4xindex>
52}
53
54// CHECK-LABEL: func @vector_extract
55// CHECK: test.reflect_bounds {smax = 6 : index, smin = 5 : index, umax = 6 : index, umin = 5 : index}
56func.func @vector_extract() -> index {
57  %0 = test.with_bounds { umin = 5 : index, umax = 6 : index, smin = 5 : index, smax = 6 : index } : vector<4xindex>
58  %1 = vector.extract %0[0] : index from vector<4xindex>
59  %2 = test.reflect_bounds %1 : index
60  func.return %2 : index
61}
62
63// CHECK-LABEL: func @vector_extractelement
64// CHECK: test.reflect_bounds {smax = 7 : index, smin = 6 : index, umax = 7 : index, umin = 6 : index}
65func.func @vector_extractelement() -> index {
66  %c0 = arith.constant 0 : index
67  %0 = test.with_bounds { umin = 6 : index, umax = 7 : index, smin = 6 : index, smax = 7 : index } : vector<4xindex>
68  %1 = vector.extractelement %0[%c0 : index] : vector<4xindex>
69  %2 = test.reflect_bounds %1 : index
70  func.return %2 : index
71}
72
73// CHECK-LABEL: func @vector_add
74// CHECK: test.reflect_bounds {smax = 12 : index, smin = 10 : index, umax = 12 : index, umin = 10 : index}
75func.func @vector_add() -> vector<4xindex> {
76  %0 = test.with_bounds { umin = 4 : index, umax = 5 : index, smin = 4 : index, smax = 5 : index } : vector<4xindex>
77  %1 = test.with_bounds { umin = 6 : index, umax = 7 : index, smin = 6 : index, smax = 7 : index } : vector<4xindex>
78  %2 = arith.addi %0, %1 : vector<4xindex>
79  %3 = test.reflect_bounds %2 : vector<4xindex>
80  func.return %3 : vector<4xindex>
81}
82
83// CHECK-LABEL: func @vector_insert
84// CHECK: test.reflect_bounds {smax = 8 : index, smin = 5 : index, umax = 8 : index, umin = 5 : index}
85func.func @vector_insert() -> vector<4xindex> {
86  %0 = test.with_bounds { umin = 5 : index, umax = 7 : index, smin = 5 : index, smax = 7 : index } : vector<4xindex>
87  %1 = test.with_bounds { umin = 6 : index, umax = 8 : index, smin = 6 : index, smax = 8 : index } : index
88  %2 = vector.insert %1, %0[0] : index into vector<4xindex>
89  %3 = test.reflect_bounds %2 : vector<4xindex>
90  func.return %3 : vector<4xindex>
91}
92
93// CHECK-LABEL: func @vector_insertelement
94// CHECK: test.reflect_bounds {smax = 8 : index, smin = 5 : index, umax = 8 : index, umin = 5 : index}
95func.func @vector_insertelement() -> vector<4xindex> {
96  %c0 = arith.constant 0 : index
97  %0 = test.with_bounds { umin = 5 : index, umax = 7 : index, smin = 5 : index, smax = 7 : index } : vector<4xindex>
98  %1 = test.with_bounds { umin = 6 : index, umax = 8 : index, smin = 6 : index, smax = 8 : index } : index
99  %2 = vector.insertelement %1, %0[%c0 : index] : vector<4xindex>
100  %3 = test.reflect_bounds %2 : vector<4xindex>
101  func.return %3 : vector<4xindex>
102}
103
104// CHECK-LABEL: func @test_loaded_vector_extract
105// No bounds
106// CHECK: test.reflect_bounds {smax = 2147483647 : si32, smin = -2147483648 : si32, umax = 4294967295 : ui32, umin = 0 : ui32} %{{.*}} : i32
107func.func @test_loaded_vector_extract(%memref : memref<16xi32>) -> i32 {
108  %c0 = arith.constant 0 : index
109  %v = vector.load %memref[%c0] : memref<16xi32>, vector<4xi32>
110  %e = vector.extract %v[0] : i32 from vector<4xi32>
111  %bounds = test.reflect_bounds %e : i32
112  func.return %bounds : i32
113}
114
115// CHECK-LABEL: func @test_vector_extsi
116// CHECK: test.reflect_bounds {smax = 5 : si32, smin = 1 : si32, umax = 5 : ui32, umin = 1 : ui32}
117func.func @test_vector_extsi() -> vector<2xi32> {
118  %0 = test.with_bounds {smax = 5 : si8, smin = 1 : si8, umax = 5 : ui8, umin = 1 : ui8 } : vector<2xi8>
119  %1 = arith.extsi %0 : vector<2xi8> to vector<2xi32>
120  %2 = test.reflect_bounds %1 : vector<2xi32>
121  func.return %2 : vector<2xi32>
122}
123