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