1// RUN: mlir-opt %s -split-input-file -test-vector-linearize -verify-diagnostics | FileCheck %s --check-prefixes=ALL,DEFAULT 2// RUN: mlir-opt %s -split-input-file -test-vector-linearize=target-vector-bitwidth=128 -verify-diagnostics | FileCheck %s --check-prefixes=ALL,BW-128 3// RUN: mlir-opt %s -split-input-file -test-vector-linearize=target-vector-bitwidth=0 | FileCheck %s --check-prefixes=ALL,BW-0 4 5// ALL-LABEL: test_linearize 6// ALL-SAME: (%[[ORIG_ARG:.*]]: vector<2x2xf32>) 7func.func @test_linearize(%arg0: vector<2x2xf32>) -> vector<2x2xf32> { 8 // DEFAULT: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x2xf32> to vector<4xf32> 9 // DEFAULT: %[[CST:.*]] = arith.constant dense<[1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00]> : vector<4xf32> 10 // DEFAULT: %[[RES:.*]] = vector.shape_cast %[[CST]] : vector<4xf32> to vector<2x2xf32> 11 12 // BW-128: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x2xf32> to vector<4xf32> 13 // BW-128: %[[CST:.*]] = arith.constant dense<[1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00]> : vector<4xf32> 14 // BW-128: %[[RES:.*]] = vector.shape_cast %[[CST]] : vector<4xf32> to vector<2x2xf32> 15 16 // BW-0: %[[RES:.*]] = arith.constant dense<{{.*}}> : vector<2x2xf32> 17 %0 = arith.constant dense<[[1.0, 2.0], [3.0, 4.0]]> : vector<2x2xf32> 18 19 // DEFAULT: %{{.*}} = math.sin %[[ARG]] : vector<4xf32> 20 // BW-128: %{{.*}} = math.sin %[[ARG]] : vector<4xf32> 21 // BW-0: %{{.*}} = math.sin %{{.*}} : vector<2x2xf32> 22 %1 = math.sin %arg0 : vector<2x2xf32> 23 24 // DEFAULT: %{{.*}} = arith.addf %[[ARG]], %[[CST]] : vector<4xf32> 25 // BW-128: %{{.*}} = arith.addf %[[ARG]], %[[CST]] : vector<4xf32> 26 // BW-0: %{{.*}} = arith.addf %{{.*}} : vector<2x2xf32> 27 %2 = arith.addf %arg0, %0 : vector<2x2xf32> 28 29 // ALL: return %[[RES]] : vector<2x2xf32> 30 return %0 : vector<2x2xf32> 31} 32 33// ----- 34 35// ALL-LABEL: test_partial_linearize 36// ALL-SAME: (%[[ORIG_ARG:.*]]: vector<2x2xf32>, %[[ORIG_ARG2:.*]]: vector<4x4xf32>) 37func.func @test_partial_linearize(%arg0: vector<2x2xf32>, %arg1: vector<4x4xf32>) -> vector<2x2xf32> { 38 // DEFAULT-DAG: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x2xf32> to vector<4xf32> 39 // DEFAULT-DAG: %[[ARG2:.*]] = vector.shape_cast %[[ORIG_ARG2]] : vector<4x4xf32> to vector<16xf32> 40 // DEFAULT: %[[CST:.*]] = arith.constant dense<{{.*}}> : vector<4xf32> 41 // DEFAULT: %[[RES:.*]] = vector.shape_cast %[[CST]] : vector<4xf32> to vector<2x2xf32> 42 43 // BW-128: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x2xf32> to vector<4xf32> 44 // BW-128: %[[CST:.*]] = arith.constant dense<{{.*}}> : vector<4xf32> 45 // BW-128: %[[RES:.*]] = vector.shape_cast %[[CST]] : vector<4xf32> to vector<2x2xf32> 46 47 // BW-0: %[[RES:.*]] = arith.constant dense<{{.*}}> : vector<2x2xf32> 48 %0 = arith.constant dense<[[1.0, 2.0], [3.0, 4.0]]> : vector<2x2xf32> 49 50 // DEFAULT: %[[C2:.*]] = arith.constant dense<{{.*}}> : vector<16xf32> 51 // BW-128: %[[C2:.*]] = arith.constant dense<{{.*}}> : vector<4x4xf32> 52 // BW-0: %[[C2:.*]] = arith.constant dense<{{.*}}> : vector<4x4xf32> 53 %5 = arith.constant dense<[[1.0, 2.0, 3.0, 4.0], [1.0, 2.0,3.0, 4.0], [1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 5.0, 6.0]]> : vector<4x4xf32> 54 55 // Arith and math ops are handled in generic way, check some of them 56 // DEFAULT: %[[SIN:.*]] = math.sin %[[ARG]] : vector<4xf32> 57 // BW-128: %[[SIN:.*]] = math.sin %[[ARG]] : vector<4xf32> 58 // BW-0: %[[SIN:.*]] = math.sin %[[ORIG_ARG]] : vector<2x2xf32> 59 %1 = math.sin %arg0 : vector<2x2xf32> 60 61 // DEFAULT: %[[SIN1:.*]] = math.sin %[[ARG2]] : vector<16xf32> 62 // BW-128: %[[SIN1:.*]] = math.sin %[[ORIG_ARG2]] : vector<4x4xf32> 63 // BW-0: %[[SIN1:.*]] = math.sin %[[ORIG_ARG2]] : vector<4x4xf32> 64 %6 = math.sin %arg1 : vector<4x4xf32> 65 66 // DEFAULT: %{{.*}} = arith.addf %[[ARG]], %[[CST]] : vector<4xf32> 67 // BW-128: %{{.*}} = arith.addf %[[ARG]], %[[CST]] : vector<4xf32> 68 // BW-0: %{{.*}} = arith.addf %{{.*}} : vector<2x2xf32> 69 %2 = arith.addf %arg0, %0 : vector<2x2xf32> 70 71 // DEFAULT: %[[ADD2:.*]] = arith.addf %[[ARG2]], %[[C2]] : vector<16xf32> 72 // BW-128: %[[ADD2:.*]] = arith.addf %[[ORIG_ARG2]], %[[C2]] : vector<4x4xf32> 73 // BW-0: %[[ADD2:.*]] = arith.addf %[[ORIG_ARG2]], %[[C2]] : vector<4x4xf32> 74 %7 = arith.addf %arg1, %5 : vector<4x4xf32> 75 76 // ALL: return %[[RES]] : vector<2x2xf32> 77 return %0 : vector<2x2xf32> 78} 79 80// ----- 81 82// ALL-LABEL: test_index_no_linearize 83func.func @test_index_no_linearize(%arg0: vector<2x2xindex>, %arg1: vector<2x2xindex>) -> vector<2x2xindex> { 84 // ALL: %[[ADD:.*]] = arith.addi {{.*}} : vector<2x2xindex> 85 %0 = arith.addi %arg0, %arg1 : vector<2x2xindex> 86 return %0 : vector<2x2xindex> 87} 88 89// ----- 90 91// vectorizable operation (arith.mulf) with tensor result types. 92 93// ALL-LABEL: test_tensor_no_linearize 94func.func @test_tensor_no_linearize(%arg0: tensor<2x2xf32>, %arg1: tensor<2x2xf32>) -> (tensor<2x2xf32>, tensor<2x2xf32>) { 95 // ALL: %[[MULF:.*]] = arith.mulf %arg0, %arg1 : tensor<2x2xf32> 96 %0 = arith.mulf %arg0, %arg1 : tensor<2x2xf32> 97 98 return %0, %arg0 : tensor<2x2xf32>, tensor<2x2xf32> 99} 100 101// ----- 102 103// ALL-LABEL: func.func @test_scalable_linearize( 104// ALL-SAME: %[[ARG_0:.*]]: vector<2x[2]xf32>) -> vector<2x[2]xf32> { 105func.func @test_scalable_linearize(%arg0: vector<2x[2]xf32>) -> vector<2x[2]xf32> { 106 // DEFAULT: %[[SC:.*]] = vector.shape_cast %[[ARG_0]] : vector<2x[2]xf32> to vector<[4]xf32> 107 // DEFAULT: %[[CST:.*]] = arith.constant dense<3.000000e+00> : vector<[4]xf32> 108 // BW-128: %[[SC:.*]] = vector.shape_cast %[[ARG_0]] : vector<2x[2]xf32> to vector<[4]xf32> 109 // BW-128: %[[CST:.*]] = arith.constant dense<3.000000e+00> : vector<[4]xf32> 110 // BW-0: %[[CST:.*]] = arith.constant dense<3.000000e+00> : vector<2x[2]xf32> 111 %0 = arith.constant dense<[[3., 3.], [3., 3.]]> : vector<2x[2]xf32> 112 113 // DEFAULT: %[[SIN:.*]] = math.sin %[[SC]] : vector<[4]xf32> 114 // BW-128: %[[SIN:.*]] = math.sin %[[SC]] : vector<[4]xf32> 115 // BW-0: %[[SIN:.*]] = math.sin %[[ARG_0]] : vector<2x[2]xf32> 116 %1 = math.sin %arg0 : vector<2x[2]xf32> 117 118 // DEFAULT: %[[ADDF:.*]] = arith.addf %[[SIN]], %[[CST]] : vector<[4]xf32> 119 // BW-128: %[[ADDF:.*]] = arith.addf %[[SIN]], %[[CST]] : vector<[4]xf32> 120 // BW-0: %[[RES:.*]] = arith.addf %[[CST]], %[[SIN]] : vector<2x[2]xf32> 121 %2 = arith.addf %0, %1 : vector<2x[2]xf32> 122 123 // DEFAULT: %[[RES:.*]] = vector.shape_cast %[[ADDF]] : vector<[4]xf32> to vector<2x[2]xf32> 124 // BW-128: %[[RES:.*]] = vector.shape_cast %[[ADDF]] : vector<[4]xf32> to vector<2x[2]xf32> 125 // ALL: return %[[RES]] : vector<2x[2]xf32> 126 return %2 : vector<2x[2]xf32> 127} 128 129// ----- 130 131// ALL-LABEL: func.func @test_scalable_no_linearize( 132// ALL-SAME: %[[VAL_0:.*]]: vector<[2]x[2]xf32>) -> vector<[2]x[2]xf32> { 133func.func @test_scalable_no_linearize(%arg0: vector<[2]x[2]xf32>) -> vector<[2]x[2]xf32> { 134 // ALL: %[[CST:.*]] = arith.constant dense<2.000000e+00> : vector<[2]x[2]xf32> 135 %0 = arith.constant dense<[[2., 2.], [2., 2.]]> : vector<[2]x[2]xf32> 136 137 // ALL: %[[SIN:.*]] = math.sin %[[VAL_0]] : vector<[2]x[2]xf32> 138 %1 = math.sin %arg0 : vector<[2]x[2]xf32> 139 140 // ALL: %[[RES:.*]] = arith.addf %[[CST]], %[[SIN]] : vector<[2]x[2]xf32> 141 %2 = arith.addf %0, %1 : vector<[2]x[2]xf32> 142 143 // ALL: return %[[RES]] : vector<[2]x[2]xf32> 144 return %2 : vector<[2]x[2]xf32> 145} 146 147// ----- 148 149// ALL-LABEL: func.func @test_0d_vector 150func.func @test_0d_vector() -> vector<f32> { 151 // ALL: %[[CST:.+]] = arith.constant dense<0.000000e+00> : vector<f32> 152 %0 = arith.constant dense<0.0> : vector<f32> 153 // ALL: return %[[CST]] 154 return %0 : vector<f32> 155} 156 157// ----- 158// ALL-LABEL: test_extract_strided_slice_1 159// ALL-SAME: (%[[ORIG_ARG:.*]]: vector<4x8xf32>) -> vector<2x2xf32> { 160func.func @test_extract_strided_slice_1(%arg0 : vector<4x8xf32>) -> vector<2x2xf32> { 161 // DEFAULT: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<4x8xf32> to vector<32xf32> 162 // DEFAULT: %[[SHUFFLE:.*]] = vector.shuffle %[[ARG]], %[[ARG]] 163 // DEFAULT-SAME: [4, 5, 12, 13] : vector<32xf32>, vector<32xf32> 164 // DEFAULT: %[[RES:.*]] = vector.shape_cast %[[SHUFFLE]] : vector<4xf32> to vector<2x2xf32> 165 // DEFAULT: return %[[RES]] : vector<2x2xf32 166 167 // BW-128: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<4x8xf32> to vector<32xf32> 168 // BW-128: %[[SHUFFLE:.*]] = vector.shuffle %[[ARG]], %[[ARG]] 169 // BW-128-SAME: [4, 5, 12, 13] : vector<32xf32>, vector<32xf32> 170 // BW-128: %[[RES:.*]] = vector.shape_cast %[[SHUFFLE]] : vector<4xf32> to vector<2x2xf32> 171 // BW-128: return %[[RES]] : vector<2x2xf32> 172 173 // BW-0: %[[RES:.*]] = vector.extract_strided_slice %[[ARG:.*]] {offsets = [0, 4], sizes = [2, 2], strides = [1, 1]} : vector<4x8xf32> to vector<2x2xf32> 174 // BW-0: return %[[RES]] : vector<2x2xf32> 175 %0 = vector.extract_strided_slice %arg0 { sizes = [2, 2], strides = [1, 1], offsets = [0, 4]} 176 : vector<4x8xf32> to vector<2x2xf32> 177 return %0 : vector<2x2xf32> 178} 179 180// ALL-LABEL: func.func @test_extract_strided_slice_1_scalable( 181// ALL-SAME: %[[VAL_0:.*]]: vector<4x[8]xf32>) -> vector<2x[8]xf32> { 182func.func @test_extract_strided_slice_1_scalable(%arg0: vector<4x[8]xf32>) -> vector<2x[8]xf32> { 183 // ALL-NOT: vector.shuffle 184 // ALL-NOT: vector.shape_cast 185 // ALL: %[[RES:.*]] = vector.extract_strided_slice %[[VAL_0]] {offsets = [1, 0], sizes = [2, 8], strides = [1, 1]} : vector<4x[8]xf32> to vector<2x[8]xf32> 186 %0 = vector.extract_strided_slice %arg0 { sizes = [2, 8], strides = [1, 1], offsets = [1, 0] } : vector<4x[8]xf32> to vector<2x[8]xf32> 187 // ALL: return %[[RES]] : vector<2x[8]xf32> 188 return %0 : vector<2x[8]xf32> 189} 190 191// ----- 192// ALL-LABEL: test_extract_strided_slice_2 193// ALL-SAME: (%[[ORIG_ARG:.*]]: vector<2x8x2xf32>) -> vector<1x4x2xf32> { 194func.func @test_extract_strided_slice_2(%arg0 : vector<2x8x2xf32>) -> vector<1x4x2xf32> { 195 // DEFAULT: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x8x2xf32> to vector<32xf32> 196 // DEFAULT: %[[SHUFFLE:.*]] = vector.shuffle %[[ARG]], %[[ARG]] 197 // DEFAULT-SAME: [20, 21, 22, 23, 24, 25, 26, 27] : vector<32xf32>, vector<32xf32> 198 // DEFAULT: %[[RES:.*]] = vector.shape_cast %[[SHUFFLE]] : vector<8xf32> to vector<1x4x2xf32> 199 // DEFAULT: return %[[RES]] : vector<1x4x2xf32> 200 201 // BW-128: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x8x2xf32> to vector<32xf32> 202 // BW-128: %[[SHUFFLE:.*]] = vector.shuffle %[[ARG]], %[[ARG]] 203 // BW-128-SAME: [20, 21, 22, 23, 24, 25, 26, 27] : vector<32xf32>, vector<32xf32> 204 // BW-128: %[[RES:.*]] = vector.shape_cast %[[SHUFFLE]] : vector<8xf32> to vector<1x4x2xf32> 205 // BW-128: return %[[RES]] : vector<1x4x2xf32> 206 207 // BW-0: %[[RES:.*]] = vector.extract_strided_slice %[[ORIG_ARG]] {offsets = [1, 2], sizes = [1, 4], strides = [1, 1]} : vector<2x8x2xf32> to vector<1x4x2xf32> 208 // BW-0: return %[[RES]] : vector<1x4x2xf32> 209 %0 = vector.extract_strided_slice %arg0 { offsets = [1, 2], strides = [1, 1], sizes = [1, 4] } 210 : vector<2x8x2xf32> to vector<1x4x2xf32> 211 return %0 : vector<1x4x2xf32> 212} 213 214// ----- 215// ALL-LABEL: test_vector_shuffle 216// ALL-SAME: (%[[ORIG_ARG0:.*]]: vector<4x2xf32>, %[[ORIG_ARG1:.*]]: vector<4x2xf32>) -> vector<8x2xf32> { 217func.func @test_vector_shuffle(%arg0: vector<4x2xf32>, %arg1: vector<4x2xf32>) -> vector<8x2xf32> { 218 // DEFAULT-DAG: %[[ARG0:.*]] = vector.shape_cast %[[ORIG_ARG0]] : vector<4x2xf32> to vector<8xf32> 219 // DEFAULT-DAG: %[[ARG1:.*]] = vector.shape_cast %[[ORIG_ARG1]] : vector<4x2xf32> to vector<8xf32> 220 // DEFAULT: %[[SHUFFLE:.*]] = vector.shuffle %[[ARG0]], %[[ARG1]] 221 // DEFAULT-SAME: [0, 1, 8, 9, 2, 3, 10, 11, 4, 5, 12, 13, 6, 7, 14, 15] : vector<8xf32>, vector<8xf32> 222 // DEFAULT: %[[RES:.*]] = vector.shape_cast %[[SHUFFLE]] : vector<16xf32> to vector<8x2xf32> 223 // DEFAULT: return %[[RES]] : vector<8x2xf32> 224 225 // BW-128-DAG: %[[ARG0:.*]] = vector.shape_cast %[[ORIG_ARG0]] : vector<4x2xf32> to vector<8xf32> 226 // BW-128-DAG: %[[ARG1:.*]] = vector.shape_cast %[[ORIG_ARG1]] : vector<4x2xf32> to vector<8xf32> 227 // BW-128: %[[SHUFFLE:.*]] = vector.shuffle %[[ARG0]], %[[ARG1]] 228 // BW-128-SAME: [0, 1, 8, 9, 2, 3, 10, 11, 4, 5, 12, 13, 6, 7, 14, 15] : vector<8xf32>, vector<8xf32> 229 // BW-128: %[[RES:.*]] = vector.shape_cast %[[SHUFFLE]] : vector<16xf32> to vector<8x2xf32> 230 // BW-128: return %[[RES]] : vector<8x2xf32> 231 232 // BW-0: %[[RES:.*]] = vector.shuffle %[[ORIG_ARG0]], %[[ORIG_ARG1]] [0, 4, 1, 5, 2, 6, 3, 7] : vector<4x2xf32>, vector<4x2xf32> 233 // BW-0: return %[[RES]] : vector<8x2xf32> 234 %0 = vector.shuffle %arg0, %arg1 [0, 4, 1, 5, 2, 6, 3, 7] : vector<4x2xf32>, vector<4x2xf32> 235 return %0 : vector<8x2xf32> 236} 237 238// ----- 239// ALL-LABEL: test_vector_extract 240// ALL-SAME: (%[[ORIG_ARG:.*]]: vector<2x8x2xf32>) -> vector<8x2xf32> { 241func.func @test_vector_extract(%arg0: vector<2x8x2xf32>) -> vector<8x2xf32> { 242 // DEFAULT: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x8x2xf32> to vector<32xf32> 243 // DEFAULT: %[[SHUFFLE:.*]] = vector.shuffle %[[ARG]], %[[ARG]] 244 // DEFAULT-SAME: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31] : vector<32xf32>, vector<32xf32> 245 // DEFAULT: %[[RES:.*]] = vector.shape_cast %[[SHUFFLE]] : vector<16xf32> to vector<8x2xf32> 246 // DEFAULT: return %[[RES]] : vector<8x2xf32> 247 248 // BW-128: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x8x2xf32> to vector<32xf32> 249 // BW-128: %[[SHUFFLE:.*]] = vector.shuffle %[[ARG]], %[[ARG]] 250 // BW-128-SAME: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31] : vector<32xf32>, vector<32xf32> 251 // BW-128: %[[RES:.*]] = vector.shape_cast %[[SHUFFLE]] : vector<16xf32> to vector<8x2xf32> 252 // BW-128: return %[[RES]] : vector<8x2xf32> 253 254 // BW-0: %[[RES:.*]] = vector.extract %[[ORIG_ARG]][1] : vector<8x2xf32> from vector<2x8x2xf32> 255 // BW-0: return %[[RES]] : vector<8x2xf32> 256 %0 = vector.extract %arg0[1]: vector<8x2xf32> from vector<2x8x2xf32> 257 return %0 : vector<8x2xf32> 258} 259 260// ALL-LABEL: func.func @test_vector_extract_scalable( 261// ALL-SAME: %[[VAL_0:.*]]: vector<2x8x[2]xf32>) -> vector<8x[2]xf32> { 262func.func @test_vector_extract_scalable(%arg0: vector<2x8x[2]xf32>) -> vector<8x[2]xf32> { 263 // ALL-NOT: vector.shuffle 264 // ALL-NOT: vector.shape_cast 265 // ALL: %[[RES:.*]] = vector.extract %[[VAL_0]][1] : vector<8x[2]xf32> from vector<2x8x[2]xf32> 266 %0 = vector.extract %arg0[1]: vector<8x[2]xf32> from vector<2x8x[2]xf32> 267 // ALL: return %[[RES]] : vector<8x[2]xf32> 268 return %0 : vector<8x[2]xf32> 269} 270// ----- 271// ALL-LABEL: test_vector_insert 272// ALL-SAME: (%[[DEST:.*]]: vector<2x8x4xf32>, %[[SRC:.*]]: vector<8x4xf32>) -> vector<2x8x4xf32> { 273func.func @test_vector_insert(%arg0: vector<2x8x4xf32>, %arg1: vector<8x4xf32>) -> vector<2x8x4xf32> { 274 // DEFAULT-DAG: %[[ARG_SRC:.*]] = vector.shape_cast %[[SRC]] : vector<8x4xf32> to vector<32xf32> 275 // DEFAULT-DAG: %[[ARG_DEST:.*]] = vector.shape_cast %[[DEST]] : vector<2x8x4xf32> to vector<64xf32> 276 // DEFAULT: %[[SHUFFLE:.*]] = vector.shuffle %[[ARG_DEST]], %[[ARG_SRC]] 277 // DEFAULT-SAME: [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 278 // DEFAULT-SAME: 88, 89, 90, 91, 92, 93, 94, 95, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 279 // DEFAULT-SAME: 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] : vector<64xf32>, vector<32xf32> 280 // DEFAULT: %[[RES:.*]] = vector.shape_cast %[[SHUFFLE]] : vector<64xf32> to vector<2x8x4xf32> 281 // DEFAULT: return %[[RES]] : vector<2x8x4xf32> 282 283 // BW-128-DAG: %[[ARG_SRC:.*]] = vector.shape_cast %[[SRC]] : vector<8x4xf32> to vector<32xf32> 284 // BW-128-DAG: %[[ARG_DEST:.*]] = vector.shape_cast %[[DEST]] : vector<2x8x4xf32> to vector<64xf32> 285 // BW-128: %[[SHUFFLE:.*]] = vector.shuffle %[[ARG_DEST]], %[[ARG_SRC]] 286 // BW-128-SAME: [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 287 // BW-128-SAME: 88, 89, 90, 91, 92, 93, 94, 95, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 288 // BW-128-SAME: 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] : vector<64xf32>, vector<32xf32> 289 // BW-128: %[[RES:.*]] = vector.shape_cast %[[SHUFFLE]] : vector<64xf32> to vector<2x8x4xf32> 290 // BW-128: return %[[RES]] : vector<2x8x4xf32> 291 292 // BW-0: %[[RES:.*]] = vector.insert %[[SRC]], %[[DEST]] [0] : vector<8x4xf32> into vector<2x8x4xf32> 293 // BW-0: return %[[RES]] : vector<2x8x4xf32> 294 295 %0 = vector.insert %arg1, %arg0[0]: vector<8x4xf32> into vector<2x8x4xf32> 296 return %0 : vector<2x8x4xf32> 297} 298 299// ALL-LABEL: func.func @test_vector_insert_scalable( 300// ALL-SAME: %[[VAL_0:.*]]: vector<2x8x[4]xf32>, %[[VAL_1:.*]]: vector<8x[4]xf32>) -> vector<2x8x[4]xf32> { 301func.func @test_vector_insert_scalable(%arg0: vector<2x8x[4]xf32>, %arg1: vector<8x[4]xf32>) -> vector<2x8x[4]xf32> { 302 // ALL-NOT: vector.shuffle 303 // ALL-NOT: vector.shape_cast 304 // ALL: %[[RES:.*]] = vector.insert %[[VAL_1]], %[[VAL_0]] [0] : vector<8x[4]xf32> into vector<2x8x[4]xf32> 305 %0 = vector.insert %arg1, %arg0[0]: vector<8x[4]xf32> into vector<2x8x[4]xf32> 306 // ALL: return %[[RES]] : vector<2x8x[4]xf32> 307 return %0 : vector<2x8x[4]xf32> 308} 309 310// ----- 311 312// ALL-LABEL: test_vector_extract_scalar 313func.func @test_vector_extract_scalar() { 314 %cst = arith.constant dense<[1, 2, 3, 4]> : vector<4xi32> 315 // ALL-NOT: vector.shuffle 316 // ALL: vector.extract 317 // ALL-NOT: vector.shuffle 318 %0 = vector.extract %cst[0] : i32 from vector<4xi32> 319 return 320} 321 322// ----- 323 324// ALL-LABEL: test_vector_bitcast 325// ALL-SAME: %[[ARG_0:.*]]: vector<4x4xf32> 326func.func @test_vector_bitcast(%arg0: vector<4x4xf32>) -> vector<4x8xf16> { 327 // DEFAULT: %[[DOWNCAST:.*]] = vector.shape_cast %[[ARG_0]] : vector<4x4xf32> to vector<16xf32> 328 // DEFAULT: %[[BITCAST:.*]] = vector.bitcast %[[DOWNCAST]] : vector<16xf32> to vector<32xf16> 329 // DEFAULT: %[[UPCAST:.*]] = vector.shape_cast %[[BITCAST]] : vector<32xf16> to vector<4x8xf16> 330 331 // BW-128: %[[UPCAST:.*]] = vector.bitcast %[[ARG_0]] : vector<4x4xf32> to vector<4x8xf16> 332 // BW-0: %[[BITCAST:.*]] = vector.bitcast %[[ARG_0]] : vector<4x4xf32> to vector<4x8xf16> 333 %1 = vector.bitcast %arg0 : vector<4x4xf32> to vector<4x8xf16> 334 return %1 : vector<4x8xf16> 335} 336 337// ----- 338 339// ALL-LABEL: test_vector_bitcast 340// ALL-SAME: %[[ARG_0:.*]]: vector<4x2xf32> 341func.func @test_vector_bitcast(%arg0: vector<4x2xf32>) -> vector<4x4xf16> { 342 // DEFAULT: %[[DOWNCAST:.*]] = vector.shape_cast %[[ARG_0]] : vector<4x2xf32> to vector<8xf32> 343 // DEFAULT: %[[BITCAST:.*]] = vector.bitcast %[[DOWNCAST]] : vector<8xf32> to vector<16xf16> 344 // DEFAULT: %[[UPCAST:.*]] = vector.shape_cast %[[BITCAST]] : vector<16xf16> to vector<4x4xf16> 345 // BW-128: %[[DOWNCAST:.*]] = vector.shape_cast %[[ARG_0]] : vector<4x2xf32> to vector<8xf32> 346 // BW-128: %[[BITCAST:.*]] = vector.bitcast %[[DOWNCAST]] : vector<8xf32> to vector<16xf16> 347 // BW-128: %[[UPCAST:.*]] = vector.shape_cast %[[BITCAST]] : vector<16xf16> to vector<4x4xf16> 348 349 // BW-0: %[[BITCAST:.*]] = vector.bitcast %[[ARG_0]] : vector<4x2xf32> to vector<4x4xf16> 350 %1 = vector.bitcast %arg0 : vector<4x2xf32> to vector<4x4xf16> 351 return %1 : vector<4x4xf16> 352} 353 354// ----- 355 356// ALL-LABEL: test_vector_bitcast 357// ALL-SAME: %[[ARG_0:.*]]: vector<4x[2]xf32> 358func.func @test_vector_bitcast(%arg0: vector<4x[2]xf32>) -> vector<4x[4]xf16> { 359 // DEFAULT: %[[DOWNCAST:.*]] = vector.shape_cast %[[ARG_0]] : vector<4x[2]xf32> to vector<[8]xf32> 360 // DEFAULT: %[[BITCAST:.*]] = vector.bitcast %[[DOWNCAST]] : vector<[8]xf32> to vector<[16]xf16> 361 // DEFAULT: %[[UPCAST:.*]] = vector.shape_cast %[[BITCAST]] : vector<[16]xf16> to vector<4x[4]xf16> 362 // BW-128: %[[DOWNCAST:.*]] = vector.shape_cast %[[ARG_0]] : vector<4x[2]xf32> to vector<[8]xf32> 363 // BW-128: %[[BITCAST:.*]] = vector.bitcast %[[DOWNCAST]] : vector<[8]xf32> to vector<[16]xf16> 364 // BW-128: %[[UPCAST:.*]] = vector.shape_cast %[[BITCAST]] : vector<[16]xf16> to vector<4x[4]xf16> 365 366 // BW-0: %[[BITCAST:.*]] = vector.bitcast %[[ARG_0]] : vector<4x[2]xf32> to vector<4x[4]xf16> 367 %1 = vector.bitcast %arg0 : vector<4x[2]xf32> to vector<4x[4]xf16> 368 return %1 : vector<4x[4]xf16> 369} 370 371// ----- 372// ALL-LABEL: test_vector_bitcast 373// ALL-SAME: %[[ARG_0:.*]]: vector<[4]x2xf32> 374func.func @test_vector_bitcast(%arg0: vector<[4]x2xf32>) -> vector<[4]x4xf16> { 375 // DEFAULT: %[[DOWNCAST:.*]] = vector.shape_cast %[[ARG_0]] : vector<[4]x2xf32> to vector<[8]xf32> 376 // DEFAULT: %[[BITCAST:.*]] = vector.bitcast %[[DOWNCAST]] : vector<[8]xf32> to vector<[16]xf16> 377 // DEFAULT: %[[UPCAST:.*]] = vector.shape_cast %[[BITCAST]] : vector<[16]xf16> to vector<[4]x4xf16> 378 // BW-128: %[[DOWNCAST:.*]] = vector.shape_cast %[[ARG_0]] : vector<[4]x2xf32> to vector<[8]xf32> 379 // BW-128: %[[BITCAST:.*]] = vector.bitcast %[[DOWNCAST]] : vector<[8]xf32> to vector<[16]xf16> 380 // BW-128: %[[UPCAST:.*]] = vector.shape_cast %[[BITCAST]] : vector<[16]xf16> to vector<[4]x4xf16> 381 382 // BW-0: %[[BITCAST:.*]] = vector.bitcast %[[ARG_0]] : vector<[4]x2xf32> to vector<[4]x4xf16> 383 %1 = vector.bitcast %arg0 : vector<[4]x2xf32> to vector<[4]x4xf16> 384 return %1 : vector<[4]x4xf16> 385} 386