|
| 1 | +// RUN: mlir-opt --arm-sve-legalize-vector-storage --split-input-file %s | FileCheck %s |
| 2 | + |
| 3 | +// ----- |
| 4 | + |
| 5 | +// CHECK-LABEL: @test_base_case |
| 6 | +// CHECK-SAME: %[[I:arg0]]: index, %[[J:arg1]]: index, %[[M:arg2]]: |
| 7 | +// CHECK: %[[COLLAPSE:.+]] = memref.collapse_shape %[[M]] |
| 8 | +// CHECK-SAME{LITERAL}: [[0], [1], [2, 3]] |
| 9 | +// CHECK-SAME: : memref<?x?x?x8xi8> into memref<?x?x?xi8> |
| 10 | +// CHECK-NEXT: %[[T0:.+]] = vector.transfer_read %[[COLLAPSE]][%[[I]], %[[J]], %c0], %c0_i8 {in_bounds = [true]} |
| 11 | +// CHECK-SAME: : memref<?x?x?xi8>, vector<[32]xi8> |
| 12 | +// CHECK-NEXT: %[[T1:.+]] = vector.shape_cast %[[T0]] : vector<[32]xi8> to vector<[4]x8xi8> |
| 13 | +// CHECK-NEXT: return %[[T1]] : vector<[4]x8xi8> |
| 14 | + |
| 15 | +func.func @test_base_case(%i : index, %j : index, %M : memref<?x?x?x8xi8>) -> vector<[4]x8xi8> { |
| 16 | + %c0 = arith.constant 0 : index |
| 17 | + %c0_i8 = arith.constant 0 : i8 |
| 18 | + |
| 19 | + %A = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 {in_bounds = [true, true]} : memref<?x?x?x8xi8>, vector<[4]x8xi8> |
| 20 | + |
| 21 | + return %A : vector<[4]x8xi8> |
| 22 | +} |
| 23 | + |
| 24 | +// ----- |
| 25 | + |
| 26 | +// CHECK-LABEL: @test_using_strided_layout |
| 27 | +// CHECK-SAME: %[[I:arg0]]: index, %[[J:arg1]]: index, %[[M:arg2]] |
| 28 | +// CHECK: %[[COLLAPSE:.+]] = memref.collapse_shape %[[M]] |
| 29 | +// CHECK-SAME{LITERAL}: [[0], [1], [2, 3]] |
| 30 | +// CHECK-SAME: : memref<?x?x?x8xi8, strided<[?, ?, 8, 1]>> into |
| 31 | +// CHECK-SAME: memref<?x?x?xi8, strided<[?, ?, 1]>> |
| 32 | +// CHECK-NEXT: %[[T0:.+]] = vector.transfer_read %[[COLLAPSE]][%[[I]], %[[J]], %c0], %c0_i8 {in_bounds = [true]} |
| 33 | +// CHECK-SAME: : memref<?x?x?xi8, strided<[?, ?, 1]>>, vector<[32]xi8> |
| 34 | +// CHECK-NEXT: %[[T1:.+]] = vector.shape_cast %[[T0]] : vector<[32]xi8> to vector<[4]x8xi8> |
| 35 | +// CHECK-NEXT: return %[[T1]] : vector<[4]x8xi8> |
| 36 | + |
| 37 | +#s0 = strided<[?, ?, 8, 1]> |
| 38 | + |
| 39 | +func.func @test_using_strided_layout(%i : index, %j : index, %M : memref<?x?x?x8xi8, #s0>) -> vector<[4]x8xi8> { |
| 40 | + %c0 = arith.constant 0 : index |
| 41 | + %c0_i8 = arith.constant 0 : i8 |
| 42 | + |
| 43 | + %A = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 {in_bounds = [true, true]} : memref<?x?x?x8xi8, #s0>, vector<[4]x8xi8> |
| 44 | + |
| 45 | + return %A : vector<[4]x8xi8> |
| 46 | +} |
| 47 | + |
| 48 | +// ----- |
| 49 | + |
| 50 | +// CHECK-LABEL: @test_3d_vector |
| 51 | +// CHECK-SAME: %[[I:arg0]]: index, %[[J:arg1]]: index, %[[M:arg2]] |
| 52 | +// CHECK: %[[COLLAPSED:.+]] = memref.collapse_shape %[[M]] |
| 53 | +// CHECK-SAME{LITERAL}: [[0], [1, 2, 3]] |
| 54 | +// CHECK-SAME: : memref<?x?x2x8xi8, strided<[?, 16, 8, 1]>> into |
| 55 | +// CHECK-SAME: memref<?x?xi8, strided<[?, 1]>> |
| 56 | +// CHECK-NEXT: %[[T0:.+]] = vector.transfer_read %[[COLLAPSED]][%[[I]], %[[J]]], %c0_i8 {in_bounds = [true]} |
| 57 | +// CHECK-SAME: : memref<?x?xi8, strided<[?, 1]>>, vector<[64]xi8> |
| 58 | +// CHECK-NEXT: %[[T1:.+]] = vector.shape_cast %[[T0]] : vector<[64]xi8> to vector<[4]x2x8xi8> |
| 59 | +// CHECK-NEXT: return %[[T1]] : vector<[4]x2x8xi8> |
| 60 | + |
| 61 | +#s1 = strided<[?, 16, 8, 1]> |
| 62 | + |
| 63 | +func.func @test_3d_vector(%i : index, %j : index, %M : memref<?x?x2x8xi8, #s1>) -> vector<[4]x2x8xi8> { |
| 64 | + %c0 = arith.constant 0 : index |
| 65 | + %c0_i8 = arith.constant 0 : i8 |
| 66 | + |
| 67 | + %A = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 {in_bounds = [true, true, true]} : memref<?x?x2x8xi8, #s1>, vector<[4]x2x8xi8> |
| 68 | + |
| 69 | + return %A : vector<[4]x2x8xi8> |
| 70 | +} |
| 71 | + |
| 72 | +// ----- |
| 73 | + |
| 74 | +// CHECK-LABEL: @test_4d_vector |
| 75 | +// CHECK-SAME: %[[I:arg0]]: index, %[[J:arg1]]: index, %[[M:arg2]] |
| 76 | +// CHECK: %[[COLLAPSED:.+]] = memref.collapse_shape %[[M]] |
| 77 | +// CHECK-SAME{LITERAL}: [[0], [1, 2, 3]] |
| 78 | +// CHECK-SAME: : memref<?x?x2x8xi8, strided<[?, 16, 8, 1]>> into |
| 79 | +// CHECK-SAME: memref<?x?xi8, strided<[?, 1]>> |
| 80 | +// CHECK-NEXT: %[[T0:.+]] = vector.transfer_read %[[COLLAPSED]][%[[I]], %[[J]]], %c0_i8 {in_bounds = [false, true]} |
| 81 | +// CHECK-SAME: : memref<?x?xi8, strided<[?, 1]>>, vector<2x[64]xi8> |
| 82 | +// CHECK-NEXT: %[[T1:.+]] = vector.shape_cast %[[T0]] : vector<2x[64]xi8> to vector<2x[4]x2x8xi8> |
| 83 | +// CHECK-NEXT: return %[[T1]] : vector<2x[4]x2x8xi8> |
| 84 | + |
| 85 | +#s2 = strided<[?, 16, 8, 1]> |
| 86 | + |
| 87 | +func.func @test_4d_vector(%i : index, %j : index, %M : memref<?x?x2x8xi8, #s2>) -> vector<2x[4]x2x8xi8> { |
| 88 | + %c0 = arith.constant 0 : index |
| 89 | + %c0_i8 = arith.constant 0 : i8 |
| 90 | + |
| 91 | + %A = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 {in_bounds = [false, true, true, true]} : memref<?x?x2x8xi8, #s2>, vector<2x[4]x2x8xi8> |
| 92 | + |
| 93 | + return %A : vector<2x[4]x2x8xi8> |
| 94 | +} |
| 95 | + |
| 96 | +// ----- |
| 97 | + |
| 98 | +// CHECK-LABEL: @negative_test_vector_legal_non_scalable |
| 99 | +// CHECK-NOT: memref.collapse |
| 100 | + |
| 101 | +func.func @negative_test_vector_legal_non_scalable(%i : index, %j : index, %M : memref<?x?x?x8xi8>) -> vector<8x8xi8> { |
| 102 | + %c0 = arith.constant 0 : index |
| 103 | + %c0_i8 = arith.constant 0 : i8 |
| 104 | + |
| 105 | + %A = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 {in_bounds = [true, true]} : memref<?x?x?x8xi8>, vector<8x8xi8> |
| 106 | + |
| 107 | + return %A : vector<8x8xi8> |
| 108 | +} |
| 109 | + |
| 110 | +// ----- |
| 111 | + |
| 112 | +// CHECK-LABEL: @negative_test_vector_legal_scalable_0 |
| 113 | +// CHECK-NOT: memref.collapse |
| 114 | + |
| 115 | +func.func @negative_test_vector_legal_scalable_0(%i : index, %j : index, %M : memref<?x?x?x8xi8>) -> vector<[8]xi8> { |
| 116 | + %c0 = arith.constant 0 : index |
| 117 | + %c0_i8 = arith.constant 0 : i8 |
| 118 | + |
| 119 | + %A = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 {in_bounds = [true]} : memref<?x?x?x8xi8>, vector<[8]xi8> |
| 120 | + |
| 121 | + return %A : vector<[8]xi8> |
| 122 | +} |
| 123 | + |
| 124 | +// ----- |
| 125 | + |
| 126 | +// CHECK-LABEL: @negative_test_vector_legal_scalable_1 |
| 127 | +// CHECK-NOT: memref.collapse |
| 128 | + |
| 129 | +func.func @negative_test_vector_legal_scalable_1(%i : index, %j : index, %M : memref<?x?x?x8xi8>) -> vector<8x[8]xi8> { |
| 130 | + %c0 = arith.constant 0 : index |
| 131 | + %c0_i8 = arith.constant 0 : i8 |
| 132 | + |
| 133 | + %A = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 {in_bounds = [true, true]} : memref<?x?x?x8xi8>, vector<8x[8]xi8> |
| 134 | + |
| 135 | + return %A : vector<8x[8]xi8> |
| 136 | +} |
| 137 | + |
| 138 | +// ----- |
| 139 | + |
| 140 | +// CHECK-LABEL: @negative_test_vector_type_not_supported |
| 141 | +// CHECK-NOT: memref.collapse |
| 142 | + |
| 143 | +func.func @negative_test_vector_type_not_supported(%i : index, %j : index, %M : memref<?x?x?x8xi8>) -> vector<[8]x[8]x8xi8> { |
| 144 | + %c0 = arith.constant 0 : index |
| 145 | + %c0_i8 = arith.constant 0 : i8 |
| 146 | + |
| 147 | + %A = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 {in_bounds = [true, true, true]} : memref<?x?x?x8xi8>, vector<[8]x[8]x8xi8> |
| 148 | + |
| 149 | + return %A : vector<[8]x[8]x8xi8> |
| 150 | +} |
| 151 | + |
| 152 | +// ----- |
| 153 | + |
| 154 | +// CHECK-LABEL: @negative_test_non_mem |
| 155 | +// CHECK-NOT: memref.collapse |
| 156 | + |
| 157 | +func.func @negative_test_non_mem(%i : index, %j : index, %M : tensor<?x?x?x8xi8>) -> vector<[4]x8xi8> { |
| 158 | + %c0 = arith.constant 0 : index |
| 159 | + %c0_i8 = arith.constant 0 : i8 |
| 160 | + |
| 161 | + %A = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 {in_bounds = [true, true]} : tensor<?x?x?x8xi8>, vector<[4]x8xi8> |
| 162 | + |
| 163 | + return %A : vector<[4]x8xi8> |
| 164 | +} |
| 165 | + |
| 166 | +// ----- |
| 167 | + |
| 168 | +// CHECK-LABEL: @negative_test_discontig_mem_0 |
| 169 | +// CHECK-NOT: memref.collapse |
| 170 | + |
| 171 | +#s3 = strided<[?, ?, 16, 1]> |
| 172 | + |
| 173 | +func.func @negative_test_discontig_mem_0(%i : index, %j : index, %M : memref<?x?x?x8xi8, #s3>) -> vector<[4]x8xi8> { |
| 174 | + %c0 = arith.constant 0 : index |
| 175 | + %c0_i8 = arith.constant 0 : i8 |
| 176 | + |
| 177 | + %A = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 {in_bounds = [true, true]} : memref<?x?x?x8xi8, #s3>, vector<[4]x8xi8> |
| 178 | + |
| 179 | + return %A : vector<[4]x8xi8> |
| 180 | +} |
| 181 | + |
| 182 | +// ----- |
| 183 | + |
| 184 | +// CHECK-LABEL: @negative_test_discontig_mem_1 |
| 185 | +// CHECK-NOT: memref.collapse |
| 186 | + |
| 187 | +#layout = affine_map<(i, j, k, p) -> (j, i, k, p)> |
| 188 | + |
| 189 | +func.func @negative_test_discontig_mem_1(%i : index, %j : index, %M : memref<?x?x?x8xi8, #layout>) -> vector<[4]x8xi8> { |
| 190 | + %c0 = arith.constant 0 : index |
| 191 | + %c0_i8 = arith.constant 0 : i8 |
| 192 | + |
| 193 | + %A = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 {in_bounds = [true, true]} : memref<?x?x?x8xi8, #layout>, vector<[4]x8xi8> |
| 194 | + |
| 195 | + return %A : vector<[4]x8xi8> |
| 196 | +} |
| 197 | + |
| 198 | +// ----- |
| 199 | + |
| 200 | +// CHECK-LABEL: @negative_test_discontig_read_strided_vec |
| 201 | +// CHECK-NOT: memref.collapse |
| 202 | + |
| 203 | +func.func @negative_test_discontig_read_strided_vec(%i : index, %j : index, %M : memref<?x?x?x8xi8>) -> vector<[4]x4xi8> { |
| 204 | + %c0 = arith.constant 0 : index |
| 205 | + %c0_i8 = arith.constant 0 : i8 |
| 206 | + |
| 207 | + %A = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 {in_bounds = [true, true]} : memref<?x?x?x8xi8>, vector<[4]x4xi8> |
| 208 | + |
| 209 | + return %A : vector<[4]x4xi8> |
| 210 | +} |
| 211 | + |
| 212 | +// ----- |
| 213 | + |
| 214 | +// CHECK-LABEL: @negative_test_bcast_transp |
| 215 | +// CHECK-NOT: memref.collapse |
| 216 | + |
| 217 | +#perm = affine_map<(i, j, k, p) -> (k, 0)> |
| 218 | + |
| 219 | +func.func @negative_test_bcast_transp(%i : index, %j : index, %M : memref<?x?x?x8xi8>) -> vector<[4]x8xi8> { |
| 220 | + %c0 = arith.constant 0 : index |
| 221 | + %c0_i8 = arith.constant 0 : i8 |
| 222 | + |
| 223 | + %A = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 {permutation_map = #perm, in_bounds = [true, true] } : memref<?x?x?x8xi8>, vector<[4]x8xi8> |
| 224 | + |
| 225 | + return %A : vector<[4]x8xi8> |
| 226 | +} |
0 commit comments