|
| 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} |
| 6 | +func.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} |
| 14 | +func.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 @vector_splat |
| 21 | +// CHECK: test.reflect_bounds {smax = 5 : index, smin = 4 : index, umax = 5 : index, umin = 4 : index} |
| 22 | +func.func @vector_splat() -> vector<4xindex> { |
| 23 | + %0 = test.with_bounds { umin = 4 : index, umax = 5 : index, smin = 4 : index, smax = 5 : index } : index |
| 24 | + %1 = vector.splat %0 : vector<4xindex> |
| 25 | + %2 = test.reflect_bounds %1 : vector<4xindex> |
| 26 | + func.return %2 : vector<4xindex> |
| 27 | +} |
| 28 | + |
| 29 | +// CHECK-LABEL: func @vector_broadcast |
| 30 | +// CHECK: test.reflect_bounds {smax = 5 : index, smin = 4 : index, umax = 5 : index, umin = 4 : index} |
| 31 | +func.func @vector_broadcast() -> vector<4x16xindex> { |
| 32 | + %0 = test.with_bounds { umin = 4 : index, umax = 5 : index, smin = 4 : index, smax = 5 : index } : vector<16xindex> |
| 33 | + %1 = vector.broadcast %0 : vector<16xindex> to vector<4x16xindex> |
| 34 | + %2 = test.reflect_bounds %1 : vector<4x16xindex> |
| 35 | + func.return %2 : vector<4x16xindex> |
| 36 | +} |
| 37 | + |
| 38 | +// CHECK-LABEL: func @vector_shape_cast |
| 39 | +// CHECK: test.reflect_bounds {smax = 5 : index, smin = 4 : index, umax = 5 : index, umin = 4 : index} |
| 40 | +func.func @vector_shape_cast() -> vector<4x4xindex> { |
| 41 | + %0 = test.with_bounds { umin = 4 : index, umax = 5 : index, smin = 4 : index, smax = 5 : index } : vector<16xindex> |
| 42 | + %1 = vector.shape_cast %0 : vector<16xindex> to vector<4x4xindex> |
| 43 | + %2 = test.reflect_bounds %1 : vector<4x4xindex> |
| 44 | + func.return %2 : vector<4x4xindex> |
| 45 | +} |
| 46 | + |
| 47 | +// CHECK-LABEL: func @vector_extract |
| 48 | +// CHECK: test.reflect_bounds {smax = 6 : index, smin = 5 : index, umax = 6 : index, umin = 5 : index} |
| 49 | +func.func @vector_extract() -> index { |
| 50 | + %0 = test.with_bounds { umin = 5 : index, umax = 6 : index, smin = 5 : index, smax = 6 : index } : vector<4xindex> |
| 51 | + %1 = vector.extract %0[0] : index from vector<4xindex> |
| 52 | + %2 = test.reflect_bounds %1 : index |
| 53 | + func.return %2 : index |
| 54 | +} |
| 55 | + |
| 56 | +// CHECK-LABEL: func @vector_extractelement |
| 57 | +// CHECK: test.reflect_bounds {smax = 7 : index, smin = 6 : index, umax = 7 : index, umin = 6 : index} |
| 58 | +func.func @vector_extractelement() -> index { |
| 59 | + %c0 = arith.constant 0 : index |
| 60 | + %0 = test.with_bounds { umin = 6 : index, umax = 7 : index, smin = 6 : index, smax = 7 : index } : vector<4xindex> |
| 61 | + %1 = vector.extractelement %0[%c0 : index] : vector<4xindex> |
| 62 | + %2 = test.reflect_bounds %1 : index |
| 63 | + func.return %2 : index |
| 64 | +} |
| 65 | + |
| 66 | +// CHECK-LABEL: func @vector_add |
| 67 | +// CHECK: test.reflect_bounds {smax = 12 : index, smin = 10 : index, umax = 12 : index, umin = 10 : index} |
| 68 | +func.func @vector_add() -> vector<4xindex> { |
| 69 | + %0 = test.with_bounds { umin = 4 : index, umax = 5 : index, smin = 4 : index, smax = 5 : index } : vector<4xindex> |
| 70 | + %1 = test.with_bounds { umin = 6 : index, umax = 7 : index, smin = 6 : index, smax = 7 : index } : vector<4xindex> |
| 71 | + %2 = arith.addi %0, %1 : vector<4xindex> |
| 72 | + %3 = test.reflect_bounds %2 : vector<4xindex> |
| 73 | + func.return %3 : vector<4xindex> |
| 74 | +} |
| 75 | + |
| 76 | +// CHECK-LABEL: func @vector_insert |
| 77 | +// CHECK: test.reflect_bounds {smax = 8 : index, smin = 5 : index, umax = 8 : index, umin = 5 : index} |
| 78 | +func.func @vector_insert() -> vector<4xindex> { |
| 79 | + %0 = test.with_bounds { umin = 5 : index, umax = 7 : index, smin = 5 : index, smax = 7 : index } : vector<4xindex> |
| 80 | + %1 = test.with_bounds { umin = 6 : index, umax = 8 : index, smin = 6 : index, smax = 8 : index } : index |
| 81 | + %2 = vector.insert %1, %0[0] : index into vector<4xindex> |
| 82 | + %3 = test.reflect_bounds %2 : vector<4xindex> |
| 83 | + func.return %3 : vector<4xindex> |
| 84 | +} |
| 85 | + |
| 86 | +// CHECK-LABEL: func @vector_insertelement |
| 87 | +// CHECK: test.reflect_bounds {smax = 8 : index, smin = 5 : index, umax = 8 : index, umin = 5 : index} |
| 88 | +func.func @vector_insertelement() -> vector<4xindex> { |
| 89 | + %c0 = arith.constant 0 : index |
| 90 | + %0 = test.with_bounds { umin = 5 : index, umax = 7 : index, smin = 5 : index, smax = 7 : index } : vector<4xindex> |
| 91 | + %1 = test.with_bounds { umin = 6 : index, umax = 8 : index, smin = 6 : index, smax = 8 : index } : index |
| 92 | + %2 = vector.insertelement %1, %0[%c0 : index] : vector<4xindex> |
| 93 | + %3 = test.reflect_bounds %2 : vector<4xindex> |
| 94 | + func.return %3 : vector<4xindex> |
| 95 | +} |
| 96 | + |
| 97 | +// CHECK-LABEL: func @test_loaded_vector_extract |
| 98 | +// No bounds |
| 99 | +// CHECK: test.reflect_bounds %{{.*}} : i32 |
| 100 | +func.func @test_loaded_vector_extract(%memref : memref<16xi32>) -> i32 { |
| 101 | + %c0 = arith.constant 0 : index |
| 102 | + %v = vector.load %memref[%c0] : memref<16xi32>, vector<4xi32> |
| 103 | + %e = vector.extract %v[0] : i32 from vector<4xi32> |
| 104 | + %bounds = test.reflect_bounds %e : i32 |
| 105 | + func.return %bounds : i32 |
| 106 | +} |
0 commit comments