brintos

brintos / llvm-project-archived public Read only

0
0
Text · 37.8 KiB · 0a276e2 Raw
725 lines · plain
1// RUN: mlir-opt --split-input-file --tosa-to-tensor %s -o -| FileCheck %s2 3// -----4 5// CHECK-LABEL: test_reshape_0d_same_s2s_explicit6// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<f32>7// CHECK: return %[[ARG_0]] : tensor<f32>8func.func @test_reshape_0d_same_s2s_explicit(%arg0: tensor<f32>) -> tensor<f32> {9  %s = tosa.const_shape { values = dense<> : tensor<0xindex> } : () -> !tosa.shape<0>10  %0 = "tosa.reshape"(%arg0, %s) : (tensor<f32>, !tosa.shape<0>) -> tensor<f32>11  return %0 : tensor<f32>12}13 14// -----15 16// CHECK-LABEL: test_reshape_0d_up_s2d_auto17// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<f32>18// CHECK: %[[VAL_0:.*]] = tensor.expand_shape %[[ARG_0]] [] output_shape [1] : tensor<f32> into tensor<1xf32>19// CHECK: %[[VAL_1:.*]] = tensor.cast %[[VAL_0]] : tensor<1xf32> to tensor<?xf32>20// CHECK: return %[[VAL_1]] : tensor<?xf32>21func.func @test_reshape_0d_up_s2d_auto(%arg0: tensor<f32>) -> tensor<?xf32> {22  %s = tosa.const_shape { values = dense<-1> : tensor<1xindex> } : () -> !tosa.shape<1>23  %0 = "tosa.reshape"(%arg0, %s) : (tensor<f32>, !tosa.shape<1>) -> tensor<?xf32>24  return %0 : tensor<?xf32>25}26 27// -----28 29// CHECK-LABEL: test_reshape_0d_up_s2d_explicit30// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<f32>31// CHECK: %[[VAL_0:.*]] = tensor.expand_shape %[[ARG_0]] [] output_shape [1] : tensor<f32> into tensor<1xf32>32// CHECK: %[[VAL_1:.*]] = tensor.cast %[[VAL_0]] : tensor<1xf32> to tensor<?xf32>33// CHECK: return %[[VAL_1]] : tensor<?xf32>34func.func @test_reshape_0d_up_s2d_explicit(%arg0: tensor<f32>) -> tensor<?xf32> {35  %s = tosa.const_shape { values = dense<1> : tensor<1xindex> } : () -> !tosa.shape<1>36  %0 = "tosa.reshape"(%arg0, %s) : (tensor<f32>, !tosa.shape<1>) -> tensor<?xf32>37  return %0 : tensor<?xf32>38}39 40// -----41 42// CHECK-LABEL: test_reshape_0d_up_s2s_auto43// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<f32>44// CHECK: %[[VAL_0:.*]] = tensor.expand_shape %[[ARG_0]] [] output_shape [1] : tensor<f32> into tensor<1xf32>45// CHECK: return %[[VAL_0]] : tensor<1xf32>46func.func @test_reshape_0d_up_s2s_auto(%arg0: tensor<f32>) -> tensor<1xf32> {47  %s = tosa.const_shape { values = dense<-1> : tensor<1xindex> } : () -> !tosa.shape<1>48  %0 = "tosa.reshape"(%arg0, %s) : (tensor<f32>, !tosa.shape<1>) -> tensor<1xf32>49  return %0 : tensor<1xf32>50}51 52// -----53 54// CHECK-LABEL: test_reshape_0d_up_s2s_explicit55// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<f32>56// CHECK: %[[VAL_0:.*]] = tensor.expand_shape %[[ARG_0]] [] output_shape [1] : tensor<f32> into tensor<1xf32>57// CHECK: return %[[VAL_0]] : tensor<1xf32>58func.func @test_reshape_0d_up_s2s_explicit(%arg0: tensor<f32>) -> tensor<1xf32> {59  %s = tosa.const_shape { values = dense<1> : tensor<1xindex> } : () -> !tosa.shape<1>60  %0 = "tosa.reshape"(%arg0, %s) : (tensor<f32>, !tosa.shape<1>) -> tensor<1xf32>61  return %0 : tensor<1xf32>62}63 64// -----65 66// CHECK-LABEL: test_reshape_1d_down_d2s_explicit67// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<?xf32>68// CHECK: %[[VAL_0:.*]] = tensor.cast %[[ARG_0]] : tensor<?xf32> to tensor<1xf32>69// CHECK: %[[VAL_1:.*]] = tensor.collapse_shape %[[VAL_0]] [] : tensor<1xf32> into tensor<f32>70// CHECK: return %[[VAL_1]] : tensor<f32>71func.func @test_reshape_1d_down_d2s_explicit(%arg0: tensor<?xf32>) -> tensor<f32> {72  %s = tosa.const_shape { values = dense<> : tensor<0xindex> } : () -> !tosa.shape<0>73  %0 = "tosa.reshape"(%arg0, %s) : (tensor<?xf32>, !tosa.shape<0>) -> tensor<f32>74  return %0 : tensor<f32>75}76 77// -----78 79// CHECK-LABEL: test_reshape_1d_down_s2s_explicit80// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<1xf32>81// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] [] : tensor<1xf32> into tensor<f32>82// CHECK: return %[[VAL_0]] : tensor<f32>83func.func @test_reshape_1d_down_s2s_explicit(%arg0: tensor<1xf32>) -> tensor<f32> {84  %s = tosa.const_shape { values = dense<> : tensor<0xindex> } : () -> !tosa.shape<0>85  %0 = "tosa.reshape"(%arg0, %s) : (tensor<1xf32>, !tosa.shape<0>) -> tensor<f32>86  return %0 : tensor<f32>87}88 89// -----90 91// CHECK-LABEL: test_reshape_1d_up_d2d_auto92// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<?xf32>93// CHECK: %[[C0:.*]] = arith.constant 0 : index94// CHECK: %[[DIM:.*]] = tensor.dim %arg0, %[[C0]] : tensor<?xf32>95// CHECK: %[[C2:.*]] = arith.constant 2 : index96// CHECK: %[[VAL_0:.*]] = arith.divsi %[[DIM]], %[[C2]] : index97// CHECK: %[[EXPANDED:.*]] = tensor.expand_shape %[[ARG_0]] {{\[\[}}0, 1]] output_shape [2, %[[VAL_0]]] : tensor<?xf32> into tensor<2x?xf32>98// CHECK: return %[[EXPANDED]] : tensor<2x?xf32>99func.func @test_reshape_1d_up_d2d_auto(%arg0: tensor<?xf32>) -> tensor<2x?xf32> {100  %s = tosa.const_shape { values = dense<[2, -1]> : tensor<2xindex> } : () -> !tosa.shape<2>101  %0 = "tosa.reshape"(%arg0, %s) : (tensor<?xf32>, !tosa.shape<2>) -> tensor<2x?xf32>102  return %0 : tensor<2x?xf32>103}104 105// -----106 107// CHECK-LABEL: test_reshape_1d_up_s2s_explicit108// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<6xf32>109// CHECK: %[[VAL_0:.*]] = tensor.expand_shape %[[ARG_0]] {{\[\[}}0, 1]] output_shape [2, 3] : tensor<6xf32> into tensor<2x3xf32>110// CHECK: return %[[VAL_0]] : tensor<2x3xf32>111func.func @test_reshape_1d_up_s2s_explicit(%arg0: tensor<6xf32>) -> tensor<2x3xf32> {112  %s = tosa.const_shape { values = dense<[2, 3]> : tensor<2xindex> } : () -> !tosa.shape<2>113  %0 = "tosa.reshape"(%arg0, %s) : (tensor<6xf32>, !tosa.shape<2>) -> tensor<2x3xf32>114  return %0 : tensor<2x3xf32>115}116 117// -----118 119// CHECK-LABEL: test_reshape_2d_down_d2d_auto120// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<2x?xf32>121// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1]] : tensor<2x?xf32> into tensor<?xf32>122// CHECK: return %[[VAL_0]] : tensor<?xf32>123func.func @test_reshape_2d_down_d2d_auto(%arg0: tensor<2x?xf32>) -> tensor<?xf32> {124  %s = tosa.const_shape { values = dense<-1> : tensor<1xindex> } : () -> !tosa.shape<1>125  %0 = "tosa.reshape"(%arg0, %s) : (tensor<2x?xf32>, !tosa.shape<1>) -> tensor<?xf32>126  return %0 : tensor<?xf32>127}128 129// -----130 131// CHECK-LABEL: test_reshape_2d_down_s2s_explicit132// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<2x3xf32>133// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1]] : tensor<2x3xf32> into tensor<6xf32>134// CHECK: return %[[VAL_0]] : tensor<6xf32>135func.func @test_reshape_2d_down_s2s_explicit(%arg0: tensor<2x3xf32>) -> tensor<6xf32> {136  %s = tosa.const_shape { values = dense<6> : tensor<1xindex> } : () -> !tosa.shape<1>137  %0 = "tosa.reshape"(%arg0, %s) : (tensor<2x3xf32>, !tosa.shape<1>) -> tensor<6xf32>138  return %0 : tensor<6xf32>139}140 141// -----142 143// CHECK-LABEL: test_reshape_2d_same_d2d_auto144// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<?x2xf32>145// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1]] : tensor<?x2xf32> into tensor<?xf32>146// CHECK: %[[C0:.*]] = arith.constant 0 : index147// CHECK: %[[DIM:.*]] = tensor.dim %[[VAL_0]], %[[C0]] : tensor<?xf32>148// CHECK: %[[C2:.*]] = arith.constant 2 : index149// CHECK: %[[DIV:.*]] = arith.divsi %[[DIM]], %[[C2]] : index150// CHECK: %[[EXPANDED:.*]] = tensor.expand_shape %[[VAL_0]] {{\[\[}}0, 1]] output_shape [2, %[[DIV]]] : tensor<?xf32> into tensor<2x?xf32>151// CHECK: return %[[EXPANDED]] : tensor<2x?xf32>152func.func @test_reshape_2d_same_d2d_auto(%arg0: tensor<?x2xf32>) -> tensor<2x?xf32> {153  %s = tosa.const_shape { values = dense<[2, -1]> : tensor<2xindex> } : () -> !tosa.shape<2>154  %0 = "tosa.reshape"(%arg0, %s) : (tensor<?x2xf32>, !tosa.shape<2>) -> tensor<2x?xf32>155  return %0 : tensor<2x?xf32>156}157 158// -----159 160// CHECK-LABEL: test_reshape_2d_same_s2d_auto161// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<2x4xf32>162// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1]] : tensor<2x4xf32> into tensor<8xf32>163// CHECK: %[[VAL_1:.*]] = tensor.expand_shape %[[VAL_0]] {{\[\[}}0, 1]] output_shape [4, 2] : tensor<8xf32> into tensor<4x2xf32>164// CHECK: %[[VAL_2:.*]] = tensor.cast %[[VAL_1]] : tensor<4x2xf32> to tensor<?x2xf32>165// CHECK: return %[[VAL_2]] : tensor<?x2xf32>166func.func @test_reshape_2d_same_s2d_auto(%arg0: tensor<2x4xf32>) -> tensor<?x2xf32> {167  %s = tosa.const_shape { values = dense<[-1, 2]> : tensor<2xindex> } : () -> !tosa.shape<2>168  %0 = "tosa.reshape"(%arg0, %s) : (tensor<2x4xf32>, !tosa.shape<2>) -> tensor<?x2xf32>169  return %0 : tensor<?x2xf32>170}171 172 173// -----174 175// CHECK-LABEL: test_reshape_2d_same_s2d_explicit176// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<2x4xf32>177// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1]] : tensor<2x4xf32> into tensor<8xf32>178// CHECK: %[[VAL_1:.*]] = tensor.expand_shape %[[VAL_0]] {{\[\[}}0, 1]] output_shape [4, 2] : tensor<8xf32> into tensor<4x2xf32>179// CHECK: %[[VAL_2:.*]] = tensor.cast %[[VAL_1]] : tensor<4x2xf32> to tensor<?x2xf32>180// CHECK: return %[[VAL_2]] : tensor<?x2xf32>181func.func @test_reshape_2d_same_s2d_explicit(%arg0: tensor<2x4xf32>) -> tensor<?x2xf32> {182  %s = tosa.const_shape { values = dense<[4, 2]> : tensor<2xindex> } : () -> !tosa.shape<2>183  %0 = "tosa.reshape"(%arg0, %s) : (tensor<2x4xf32>, !tosa.shape<2>) -> tensor<?x2xf32>184  return %0 : tensor<?x2xf32>185}186 187// -----188 189// CHECK-LABEL: test_reshape_2d_same_s2s_explicit190// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<3x2xf32>191// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1]] : tensor<3x2xf32> into tensor<6xf32>192// CHECK: %[[VAL_1:.*]] = tensor.expand_shape %[[VAL_0]] {{\[\[}}0, 1]] output_shape [2, 3] : tensor<6xf32> into tensor<2x3xf32>193// CHECK: return %[[VAL_1]] : tensor<2x3xf32>194func.func @test_reshape_2d_same_s2s_explicit(%arg0: tensor<3x2xf32>) -> tensor<2x3xf32> {195  %s = tosa.const_shape { values = dense<[2, 3]> : tensor<2xindex> } : () -> !tosa.shape<2>196  %0 = "tosa.reshape"(%arg0, %s) : (tensor<3x2xf32>, !tosa.shape<2>) -> tensor<2x3xf32>197  return %0 : tensor<2x3xf32>198}199 200// -----201 202// CHECK-LABEL: test_reshape_3d_same_d2d_auto_empty203// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<3x2x?xf32>204// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1, 2]] : tensor<3x2x?xf32> into tensor<?xf32>205// CHECK: %[[C0:.*]] = arith.constant 0 : index206// CHECK: %[[DIM:.*]] = tensor.dim %[[VAL_0]], %[[C0]] : tensor<?xf32>207// CHECK: %[[C0_0:.*]] = arith.constant 0 : index208// CHECK: %[[DIV:.*]] = arith.divsi %[[DIM]], %[[C0_0]] : index209// CHECK: %[[VAL_1:.*]] = tensor.expand_shape %[[VAL_0]] {{\[\[}}0, 1, 2]] output_shape [0, 3, %[[DIV]]] : tensor<?xf32> into tensor<0x3x?xf32>210// CHECK: %[[VAL_2:.*]] = tensor.cast %[[VAL_1]] : tensor<0x3x?xf32> to tensor<?x?x?xf32>211// CHECK: return %[[VAL_2]] : tensor<?x?x?xf32>212func.func @test_reshape_3d_same_d2d_auto_empty(%arg0: tensor<3x2x?xf32>) -> tensor<?x?x?xf32> {213  %s = tosa.const_shape { values = dense<[0, 3, -1]> : tensor<3xindex> } : () -> !tosa.shape<3>214  %0 = "tosa.reshape"(%arg0, %s) : (tensor<3x2x?xf32>, !tosa.shape<3>) -> tensor<?x?x?xf32>215  return %0 : tensor<?x?x?xf32>216}217 218// -----219 220// CHECK-LABEL: test_reshape_3d_same_d2d_auto221// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<2x?x?xf32>222// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1, 2]] : tensor<2x?x?xf32> into tensor<?xf32>223// CHECK: %[[C0:.*]] = arith.constant 0 : index224// CHECK: %[[DIM:.*]] = tensor.dim %[[VAL_0]], %[[C0]] : tensor<?xf32>225// CHECK: %[[C8:.*]] = arith.constant 8 : index226// CHECK: %[[DIV:.*]] = arith.divsi %[[DIM]], %[[C8]] : index227// CHECK: %[[VAL_1:.*]] = tensor.expand_shape %[[VAL_0]] {{\[\[}}0, 1, 2]] output_shape [2, %[[DIV]], 4] : tensor<?xf32> into tensor<2x?x4xf32>228// CHECK: %[[VAL_2:.*]] = tensor.cast %[[VAL_1]] : tensor<2x?x4xf32> to tensor<?x?x?xf32>229// CHECK: return %[[VAL_2]] : tensor<?x?x?xf32>230func.func @test_reshape_3d_same_d2d_auto(%arg0: tensor<2x?x?xf32>) -> tensor<?x?x?xf32> {231  %s = tosa.const_shape { values = dense<[2, -1, 4]> : tensor<3xindex> } : () -> !tosa.shape<3>232  %0 = "tosa.reshape"(%arg0, %s) : (tensor<2x?x?xf32>, !tosa.shape<3>) -> tensor<?x?x?xf32>233  return %0 : tensor<?x?x?xf32>234}235 236// -----237 238// CHECK-LABEL: test_reshape_3d_same_d2d_auto_identity239// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<?x3x4xf32>240// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1, 2]] : tensor<?x3x4xf32> into tensor<?xf32>241// CHECK: %[[C0:.*]] = arith.constant 0 : index242// CHECK: %[[DIM:.*]] = tensor.dim %[[VAL_0]], %[[C0]] : tensor<?xf32>243// CHECK: %[[C6:.*]] = arith.constant 6 : index244// CHECK: %[[DIV:.*]] = arith.divsi %[[DIM]], %[[C6]] : index245// CHECK: %[[VAL_1:.*]] = tensor.expand_shape %[[VAL_0]] {{\[\[}}0, 1, 2]] output_shape [2, 3, %[[DIV]]] : tensor<?xf32> into tensor<2x3x?xf32>246// CHECK: return %[[VAL_1]] : tensor<2x3x?xf32>247func.func @test_reshape_3d_same_d2d_auto_identity(%arg0: tensor<?x3x4xf32>) -> tensor<2x3x?xf32> {248  %s = tosa.const_shape { values = dense<[2, 3, -1]> : tensor<3xindex> } : () -> !tosa.shape<3>249  %0 = "tosa.reshape"(%arg0, %s) : (tensor<?x3x4xf32>, !tosa.shape<3>) -> tensor<2x3x?xf32>250  return %0 : tensor<2x3x?xf32>251}252 253// -----254 255// CHECK-LABEL: test_reshape_3d_same_d2d_explicit_empty256// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<3x2x?xf32>257// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1, 2]] : tensor<3x2x?xf32> into tensor<?xf32>258// CHECK: %[[C0:.*]] = arith.constant 0 : index259// CHECK: %[[DIM:.*]] = tensor.dim %[[VAL_0]], %[[C0]] : tensor<?xf32>260// CHECK: %[[C6:.*]] = arith.constant 6 : index261// CHECK: %[[DIV:.*]] = arith.divsi %[[DIM]], %[[C6]] : index262// CHECK: %[[EXPANDED:.*]] = tensor.expand_shape %[[VAL_0]] {{\[\[}}0, 1, 2]] output_shape [%[[DIV]], 3, 2] : tensor<?xf32> into tensor<?x3x2xf32>263// CHECK: %[[VAL_2:.*]] = tensor.cast %[[EXPANDED]] : tensor<?x3x2xf32> to tensor<?x?x?xf32>264// CHECK: return %[[VAL_2]] : tensor<?x?x?xf32>265func.func @test_reshape_3d_same_d2d_explicit_empty(%arg0: tensor<3x2x?xf32>) -> tensor<?x?x?xf32> {266  %s = tosa.const_shape { values = dense<[0, 3, 2]> : tensor<3xindex> } : () -> !tosa.shape<3>267  %0 = "tosa.reshape"(%arg0, %s) : (tensor<3x2x?xf32>, !tosa.shape<3>) -> tensor<?x?x?xf32>268  return %0 : tensor<?x?x?xf32>269}270 271// -----272 273// CHECK-LABEL: test_reshape_3d_same_d2d_explicit274// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<?x?x?xf32>275// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1, 2]] : tensor<?x?x?xf32> into tensor<?xf32>276// CHECK: %[[C0:.*]] = arith.constant 0 : index277// CHECK: %[[DIM:.*]] = tensor.dim %[[VAL_0]], %[[C0]] : tensor<?xf32>278// CHECK: %[[C12:.*]] = arith.constant 12 : index279// CHECK: %[[DIV:.*]] = arith.divsi %[[DIM]], %[[C12]] : index280// CHECK: %[[EXPANDED:.*]] = tensor.expand_shape %[[VAL_0]] {{\[\[}}0, 1, 2]] output_shape [%[[DIV]], 3, 4] : tensor<?xf32> into tensor<?x3x4xf32>281// CHECK: %[[VAL_2:.*]] = tensor.cast %[[EXPANDED]] : tensor<?x3x4xf32> to tensor<?x?x?xf32>282// CHECK: return %[[VAL_2]] : tensor<?x?x?xf32>283func.func @test_reshape_3d_same_d2d_explicit(%arg0: tensor<?x?x?xf32>) -> tensor<?x?x?xf32> {284  %s = tosa.const_shape { values = dense<[2, 3, 4]> : tensor<3xindex> } : () -> !tosa.shape<3>285  %0 = "tosa.reshape"(%arg0, %s) : (tensor<?x?x?xf32>, !tosa.shape<3>) -> tensor<?x?x?xf32>286  return %0 : tensor<?x?x?xf32>287}288 289// -----290 291// CHECK-LABEL: test_reshape_3d_same_d2d_explicit_identity292// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<?x3x4xf32>293// CHECK: %[[VAL_0:.*]] = tensor.cast %[[ARG_0]] : tensor<?x3x4xf32> to tensor<2x3x?xf32>294// CHECK: return %[[VAL_0]] : tensor<2x3x?xf32>295func.func @test_reshape_3d_same_d2d_explicit_identity(%arg0: tensor<?x3x4xf32>) -> tensor<2x3x?xf32> {296  %s = tosa.const_shape { values = dense<[2, 3, 4]> : tensor<3xindex> } : () -> !tosa.shape<3>297  %0 = "tosa.reshape"(%arg0, %s) : (tensor<?x3x4xf32>, !tosa.shape<3>) -> tensor<2x3x?xf32>298  return %0 : tensor<2x3x?xf32>299}300 301// -----302 303// CHECK-LABEL: test_reshape_3d_same_d2s_auto304// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<?x?x?xf32>305// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1, 2]] : tensor<?x?x?xf32> into tensor<?xf32>306// CHECK: %[[C0:.*]] = arith.constant 0 : index307// CHECK: %[[DIM:.*]] = tensor.dim %[[VAL_0]], %[[C0]] : tensor<?xf32>308// CHECK: %[[C8:.*]] = arith.constant 8 : index309// CHECK: %[[DIV:.*]] = arith.divsi %[[DIM]], %[[C8]] : index310// CHECK: %[[EXPANDED:.*]] = tensor.expand_shape %[[VAL_0]] {{\[\[}}0, 1, 2]] output_shape [2, %[[DIV]], 4] : tensor<?xf32> into tensor<2x?x4xf32>311// CHECK: %[[VAL_2:.*]] = tensor.cast %[[EXPANDED]] : tensor<2x?x4xf32> to tensor<2x3x4xf32>312// CHECK: return %[[VAL_2]] : tensor<2x3x4xf32>313func.func @test_reshape_3d_same_d2s_auto(%arg0: tensor<?x?x?xf32>) -> tensor<2x3x4xf32> {314  %s = tosa.const_shape { values = dense<[2, -1, 4]> : tensor<3xindex> } : () -> !tosa.shape<3>315  %0 = "tosa.reshape"(%arg0, %s) : (tensor<?x?x?xf32>, !tosa.shape<3>) -> tensor<2x3x4xf32>316  return %0 : tensor<2x3x4xf32>317}318 319// -----320 321// CHECK-LABEL: test_reshape_3d_same_d2s_explicit322// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<?x?x?xf32>323// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1, 2]] : tensor<?x?x?xf32> into tensor<?xf32>324// CHECK: %[[C0:.*]] = arith.constant 0 : index325// CHECK: %[[DIM:.*]] = tensor.dim %[[VAL_0]], %[[C0]] : tensor<?xf32>326// CHECK: %[[C12:.*]] = arith.constant 12 : index327// CHECK: %[[DIV:.*]] = arith.divsi %[[DIM]], %[[C12]] : index328// CHECK: %[[EXPANDED:.*]] = tensor.expand_shape %[[VAL_0]] {{\[\[}}0, 1, 2]] output_shape [%[[DIV]], 3, 4] : tensor<?xf32> into tensor<?x3x4xf32>329// CHECK: %[[VAL_2:.*]] = tensor.cast %[[EXPANDED]] : tensor<?x3x4xf32> to tensor<2x3x4xf32>330// CHECK: return %[[VAL_2]] : tensor<2x3x4xf32>331func.func @test_reshape_3d_same_d2s_explicit(%arg0: tensor<?x?x?xf32>) -> tensor<2x3x4xf32> {332  %s = tosa.const_shape { values = dense<[2, 3, 4]> : tensor<3xindex> } : () -> !tosa.shape<3>333  %0 = "tosa.reshape"(%arg0, %s) : (tensor<?x?x?xf32>, !tosa.shape<3>) -> tensor<2x3x4xf32>334  return %0 : tensor<2x3x4xf32>335}336 337// -----338 339// CHECK-LABEL: test_reshape_3d_same_s2s_explicit_identity340// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<2x3x4xf32>341// CHECK: return %[[ARG_0]] : tensor<2x3x4xf32>342func.func @test_reshape_3d_same_s2s_explicit_identity(%arg0: tensor<2x3x4xf32>) -> tensor<2x3x4xf32> {343  %s = tosa.const_shape { values = dense<[2, 3, 4]> : tensor<3xindex> } : () -> !tosa.shape<3>344  %0 = "tosa.reshape"(%arg0, %s) : (tensor<2x3x4xf32>, !tosa.shape<3>) -> tensor<2x3x4xf32>345  return %0 : tensor<2x3x4xf32>346}347 348// -----349 350// CHECK-LABEL: test_reshape_3d_up_d2s_explicit351// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<?x?x?xf32>352// CHECK: %[[COLLAPSED:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1, 2]] : tensor<?x?x?xf32> into tensor<?xf32>353// CHECK: %[[C0:.*]] = arith.constant 0 : index354// CHECK: %[[DIM:.*]] = tensor.dim %[[COLLAPSED]], %[[C0]] : tensor<?xf32>355// CHECK: %[[C6:.*]] = arith.constant 6 : index356// CHECK: %[[VAL_0:.*]] = arith.divsi %[[DIM]], %[[C6]] : index357// CHECK: %[[EXPANDED:.*]] = tensor.expand_shape %[[COLLAPSED]] {{\[\[}}0, 1, 2, 3]] output_shape [%[[VAL_0]], 3, 2, 1] : tensor<?xf32> into tensor<?x3x2x1xf32>358// CHECK: %[[CAST:.*]] = tensor.cast %[[EXPANDED]] : tensor<?x3x2x1xf32> to tensor<1x3x2x1xf32>359// CHECK: return %[[CAST]] : tensor<1x3x2x1xf32>360func.func @test_reshape_3d_up_d2s_explicit(%input: tensor<?x?x?xf32>) -> tensor<1x3x2x1xf32> {361  %s = tosa.const_shape { values = dense<[1, 3, 2, 1]> : tensor<4xindex> } : () -> !tosa.shape<4>362  %0 = tosa.reshape %input, %s : (tensor<?x?x?xf32>, !tosa.shape<4>) -> tensor<1x3x2x1xf32>363  return %0 : tensor<1x3x2x1xf32>364}365 366// -----367 368// CHECK-LABEL: test_reshape_4d_down_d2s_explicit369// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<?x?x?x?xf32>370// CHECK: %[[VAL_0:.*]] = tensor.cast %[[ARG_0]] : tensor<?x?x?x?xf32> to tensor<1x1x1x1xf32>371// CHECK: %[[VAL_1:.*]] = tensor.collapse_shape %[[VAL_0]] [] : tensor<1x1x1x1xf32> into tensor<f32>372// CHECK: return %[[VAL_1]] : tensor<f32>373func.func @test_reshape_4d_down_d2s_explicit(%arg0: tensor<?x?x?x?xf32>) -> tensor<f32> {374  %s = tosa.const_shape { values = dense<> : tensor<0xindex> } : () -> !tosa.shape<0>375  %0 = "tosa.reshape"(%arg0, %s) : (tensor<?x?x?x?xf32>, !tosa.shape<0>) -> tensor<f32>376  return %0 : tensor<f32>377}378 379// -----380 381// CHECK-LABEL: test_reshape_5d_down_d2d_auto382// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<?x?x?x2x3xf32>383// CHECK: %[[COLLAPSED:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1, 2, 3, 4]] : tensor<?x?x?x2x3xf32> into tensor<?xf32>384// CHECK: %[[C0:.*]] = arith.constant 0 : index385// CHECK: %[[DIM:.*]] = tensor.dim %[[COLLAPSED]], %[[C0]] : tensor<?xf32>386// CHECK: %[[C6:.*]] = arith.constant 6 : index387// CHECK: %[[VAL_0:.*]] = arith.divsi %[[DIM]], %[[C6]] : index388// CHECK: %[[EXPANDED:.*]] = tensor.expand_shape %[[COLLAPSED]] {{\[\[}}0, 1, 2]] output_shape [%[[VAL_0]], 2, 3] : tensor<?xf32> into tensor<?x2x3xf32>389// CHECK: return %[[EXPANDED]] : tensor<?x2x3xf32>390func.func @test_reshape_5d_down_d2d_auto(%arg0: tensor<?x?x?x2x3xf32>) -> tensor<?x2x3xf32> {391  %s = tosa.const_shape { values = dense<[-1, 2, 3]> : tensor<3xindex> } : () -> !tosa.shape<3>392  %0 = "tosa.reshape"(%arg0, %s) : (tensor<?x?x?x2x3xf32>, !tosa.shape<3>) -> tensor<?x2x3xf32>393  return %0 : tensor<?x2x3xf32>394}395 396// -----397 398// CHECK-LABEL: test_reshape_6d_down_d2d_auto399// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<1x2x?x5x7x11xf32>400// CHECK: %[[COLLAPSED:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1, 2, 3, 4, 5]] : tensor<1x2x?x5x7x11xf32> into tensor<?xf32>401// CHECK: %[[C0:.*]] = arith.constant 0 : index402// CHECK: %[[DIM:.*]] = tensor.dim %[[COLLAPSED]], %[[C0]] : tensor<?xf32>403// CHECK: %[[C385:.*]] = arith.constant 385 : index404// CHECK: %[[VAL_0:.*]] = arith.divsi %[[DIM]], %[[C385]] : index405// CHECK: %[[EXPANDED:.*]] = tensor.expand_shape %[[COLLAPSED]] {{\[\[}}0, 1, 2]] output_shape [%[[VAL_0]], 5, 77] : tensor<?xf32> into tensor<?x5x77xf32>406// CHECK: return %[[EXPANDED]] : tensor<?x5x77xf32>407func.func @test_reshape_6d_down_d2d_auto(%arg0: tensor<1x2x?x5x7x11xf32>) -> tensor<?x5x77xf32> {408  %s = tosa.const_shape { values = dense<[-1, 5, 77]> : tensor<3xindex> } : () -> !tosa.shape<3>409  %0 = "tosa.reshape"(%arg0, %s) : (tensor<1x2x?x5x7x11xf32>, !tosa.shape<3>) -> tensor<?x5x77xf32>410  return %0 : tensor<?x5x77xf32>411}412 413// -----414 415// CHECK-LABEL: test_reshape_6d_down_s2s_auto416// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<1x2x3x5x7x11xf32>417// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1, 2], [3], [4, 5]] : tensor<1x2x3x5x7x11xf32> into tensor<6x5x77xf32>418// CHECK: return %[[VAL_0]] : tensor<6x5x77xf32>419func.func @test_reshape_6d_down_s2s_auto(%arg0: tensor<1x2x3x5x7x11xf32>) -> tensor<6x5x77xf32> {420  %s = tosa.const_shape { values = dense<[6, 5, -1]> : tensor<3xindex> } : () -> !tosa.shape<3>421  %0 = "tosa.reshape"(%arg0, %s) : (tensor<1x2x3x5x7x11xf32>, !tosa.shape<3>) -> tensor<6x5x77xf32>422  return %0 : tensor<6x5x77xf32>423}424 425// -----426 427// This test would previously fail on GCC with certain compiler flags.428// The GCC issue would cause invalid IR after tosa-to-tensor, so this test429// locks down that the code goes through tosa-to-tensor and verifies.430//431// See https://github.com/llvm/llvm-project/pull/91521 for a full description.432 433// -----434 435// CHECK-LABEL: reshape_bug_fix436// CHECK: tensor.expand_shape437func.func @reshape_bug_fix(%arg0: tensor<?xf32>) -> tensor<1x1x1x?xf32> {438  %1 = "tosa.const_shape"() {values = dense<[1, 1, 1, -1]> : tensor<4xindex>} : () -> !tosa.shape<4>439  %0 = "tosa.reshape"(%arg0, %1) : (tensor<?xf32>, !tosa.shape<4>) -> tensor<1x1x1x?xf32>440  return %0 : tensor<1x1x1x?xf32>441}442 443// -----444 445// CHECK-LABEL: test_reshape_6d_down_s2s_explicit446// CHECK-SAME: %[[ARG_0:[a-zA-Z0-9_]+]]: tensor<1x2x3x5x7x11xf32>447// CHECK: %[[VAL_0:.*]] = tensor.collapse_shape %[[ARG_0]] {{\[\[}}0, 1, 2], [3], [4, 5]] : tensor<1x2x3x5x7x11xf32> into tensor<6x5x77xf32>448// CHECK: return %[[VAL_0]] : tensor<6x5x77xf32>449func.func @test_reshape_6d_down_s2s_explicit(%arg0: tensor<1x2x3x5x7x11xf32>) -> tensor<6x5x77xf32> {450  %s = tosa.const_shape { values = dense<[6, 5, 77]> : tensor<3xindex> } : () -> !tosa.shape<3>451  %0 = "tosa.reshape"(%arg0, %s) : (tensor<1x2x3x5x7x11xf32>, !tosa.shape<3>) -> tensor<6x5x77xf32>452  return %0 : tensor<6x5x77xf32>453}454 455// -----456 457// CHECK-LABEL: @test_reshape_samerank_unsigned458// CHECK-SAME: (%[[VAL_0:.*]]: tensor<3x2xui8>)459func.func @test_reshape_samerank_unsigned(%arg0: tensor<3x2xui8>) -> tensor<2x3xui8> {460  // CHECK: %[[CAST1:.*]] = builtin.unrealized_conversion_cast %arg0 : tensor<3x2xui8> to tensor<3x2xi8>461  // CHECK: %[[RESHAPE1:.*]] = tensor.collapse_shape %[[CAST1]] {{\[}}[0, 1]] : tensor<3x2xi8> into tensor<6xi8>462  // CHECK: %[[RESHAPE2:.*]] = tensor.expand_shape %[[RESHAPE1]] {{\[}}[0, 1]] output_shape {{\[}}2, 3] : tensor<6xi8> into tensor<2x3xi8>463  // CHECK: %[[CAST2:.*]] = builtin.unrealized_conversion_cast %[[RESHAPE2]] : tensor<2x3xi8> to tensor<2x3xui8464  %s = tosa.const_shape { values = dense<[2, 3]> : tensor<2xindex> } : () -> !tosa.shape<2>465  %0 = "tosa.reshape"(%arg0, %s): (tensor<3x2xui8>, !tosa.shape<2>) -> tensor<2x3xui8>466  return %0 : tensor<2x3xui8>467}468 469// -----470 471// CHECK-LABEL: func @slice472func.func @slice(%arg0: tensor<6xf32>) ->() {473  // CHECK: [[SLICE:%.+]] = tensor.extract_slice %arg0[2] [1] [1]474  %0 = tosa.const_shape  {values = dense<2> : tensor<1xindex>} : () -> !tosa.shape<1>475  %1 = tosa.const_shape  {values = dense<1> : tensor<1xindex>} : () -> !tosa.shape<1>476  %2 = tosa.slice %arg0, %0, %1 : (tensor<6xf32>, !tosa.shape<1>, !tosa.shape<1>) -> tensor<1xf32>477  return478}479 480// -----481 482// CHECK-LABEL: @slice_dyn483func.func @slice_dyn(%arg0: tensor<?xf32>) -> (tensor<?xf32>) {484  // CHECK: %[[C0:.+]] = arith.constant 0 : index485  // CHECK: %[[DIM:.+]] = tensor.dim %arg0, %[[C0]]486  // CHECK: %[[C2:.+]] = arith.constant 2 : index487  // CHECK: %[[SUB:.+]] = arith.subi %[[DIM]], %[[C2]]488  // CHECK: tensor.extract_slice %arg0[2] [%[[SUB]]] [1]489  %0 = tosa.const_shape  {values = dense<2> : tensor<1xindex>} : () -> !tosa.shape<1>490  %1 = tosa.const_shape  {values = dense<-1> : tensor<1xindex>} : () -> !tosa.shape<1>491  %2 = tosa.slice %arg0, %0, %1 : (tensor<?xf32>, !tosa.shape<1>, !tosa.shape<1>) -> tensor<?xf32>492  return %2 : tensor<?xf32>493}494 495// -----496 497// CHECK-LABEL: @pad_float498// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:499func.func @pad_float(%arg0 : tensor<1x2xf32>) -> (tensor<4x9xf32>) {500  %0 = tosa.const_shape {values = dense<[1, 2, 3, 4]> : tensor<4xindex>} : () -> !tosa.shape<4>501  %pad_const = "tosa.const"() {values = dense<3.14> : tensor<1xf32>} : () -> tensor<1xf32>502  // CHECK-DAG: [[INDEX1:%.+]] = arith.constant 1 : index503  // CHECK-DAG: [[INDEX2:%.+]] = arith.constant 2 : index504  // CHECK-DAG: [[INDEX3:%.+]] = arith.constant 3 : index505  // CHECK-DAG: [[INDEX4:%.+]] = arith.constant 4 : index506  // CHECK-DAG: [[CST:%.+]] = arith.constant 3.140000e+00 : f32507  // CHECK: tensor.pad %[[ARG0]] low{{\[}}[[INDEX1]], [[INDEX3]]] high{{\[}}[[INDEX2]], [[INDEX4]]]  {508  // CHECK:   tensor.yield [[CST]]509  // CHECK: } : tensor<1x2xf32> to tensor<4x9xf32>510  %1 = "tosa.pad"(%arg0, %0, %pad_const)  : (tensor<1x2xf32>, !tosa.shape<4>, tensor<1xf32>)  -> (tensor<4x9xf32>)511  return %1 : tensor<4x9xf32>512}513// -----514 515func.func @pad_int(%arg0 : tensor<1x2xi32>) -> (tensor<4x9xi32>) {516  %0 = tosa.const_shape {values = dense<[1, 2, 3, 4]> : tensor<4xindex>} : () -> !tosa.shape<4>517  %pad_const = "tosa.const"() {values = dense<3> : tensor<1xi32>} : () -> tensor<1xi32>518  // CHECK: [[CST:%.+]] = arith.constant 3 : i32519  // CHECK: tensor.pad520  // CHECK:   tensor.yield [[CST]]521  %1 = "tosa.pad"(%arg0, %0, %pad_const)  : (tensor<1x2xi32>, !tosa.shape<4>, tensor<1xi32>)  -> (tensor<4x9xi32>)522  return %1 : tensor<4x9xi32>523}524// -----525 526func.func @pad_quant(%arg0 : tensor<1x2xi32>) -> (tensor<4x9xi32>) {527  %0 = tosa.const_shape {values = dense<[1, 2, 3, 4]> : tensor<4xindex>} : () -> !tosa.shape<4>528  %pad_const = "tosa.const"() {values = dense<0> : tensor<1xi32>} : () -> tensor<1xi32>529  // CHECK: [[CST:%.+]] = arith.constant 0 : i32530  // CHECK: tensor.pad531  // CHECK:   tensor.yield [[CST]]532  %1 = "tosa.pad"(%arg0, %0, %pad_const) {input_zp = 42 : i32} : (tensor<1x2xi32>, !tosa.shape<4>, tensor<1xi32>)  -> (tensor<4x9xi32>)533  return %1 : tensor<4x9xi32>534}535 536// -----537 538func.func @pad_float_explicit(%arg0 : tensor<1x2xf32>) -> (tensor<4x9xf32>) {539  %0 = tosa.const_shape {values = dense<[1, 2, 3, 4]> : tensor<4xindex>} : () -> !tosa.shape<4>540  // CHECK-DAG: [[INDEX1:%.+]] = arith.constant 1 : index541  // CHECK-DAG: [[INDEX2:%.+]] = arith.constant 2 : index542  // CHECK-DAG: [[INDEX3:%.+]] = arith.constant 3 : index543  // CHECK-DAG: [[INDEX4:%.+]] = arith.constant 4 : index544  // CHECK-DAG: [[CST:%.+]] = arith.constant 4.200000e+01 : f32545  // CHECK: tensor.pad %[[ARG0]] low{{\[}}[[INDEX1]], [[INDEX3]]] high{{\[}}[[INDEX2]], [[INDEX4]]]  {546  // CHECK:   tensor.yield [[CST]]547  // CHECK: } : tensor<1x2xf32> to tensor<4x9xf32>548  %1 = arith.constant dense<42.0> : tensor<1xf32>549  %2 = "tosa.pad"(%arg0, %0, %1)  : (tensor<1x2xf32>, !tosa.shape<4>, tensor<1xf32>)  -> (tensor<4x9xf32>)550  return %2 : tensor<4x9xf32>551}552 553// -----554 555func.func @pad_dyn_input(%arg0 : tensor<?x2xf32>) -> (tensor<?x9xf32>) {556  %0 = tosa.const_shape {values = dense<[1, 2, 3, 4]> : tensor<4xindex>} : () -> !tosa.shape<4>557  %pad_const = "tosa.const"() {values = dense<3.14> : tensor<1xf32>} : () -> tensor<1xf32>558  // CHECK-DAG: [[INDEX1:%.+]] = arith.constant 1 : index559  // CHECK-DAG: [[INDEX2:%.+]] = arith.constant 2 : index560  // CHECK-DAG: [[INDEX3:%.+]] = arith.constant 3 : index561  // CHECK-DAG: [[INDEX4:%.+]] = arith.constant 4 : index562  // CHECK-DAG: [[CST:%.+]] = arith.constant 3.140000e+00 : f32563  // CHECK: tensor.pad %[[ARG0]] low{{\[}}[[INDEX1]], [[INDEX3]]] high{{\[}}[[INDEX2]], [[INDEX4]]]  {564  // CHECK:   tensor.yield [[CST]]565  // CHECK: } : tensor<?x2xf32> to tensor<?x9xf32>566  %1 = "tosa.pad"(%arg0, %0, %pad_const)  : (tensor<?x2xf32>, !tosa.shape<4>, tensor<1xf32>)  -> (tensor<?x9xf32>)567  return %1 : tensor<?x9xf32>568}569// -----570 571func.func @pad_dyn_padding(%arg0 : tensor<1x2xf32>) -> (tensor<?x9xf32>) {572  %0 = tosa.const_shape {values = dense<[-1, 2, 3, 4]> : tensor<4xindex>} : () -> !tosa.shape<4>573  %pad_const = "tosa.const"() {values = dense<3.14> : tensor<1xf32>} : () -> tensor<1xf32>574  // CHECK-DAG: [[INDEX1:%.+]] = arith.constant -1 : index575  // CHECK-DAG: [[INDEX2:%.+]] = arith.constant 2 : index576  // CHECK-DAG: [[INDEX3:%.+]] = arith.constant 3 : index577  // CHECK-DAG: [[INDEX4:%.+]] = arith.constant 4 : index578  // CHECK-DAG: [[CST:%.+]] = arith.constant 3.140000e+00 : f32579  // CHECK: tensor.pad %[[ARG0]] low{{\[}}[[INDEX1]], [[INDEX3]]] high{{\[}}[[INDEX2]], [[INDEX4]]]  {580  // CHECK:   tensor.yield [[CST]]581  // CHECK: } : tensor<1x2xf32> to tensor<?x9xf32>582  %1 = "tosa.pad"(%arg0, %0, %pad_const)  : (tensor<1x2xf32>, !tosa.shape<4>, tensor<1xf32>)  -> (tensor<?x9xf32>)583  return %1 : tensor<?x9xf32>584}585 586// -----587 588// CHECK-LABEL: @concat589// CHECK-SAME: %[[ARG0:.+]]: tensor<5x1xf32>590// CHECK-SAME: %[[ARG1:.+]]: tensor<6x1xf32>591func.func @concat(%arg0: tensor<5x1xf32>, %arg1: tensor<6x1xf32>) -> () {592  // CHECK-DAG: [[INIT:%.+]] = tensor.empty() : tensor<11x1xf32>593  // CHECK-DAG: [[INSERT0:%.+]] = tensor.insert_slice %[[ARG0]] into [[INIT]][0, 0] [5, 1] [1, 1]594  // CHECK-DAG: [[INSERT1:%.+]] = tensor.insert_slice %[[ARG1]] into [[INSERT0]][5, 0] [6, 1] [1, 1]595  %0 = "tosa.concat"(%arg0, %arg1) { axis = 0 : i32} : (tensor<5x1xf32>, tensor<6x1xf32>)  -> (tensor<11x1xf32>)596 597  // CHECK-DAG: [[INIT:%.+]] = tensor.empty() : tensor<5x2xf32>598  // CHECK-DAG: [[INSERT0:%.+]] = tensor.insert_slice %[[ARG0]] into [[INIT]][0, 0] [5, 1] [1, 1]599  // CHECK: [[INSERT1:%.+]] = tensor.insert_slice %[[ARG0]] into [[INSERT0]][0, 1] [5, 1] [1, 1]600  %1 = "tosa.concat"(%arg0, %arg0) { axis = 1 : i32} : (tensor<5x1xf32>, tensor<5x1xf32>)  -> (tensor<5x2xf32>)601  return602}603 604// -----605 606// CHECK-LABEL: @concat_non_axis_dyn607// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:608// CHECK-SAME:  %[[ARG1:[0-9a-zA-Z_]*]]609func.func @concat_non_axis_dyn(%arg0: tensor<5x?xf32>, %arg1: tensor<6x?xf32>) -> () {610  // CHECK-DAG: %[[AXIS:.+]] = arith.constant 0611  // CHECK-DAG: %[[IDX1:.+]] = arith.constant 1612  // CHECK-DAG: %[[DIM0:.+]] = tensor.dim %[[ARG0]], %[[IDX1]]613  // CHECK-DAG: %[[INIT:.+]] = tensor.empty(%[[DIM0]]) : tensor<11x?xf32>614  // CHECK-DAG: %[[IDX1_1:.+]] = arith.constant 1 : index615  // CHECK-DAG: %[[DIM1:.+]] = tensor.dim %[[ARG0]], %[[IDX1_1]]616  // CHECK-DAG: %[[INSERT0:.+]] = tensor.insert_slice %[[ARG0]] into %[[INIT]][0, 0] [5, %[[DIM1]]] [1, 1]617  // CHECK-DAG: %[[IDX1_2:.+]] = arith.constant 1 : index618  // CHECK-DAG: %[[DIM2:.+]] = tensor.dim %[[ARG1]], %[[IDX1_2]] : tensor<6x?xf32>619  // CHECK: %[[INSERT1:.+]] = tensor.insert_slice %[[ARG1]] into %[[INSERT0]][5, 0] [6, %[[DIM2]]] [1, 1]620  %0 = "tosa.concat"(%arg0, %arg1) { axis = 0 : i32} : (tensor<5x?xf32>, tensor<6x?xf32>)  -> (tensor<11x?xf32>)621  return622}623 624// -----625 626// CHECK-LABEL: @concat_axis_dyn627// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:628// CHECK-SAME:  %[[ARG1:[0-9a-zA-Z_]*]]:629func.func @concat_axis_dyn(%arg0: tensor<?x3xf32>, %arg1: tensor<?x3xf32>) -> () {630  // CHECK-DAG: %[[AXIS:.+]] = arith.constant 0 : index631  // CHECK-DAG: %[[IDX0:.+]] = arith.constant 0 : index632  // CHECK-DAG: %[[DIM0:.+]] = tensor.dim %[[ARG0]], %[[IDX0]] : tensor<?x3xf32>633  // CHECK-DAG: %[[DIM1:.+]] = tensor.dim %[[ARG1]], %[[AXIS]] : tensor<?x3xf32>634  // CHECK-DAG: %[[SUM:.+]] = arith.addi %[[DIM0]], %[[DIM1]] : index635  // CHECK-DAG: %[[INIT:.+]] = tensor.empty(%[[SUM]]) : tensor<?x3xf32>636  // CHECK-DAG: %[[IDX0_1:.+]] = arith.constant 0 : index637  // CHECK-DAG: %[[DIM2:.+]] = tensor.dim %[[ARG0]], %[[IDX0_1]] : tensor<?x3xf32>638  // CHECK-DAG: %[[INSERT0:.+]] = tensor.insert_slice %[[ARG0]] into %[[INIT]][0, 0] [%[[DIM2]], 3] [1, 1] : tensor<?x3xf32> into tensor<?x3xf32>639  // CHECK-DAG: %[[IDX0_2:.+]] = arith.constant 0 : index640  // CHECK-DAG: %[[DIM3:.+]] = tensor.dim %[[ARG1]], %[[IDX0_2]] : tensor<?x3xf32>641  // CHECK: %[[INSERT1:.+]] = tensor.insert_slice %[[ARG1]] into %[[INSERT0]][%[[DIM0]], 0] [%[[DIM3]], 3] [1, 1] : tensor<?x3xf32> into tensor<?x3xf32>642 643  %0 = "tosa.concat"(%arg0, %arg1) { axis = 0 : i32} : (tensor<?x3xf32>, tensor<?x3xf32>)  -> (tensor<?x3xf32>)644  return645}646 647// -----648 649// CHECK-LABEL: @concat_axis_dyn_mixed650// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:651// CHECK-SAME:  %[[ARG1:[0-9a-zA-Z_]*]]:652// CHECK-SAME:  %[[ARG2:[0-9a-zA-Z_]*]]:653func.func @concat_axis_dyn_mixed(%arg0: tensor<?x1xf32>, %arg1: tensor<?x1xf32>, %arg2: tensor<?x1xf32>) -> () {654  // CHECK-DAG: %[[C0:.+]] = arith.constant 0 : index655  // CHECK-DAG: %[[C0_0:.+]] = arith.constant 0 : index656  // CHECK-DAG: %[[OFFSET0:.+]] = tensor.dim %[[ARG0]], %[[C0_0]] : tensor<?x1xf32>657  // CHECK-DAG: %[[DIM1_0:.+]] = tensor.dim %[[ARG1]], %[[C0]] : tensor<?x1xf32>658  // CHECK-DAG: %[[OFFSET1:.+]] = arith.addi %[[OFFSET0]], %[[DIM1_0]] : index659  // CHECK-DAG: %[[DIM2_2:.+]] = tensor.dim %[[ARG2]], %[[C0]] : tensor<?x1xf32>660  // CHECK-DAG: %[[OFFSET2:.+]] = arith.addi %[[OFFSET1]], %[[DIM2_2]] : index661  // CHECK-DAG: %[[INIT:.+]] = tensor.empty() : tensor<5x1xf32>662  // CHECK-DAG: %[[C0_3:.+]] = arith.constant 0 : index663  // CHECK-DAG: %[[DIM_4:.+]] = tensor.dim %[[ARG0]], %[[C0_3]] : tensor<?x1xf32>664  // CHECK-DAG: %[[INSERT0:.+]] = tensor.insert_slice %[[ARG0]] into %[[INIT]][0, 0] [%[[DIM_4]], 1] [1, 1] : tensor<?x1xf32> into tensor<5x1xf32>665  // CHECK-DAG: %[[C0_4:.+]] = arith.constant 0 : index666  // CHECK-DAG: %[[DIM_6:.+]] = tensor.dim %[[ARG1]], %[[C0_4]] : tensor<?x1xf32>667  // CHECK-DAG: %[[INSERT1:.+]] = tensor.insert_slice %[[ARG1]] into %[[INSERT0]][%[[OFFSET0]], 0] [%[[DIM_6]], 1] [1, 1] : tensor<?x1xf32> into tensor<5x1xf32>668  // CHECK-DAG: %[[C0_8:.+]] = arith.constant 0 : index669  // CHECK-DAG: %[[DIM_9:.+]] = tensor.dim %[[ARG2]], %[[C0_8]] : tensor<?x1xf32>670  // CHECK-DAG: %[[INSERT3:.+]] = tensor.insert_slice %[[ARG2]] into %[[INSERT1]][%[[OFFSET1]], 0] [%[[DIM_9]], 1] [1, 1] : tensor<?x1xf32> into tensor<5x1xf32>671 672  // CHECK: return673 674  %0 = "tosa.concat"(%arg0, %arg1, %arg2) <{axis = 0 : i32}> : (tensor<?x1xf32>, tensor<?x1xf32>, tensor<?x1xf32>) -> tensor<5x1xf32>675  return676}677 678// -----679 680// CHECK-LABEL: @concat_non_axis_dyn_mixed681// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:682// CHECK-SAME:  %[[ARG1:[0-9a-zA-Z_]*]]:683// CHECK-SAME:  %[[ARG2:[0-9a-zA-Z_]*]]:684func.func @concat_non_axis_dyn_mixed(%arg0: tensor<?x1xf32>, %arg1: tensor<?x1xf32>, %arg2: tensor<?x1xf32>) -> () {685  // CHECK-DAG: %[[UNUSED0:.+]] = arith.constant 0 : index686  // CHECK-DAG: %[[UNUSED1:.+]] = tensor.dim %[[ARG0]], %[[UNUSED0]] : tensor<?x1xf32>687 688  // CHECK-DAG: %[[INIT:.+]] = tensor.empty() : tensor<5x3xf32>689  // CHECK-DAG: %[[C0_0:.+]] = arith.constant 0 : index690  // CHECK-DAG: %[[DIM0_0:.+]] = tensor.dim %[[ARG0]], %[[C0_0]] : tensor<?x1xf32>691  // CHECK-DAG: %[[INSERT0:.+]] = tensor.insert_slice %[[ARG0]] into %[[INIT]][0, 0] [%[[DIM0_0]], 1] [1, 1] : tensor<?x1xf32> into tensor<5x3xf32>692  // CHECK-DAG: %[[C0_1:.+]] = arith.constant 0 : index693  // CHECK-DAG: %[[DIM1_0:.+]] = tensor.dim %[[ARG1]], %[[C0_1]] : tensor<?x1xf32>694  // CHECK-DAG: %[[INSERT1:.+]] = tensor.insert_slice %[[ARG1]] into %[[INSERT0]][0, 1] [%[[DIM1_0]], 1] [1, 1] : tensor<?x1xf32> into tensor<5x3xf32>695  // CHECK-DAG: %[[C0_2:.+]] = arith.constant 0 : index696  // CHECK-DAG: %[[DIM2_0:.+]] = tensor.dim %[[ARG2]], %[[C0_2]] : tensor<?x1xf32>697  // CHECK-DAG: %[[INSERT2:.+]] = tensor.insert_slice %[[ARG2]] into %[[INSERT1]][0, 2] [%[[DIM2_0]], 1] [1, 1] : tensor<?x1xf32> into tensor<5x3xf32>698  // CHECK: return699 700  %0 = "tosa.concat"(%arg0, %arg1, %arg2) <{axis = 1 : i32}> : (tensor<?x1xf32>, tensor<?x1xf32>, tensor<?x1xf32>) -> tensor<5x3xf32>701  return702}703 704// -----705 706// CHECK-LABEL: func @pad_variable_pad_const707// CHECK-SAME: (%[[ARG0_SSA:.*]]: tensor<2x2xi32>, %[[PAD_INPUT_TENSOR_SSA:.*]]: tensor<1xi32>)708func.func @pad_variable_pad_const(%arg0: tensor<2x2xi32>, %pad_input_tensor: tensor<1xi32>) -> tensor<4x5xi32> {709  // CHECK-DAG: %[[C0_INDEX:.*]] = arith.constant 0 : index710  // CHECK-DAG: %[[EXTRACTED_PAD_VAL:.*]] = tensor.extract %[[PAD_INPUT_TENSOR_SSA]][%[[C0_INDEX]]] : tensor<1xi32>711 712  // CHECK: %[[C_PAD_LOW_0:.*]] = arith.constant 1 : index713  // CHECK: %[[C_PAD_HIGH_0:.*]] = arith.constant 1 : index714  // CHECK: %[[C_PAD_LOW_1:.*]] = arith.constant 0 : index715  // CHECK: %[[C_PAD_HIGH_1:.*]] = arith.constant 3 : index716 717  // CHECK: %{{.*}} = tensor.pad %[[ARG0_SSA]] low[%[[C_PAD_LOW_0]], %[[C_PAD_LOW_1]]] high[%[[C_PAD_HIGH_0]], %[[C_PAD_HIGH_1]]] {718  // CHECK:   tensor.yield %[[EXTRACTED_PAD_VAL]] : i32719  // CHECK: } : tensor<2x2xi32> to tensor<4x5xi32>720 721  %padding_indices = tosa.const_shape {values = dense<[1, 1, 0, 3]> : tensor<4xindex>} : () -> !tosa.shape<4>722  %result = "tosa.pad"(%arg0, %padding_indices, %pad_input_tensor) : (tensor<2x2xi32>, !tosa.shape<4>, tensor<1xi32>) -> tensor<4x5xi32>723  return %result : tensor<4x5xi32>724}725