brintos

brintos / llvm-project-archived public Read only

0
0
Text · 24.7 KiB · aa75e02 Raw
416 lines · plain
1// RUN: mlir-opt %s --transform-interpreter --split-input-file | FileCheck %s2 3///----------------------------------------------------------------------------------------4/// arith.extsi5///6/// [Pattern: RewriteAlignedSubByteIntExt]7///----------------------------------------------------------------------------------------8// Negative test - the trailing dim 1 is not a multiple of 2 (i.e. 8 / 4).9// CHECK-LABEL: func.func @unaligned_extsi_i4_to_i8(10func.func @unaligned_extsi_i4_to_i8(%a: vector<1xi4>) -> vector<1xi8> {11  // CHECK-NOT: arith.bitcast12  // CHECK: arith.extsi %[[IN:.*]] : vector<1xi4> to vector<1xi8>13  %0 = arith.extsi %a : vector<1xi4> to vector<1xi8>14  return %0 : vector<1xi8>15}16 17// Negative test - the trailing dim 2 is not a multiple of 4 (i.e. 8 / 2).18// CHECK-LABEL: func.func @unaligned_extsi_i2_to_i8(19func.func @unaligned_extsi_i2_to_i8(%a: vector<2xi2>) -> vector<2xi8> {20  // CHECK-NOT: arith.bitcast21  // CHECK: arith.extsi %[[IN:.*]] : vector<2xi2> to vector<2xi8>22  %0 = arith.extsi %a : vector<2xi2> to vector<2xi8>23  return %0 : vector<2xi8>24}25 26// CHECK-LABEL: func.func @aligned_extsi_i4_to_i8(27func.func @aligned_extsi_i4_to_i8(%a: vector<8xi4>) -> vector<8xi8> {28// CHECK-SAME:    %[[IN:.*]]: vector<8xi4>) -> vector<8xi8> {29// CHECK:           %[[I4_BITS:.*]] = arith.constant dense<4> : vector<4xi8>30// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[IN]] : vector<8xi4> to vector<4xi8>31// CHECK:           %[[SHL_LOW:.*]] = arith.shli %[[BITCAST]], %[[I4_BITS]] : vector<4xi8>32// CHECK:           %[[LOW:.*]] = arith.shrsi %[[SHL_LOW]], %[[I4_BITS]] : vector<4xi8>33// CHECK:           %[[HIGH:.*]] = arith.shrsi %[[BITCAST]], %[[I4_BITS]] : vector<4xi8>34// CHECK:           %[[INTERLEAVE:.*]] = vector.interleave %[[LOW]], %[[HIGH]] : vector<4xi8>35  %0 = arith.extsi %a : vector<8xi4> to vector<8xi8>36  return %0 : vector<8xi8>37}38 39// CHECK-LABEL: func.func @aligned_extsi_i2_to_i8(40func.func @aligned_extsi_i2_to_i8(%a: vector<8xi2>) -> vector<8xi8> {41// CHECK-SAME:      %[[IN:.*]]: vector<8xi2>) -> vector<8xi8> {42// CHECK:           %[[CST_2:.*]] = arith.constant dense<2> : vector<2xi8>43// CHECK:           %[[CST_4:.*]] = arith.constant dense<4> : vector<2xi8>44// CHECK:           %[[CST_6:.*]] = arith.constant dense<6> : vector<2xi8>45// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[IN]] : vector<8xi2> to vector<2xi8>46// Extract bits 0-147// CHECK:           %[[SHL_6:.*]] = arith.shli %[[BITCAST]], %[[CST_6]] : vector<2xi8>48// CHECK:           %[[ELEM0:.*]] = arith.shrsi %[[SHL_6]], %[[CST_6]] : vector<2xi8>49// Extract bits 2-350// CHECK:           %[[SHL_4:.*]] = arith.shli %[[BITCAST]], %[[CST_4]] : vector<2xi8>51// CHECK:           %[[ELEM1:.*]] = arith.shrsi %[[SHL_4]], %[[CST_6]] : vector<2xi8>52// Extract bits 4-553// CHECK:           %[[SHL_2:.*]] = arith.shli %[[BITCAST]], %[[CST_2]] : vector<2xi8>54// CHECK:           %[[ELEM2:.*]] = arith.shrsi %[[SHL_2]], %[[CST_6]] : vector<2xi8>55// Extract bits 6-756// CHECK:           %[[ELEM3:.*]] = arith.shrsi %[[BITCAST]], %[[CST_6]] : vector<2xi8>57// CHECK:           %[[INTERLEAVE02:.*]] = vector.interleave %[[ELEM0]], %[[ELEM2]] : vector<2xi8>58// CHECK:           %[[INTERLEAVE13:.*]] = vector.interleave %[[ELEM1]], %[[ELEM3]] : vector<2xi8>59// CHECK:           %[[RESULT:.*]] = vector.interleave %[[INTERLEAVE02]], %[[INTERLEAVE13]] : vector<4xi8>60  %0 = arith.extsi %a : vector<8xi2> to vector<8xi8>61  return %0 : vector<8xi8>62}63 64// CHECK-LABEL: func.func @aligned_extsi_i4_to_i32(65func.func @aligned_extsi_i4_to_i32(%a: vector<8xi4>) -> vector<8xi32> {66// CHECK-SAME:    %[[IN:.*]]: vector<8xi4>) -> vector<8xi32> {67// CHECK:           %[[I4_BITS:.*]] = arith.constant dense<4> : vector<4xi8>68// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[IN]] : vector<8xi4> to vector<4xi8>69// CHECK:           %[[SHL_LOW:.*]] = arith.shli %[[BITCAST]], %[[I4_BITS]] : vector<4xi8>70// CHECK:           %[[LOW:.*]] = arith.shrsi %[[SHL_LOW]], %[[I4_BITS]] : vector<4xi8>71// CHECK:           %[[HIGH:.*]] = arith.shrsi %[[BITCAST]], %[[I4_BITS]] : vector<4xi8>72// CHECK:           %[[INTERLEAVE:.*]] = vector.interleave %[[LOW]], %[[HIGH]] : vector<4xi8>73// CHECK:           %[[I32:.*]] = arith.extsi %[[INTERLEAVE]] : vector<8xi8> to vector<8xi32>74  %0 = arith.extsi %a : vector<8xi4> to vector<8xi32>75  return %0 : vector<8xi32>76}77 78// CHECK-LABEL: func.func @aligned_extsi_i2_to_i32(79func.func @aligned_extsi_i2_to_i32(%a: vector<8xi2>) -> vector<8xi32> {80// CHECK-SAME:      %[[IN:.*]]: vector<8xi2>) -> vector<8xi32> {81// CHECK:           %[[CST_2:.*]] = arith.constant dense<2> : vector<2xi8>82// CHECK:           %[[CST_4:.*]] = arith.constant dense<4> : vector<2xi8>83// CHECK:           %[[CST_6:.*]] = arith.constant dense<6> : vector<2xi8>84// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[IN]] : vector<8xi2> to vector<2xi8>85// Extract bits 0-186// CHECK:           %[[SHL_6:.*]] = arith.shli %[[BITCAST]], %[[CST_6]] : vector<2xi8>87// CHECK:           %[[ELEM0:.*]] = arith.shrsi %[[SHL_6]], %[[CST_6]] : vector<2xi8>88// Extract bits 2-389// CHECK:           %[[SHL_4:.*]] = arith.shli %[[BITCAST]], %[[CST_4]] : vector<2xi8>90// CHECK:           %[[ELEM1:.*]] = arith.shrsi %[[SHL_4]], %[[CST_6]] : vector<2xi8>91// Extract bits 4-592// CHECK:           %[[SHL_2:.*]] = arith.shli %[[BITCAST]], %[[CST_2]] : vector<2xi8>93// CHECK:           %[[ELEM2:.*]] = arith.shrsi %[[SHL_2]], %[[CST_6]] : vector<2xi8>94// Extract bits 6-795// CHECK:           %[[ELEM3:.*]] = arith.shrsi %[[BITCAST]], %[[CST_6]] : vector<2xi8>96// CHECK:           %[[INTERLEAVE02:.*]] = vector.interleave %[[ELEM0]], %[[ELEM2]] : vector<2xi8>97// CHECK:           %[[INTERLEAVE13:.*]] = vector.interleave %[[ELEM1]], %[[ELEM3]] : vector<2xi8>98// CHECK:           %[[INTERLEAVE:.*]] = vector.interleave %[[INTERLEAVE02]], %[[INTERLEAVE13]] : vector<4xi8>99// CHECK:           %[[RESULT:.*]] = arith.extsi %[[INTERLEAVE]] : vector<8xi8> to vector<8xi32>100  %0 = arith.extsi %a : vector<8xi2> to vector<8xi32>101  return %0 : vector<8xi32>102}103 104// CHECK-LABEL: func.func @aligned_extsi_i4_to_i32_2d(105func.func @aligned_extsi_i4_to_i32_2d(%a: vector<8x32xi4>) -> vector<8x32xi32> {106// CHECK-SAME:    %[[IN:.*]]: vector<8x32xi4>) -> vector<8x32xi32> {107// CHECK:           %[[I4_BITS:.*]] = arith.constant dense<4> : vector<8x16xi8>108// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[IN]] : vector<8x32xi4> to vector<8x16xi8>109// CHECK:           %[[SHL_LOW:.*]] = arith.shli %[[BITCAST]], %[[I4_BITS]] : vector<8x16xi8>110// CHECK:           %[[LOW:.*]] = arith.shrsi %[[SHL_LOW]], %[[I4_BITS]] : vector<8x16xi8>111// CHECK:           %[[HIGH:.*]] = arith.shrsi %[[BITCAST]], %[[I4_BITS]] : vector<8x16xi8>112// CHECK:           %[[INTERLEAVE:.*]] = vector.interleave %[[LOW]], %[[HIGH]] : vector<8x16xi8>113// CHECK:           %[[I32:.*]] = arith.extsi %[[INTERLEAVE]] : vector<8x32xi8> to vector<8x32xi32>114  %0 = arith.extsi %a : vector<8x32xi4> to vector<8x32xi32>115  return %0 : vector<8x32xi32>116}117 118// CHECK-LABEL: func.func @aligned_extsi_i2_to_i32_2d(119func.func @aligned_extsi_i2_to_i32_2d(%a: vector<8x32xi2>) -> vector<8x32xi32> {120// CHECK-SAME:      %[[IN:.*]]: vector<8x32xi2>) -> vector<8x32xi32> {121// CHECK:           %[[CST_2:.*]] = arith.constant dense<2> : vector<8x8xi8>122// CHECK:           %[[CST_4:.*]] = arith.constant dense<4> : vector<8x8xi8>123// CHECK:           %[[CST_6:.*]] = arith.constant dense<6> : vector<8x8xi8>124// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[IN]] : vector<8x32xi2> to vector<8x8xi8>125// Extract bits 0-1126// CHECK:           %[[SHL_6:.*]] = arith.shli %[[BITCAST]], %[[CST_6]] : vector<8x8xi8>127// CHECK:           %[[ELEM0:.*]] = arith.shrsi %[[SHL_6]], %[[CST_6]] : vector<8x8xi8>128// Extract bits 2-3129// CHECK:           %[[SHL_4:.*]] = arith.shli %[[BITCAST]], %[[CST_4]] : vector<8x8xi8>130// CHECK:           %[[ELEM1:.*]] = arith.shrsi %[[SHL_4]], %[[CST_6]] : vector<8x8xi8>131// Extract bits 4-5132// CHECK:           %[[SHL_2:.*]] = arith.shli %[[BITCAST]], %[[CST_2]] : vector<8x8xi8>133// CHECK:           %[[ELEM2:.*]] = arith.shrsi %[[SHL_2]], %[[CST_6]] : vector<8x8xi8>134// Extract bits 6-7135// CHECK:           %[[ELEM3:.*]] = arith.shrsi %[[BITCAST]], %[[CST_6]] : vector<8x8xi8>136// CHECK:           %[[INTERLEAVE02:.*]] = vector.interleave %[[ELEM0]], %[[ELEM2]] : vector<8x8xi8>137// CHECK:           %[[INTERLEAVE13:.*]] = vector.interleave %[[ELEM1]], %[[ELEM3]] : vector<8x8xi8>138// CHECK:           %[[INTERLEAVE:.*]] = vector.interleave %[[INTERLEAVE02]], %[[INTERLEAVE13]] : vector<8x16xi8>139// CHECK:           %[[RESULT:.*]] = arith.extsi %[[INTERLEAVE]] : vector<8x32xi8> to vector<8x32xi32>140  %0 = arith.extsi %a : vector<8x32xi2> to vector<8x32xi32>141  return %0 : vector<8x32xi32>142}143 144///----------------------------------------------------------------------------------------145/// arith.trunci146///147/// [Pattern: RewriteAlignedSubByteIntTrunc]148///----------------------------------------------------------------------------------------149// CHECK-LABEL: func.func @aligned_trunci_i8_to_i4(150func.func @aligned_trunci_i8_to_i4(%a: vector<8xi8>) -> vector<8xi4> {151// CHECK-SAME:    %[[IN:.*]]: vector<8xi8>) -> vector<8xi4> {152// CHECK-DAG:       %[[LOW_MASK:.*]] = arith.constant dense<15> : vector<4xi8>153// CHECK-DAG:       %[[I4_BITS:.*]] = arith.constant dense<4> : vector<4xi8>154// CHECK:           %[[LOW:.*]], %[[HIGH:.*]] = vector.deinterleave %[[IN]] : vector<8xi8> -> vector<4xi8>155// CHECK:           %[[ZEROED_LOW:.*]] = arith.andi %[[LOW]], %[[LOW_MASK]] : vector<4xi8>156// CHECK:           %[[SHL_HIGH:.*]] = arith.shli %[[HIGH]], %[[I4_BITS]] : vector<4xi8>157// CHECK:           %[[MERGED:.*]] = arith.ori %[[ZEROED_LOW]], %[[SHL_HIGH]] : vector<4xi8>158// CHECK:           %[[I4:.*]] = vector.bitcast %[[MERGED]] : vector<4xi8> to vector<8xi4>159  %0 = arith.trunci %a : vector<8xi8> to vector<8xi4>160  return %0 : vector<8xi4>161}162 163// CHECK-LABEL: func.func @aligned_trunci_i32_to_i4(164func.func @aligned_trunci_i32_to_i4(%a: vector<8xi32>) -> vector<8xi4> {165// CHECK-SAME:    %[[IN:.*]]: vector<8xi32>) -> vector<8xi4> {166// CHECK-DAG:       %[[LOW_MASK:.*]] = arith.constant dense<15> : vector<4xi8>167// CHECK-DAG:       %[[I4_BITS:.*]] = arith.constant dense<4> : vector<4xi8>168// CHECK:           %[[I8:.*]] = arith.trunci %[[IN]] : vector<8xi32> to vector<8xi8>169// CHECK:           %[[LOW:.*]], %[[HIGH:.*]] = vector.deinterleave %[[I8]] : vector<8xi8> -> vector<4xi8>170// CHECK:           %[[ZEROED_LOW:.*]] = arith.andi %[[LOW]], %[[LOW_MASK]] : vector<4xi8>171// CHECK:           %[[SHL_HIGH:.*]] = arith.shli %[[HIGH]], %[[I4_BITS]] : vector<4xi8>172// CHECK:           %[[MERGED:.*]] = arith.ori %[[ZEROED_LOW]], %[[SHL_HIGH]] : vector<4xi8>173// CHECK:           %[[I4:.*]] = vector.bitcast %[[MERGED]] : vector<4xi8> to vector<8xi4>174  %0 = arith.trunci %a : vector<8xi32> to vector<8xi4>175  return %0 : vector<8xi4>176}177 178// CHECK-LABEL: func.func @aligned_trunci_2d(179func.func @aligned_trunci_2d(%a: vector<8x32xi32>) -> vector<8x32xi4> {180// CHECK-NOT:       vector.shuffle181// CHECK-NOT:       vector.andi182// CHECK-NOT:       vector.shli183// CHECK-NOT:       vector.ori184// CHECK:           arith.trunci {{.*}} : vector<8x32xi32> to vector<8x32xi8>185// CHECK-NOT:       arith.trunci {{.*}} : vector<8x32xi8> to vector<8x32xi4>186// CHECK:           vector.deinterleave187  %0 = arith.trunci %a : vector<8x32xi32> to vector<8x32xi4>188  return %0 : vector<8x32xi4>189}190 191// CHECK-LABEL: func.func @aligned_trunci_nd(192// CHECK-SAME: %[[IN:.*]]: vector<3x8x32xi32>) -> vector<3x8x32xi4> {193func.func @aligned_trunci_nd(%a: vector<3x8x32xi32>) -> vector<3x8x32xi4> {194  // CHECK: %[[LEFT_SHIFT_BITS:.*]] = arith.constant dense<4> : vector<3x8x16xi8>195  // CHECK: %[[I4_MASK:.*]] = arith.constant dense<15> : vector<3x8x16xi8>196  // CHECK: %[[I8:.*]] = arith.trunci %[[IN]] : vector<3x8x32xi32> to vector<3x8x32xi8>197  // CHECK: %[[LOW:.*]], %[[HIGH:.*]] = vector.deinterleave %[[I8]] : vector<3x8x32xi8> -> vector<3x8x16xi8>198  // CHECK: %[[ZEROED_LOW:.*]] = arith.andi %[[LOW]], %[[I4_MASK]] : vector<3x8x16xi8>199  // CHECK: %[[SHL_HIGH:.*]] = arith.shli %[[HIGH]], %[[LEFT_SHIFT_BITS]] : vector<3x8x16xi8>200  // CHECK: %[[MERGED:.*]] = arith.ori %[[ZEROED_LOW]], %[[SHL_HIGH]] : vector<3x8x16xi8>201  // CHECK: %[[I4:.*]] = vector.bitcast %[[MERGED]] : vector<3x8x16xi8> to vector<3x8x32xi4>202  %0 = arith.trunci %a : vector<3x8x32xi32> to vector<3x8x32xi4>203  return %0 : vector<3x8x32xi4>204}205 206func.func @aligned_trunci_i8_to_i2_no_match(%a: vector<8xi8>) -> vector<8xi2> {207  // CHECK-NOT: arith.bitcast208  // CHECK: arith.trunci %[[IN:.*]] : vector<8xi8> to vector<8xi2>209  %0 = arith.trunci %a : vector<8xi8> to vector<8xi2>210  return %0 : vector<8xi2>211}212 213///----------------------------------------------------------------------------------------214/// arith.extui215///216/// [Pattern: RewriteAlignedSubByteIntExt]217///----------------------------------------------------------------------------------------218 219// CHECK-LABEL: func.func @aligned_extui_i4_to_i8(220func.func @aligned_extui_i4_to_i8(%a: vector<8xi4>) -> vector<8xi8> {221// CHECK-SAME:                             %[[IN:.*]]: vector<8xi4>) -> vector<8xi8> {222// CHECK:           %[[I4_BITS:.*]] = arith.constant dense<4> : vector<4xi8>223// CHECK:           %[[LOWBITS_MASK:.*]] = arith.constant dense<15> : vector<4xi8>224// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[IN]] : vector<8xi4> to vector<4xi8>225// CHECK:           %[[LOW:.*]] = arith.andi %[[BITCAST]], %[[LOWBITS_MASK]] : vector<4xi8>226// CHECK:           %[[HIGH:.*]] = arith.shrui %[[BITCAST]], %[[I4_BITS]] : vector<4xi8>227// CHECK:           %[[INTERLEAVE:.*]] = vector.interleave %[[LOW]], %[[HIGH]] : vector<4xi8>228  %0 = arith.extui %a : vector<8xi4> to vector<8xi8>229  return %0 : vector<8xi8>230}231 232// CHECK-LABEL: func.func @aligned_extui_i2_to_i8(233func.func @aligned_extui_i2_to_i8(%a: vector<8xi2>) -> vector<8xi8> {234// CHECK-SAME:      %[[IN:.*]]: vector<8xi2>) -> vector<8xi8> {235// CHECK:           %[[CST_6:.*]] = arith.constant dense<6> : vector<2xi8>236// CHECK:           %[[CST_4:.*]] = arith.constant dense<4> : vector<2xi8>237// CHECK:           %[[CST_2:.*]] = arith.constant dense<2> : vector<2xi8>238// CHECK:           %[[LOWBITS_MASK:.*]] = arith.constant dense<3> : vector<2xi8>239// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[IN]] : vector<8xi2> to vector<2xi8>240// Extract bits 0-1241// CHECK:           %[[ELEM0:.*]] = arith.andi %[[BITCAST]], %[[LOWBITS_MASK]] : vector<2xi8>242// Extract bits 2-3243// CHECK:           %[[SHR_2:.*]] = arith.shrui %[[BITCAST]], %[[CST_2]] : vector<2xi8>244// CHECK:           %[[ELEM1:.*]] = arith.andi %[[SHR_2]], %[[LOWBITS_MASK]] : vector<2xi8>245// Extract bits 4-5246// CHECK:           %[[SHR_4:.*]] = arith.shrui %[[BITCAST]], %[[CST_4]] : vector<2xi8>247// CHECK:           %[[ELEM2:.*]] = arith.andi %[[SHR_4]], %[[LOWBITS_MASK]] : vector<2xi8>248// Extract bits 6-7249// CHECK:           %[[ELEM3:.*]] = arith.shrui %[[BITCAST]], %[[CST_6]] : vector<2xi8>250// CHECK:           %[[INTERLEAVE02:.*]] = vector.interleave %[[ELEM0]], %[[ELEM2]] : vector<2xi8>251// CHECK:           %[[INTERLEAVE13:.*]] = vector.interleave %[[ELEM1]], %[[ELEM3]] : vector<2xi8>252// CHECK:           %[[RESULT:.*]] = vector.interleave %[[INTERLEAVE02]], %[[INTERLEAVE13]] : vector<4xi8>253  %0 = arith.extui %a : vector<8xi2> to vector<8xi8>254  return %0 : vector<8xi8>255}256 257// CHECK-LABEL: func.func @aligned_extui_i4_to_i32(258func.func @aligned_extui_i4_to_i32(%a: vector<8xi4>) -> vector<8xi32> {259// CHECK-SAME:                             %[[IN:.*]]: vector<8xi4>) -> vector<8xi32> {260// CHECK:           %[[I4_BITS:.*]] = arith.constant dense<4> : vector<4xi8>261// CHECK:           %[[LOWBITS_MASK:.*]] = arith.constant dense<15> : vector<4xi8>262// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[IN]] : vector<8xi4> to vector<4xi8>263// CHECK:           %[[LOW:.*]] = arith.andi %[[BITCAST]], %[[LOWBITS_MASK]] : vector<4xi8>264// CHECK:           %[[HIGH:.*]] = arith.shrui %[[BITCAST]], %[[I4_BITS]] : vector<4xi8>265// CHECK:           %[[INTERLEAVE:.*]] = vector.interleave %[[LOW]], %[[HIGH]] : vector<4xi8>266// CHECK:           %[[I32:.*]] = arith.extui %[[INTERLEAVE]] : vector<8xi8> to vector<8xi32>267  %0 = arith.extui %a : vector<8xi4> to vector<8xi32>268  return %0 : vector<8xi32>269}270 271// CHECK-LABEL: func.func @aligned_extui_i2_to_i32(272func.func @aligned_extui_i2_to_i32(%a: vector<8xi2>) -> vector<8xi32> {273// CHECK-SAME:      %[[IN:.*]]: vector<8xi2>) -> vector<8xi32> {274// CHECK:           %[[CST_6:.*]] = arith.constant dense<6> : vector<2xi8>275// CHECK:           %[[CST_4:.*]] = arith.constant dense<4> : vector<2xi8>276// CHECK:           %[[CST_2:.*]] = arith.constant dense<2> : vector<2xi8>277// CHECK:           %[[LOWBITS_MASK:.*]] = arith.constant dense<3> : vector<2xi8>278// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[IN]] : vector<8xi2> to vector<2xi8>279// Extract bits 0-1280// CHECK:           %[[ELEM0:.*]] = arith.andi %[[BITCAST]], %[[LOWBITS_MASK]] : vector<2xi8>281// Extract bits 2-3282// CHECK:           %[[SHR_2:.*]] = arith.shrui %[[BITCAST]], %[[CST_2]] : vector<2xi8>283// CHECK:           %[[ELEM1:.*]] = arith.andi %[[SHR_2]], %[[LOWBITS_MASK]] : vector<2xi8>284// Extract bits 4-5285// CHECK:           %[[SHR_4:.*]] = arith.shrui %[[BITCAST]], %[[CST_4]] : vector<2xi8>286// CHECK:           %[[ELEM2:.*]] = arith.andi %[[SHR_4]], %[[LOWBITS_MASK]] : vector<2xi8>287// Extract bits 6-7288// CHECK:           %[[ELEM3:.*]] = arith.shrui %[[BITCAST]], %[[CST_6]] : vector<2xi8>289// CHECK:           %[[INTERLEAVE02:.*]] = vector.interleave %[[ELEM0]], %[[ELEM2]] : vector<2xi8>290// CHECK:           %[[INTERLEAVE13:.*]] = vector.interleave %[[ELEM1]], %[[ELEM3]] : vector<2xi8>291// CHECK:           %[[INTERLEAVE:.*]] = vector.interleave %[[INTERLEAVE02]], %[[INTERLEAVE13]] : vector<4xi8>292// CHECK:           %[[RESULT:.*]] = arith.extui %[[INTERLEAVE]] : vector<8xi8> to vector<8xi32>293  %0 = arith.extui %a : vector<8xi2> to vector<8xi32>294  return %0 : vector<8xi32>295}296 297// CHECK-LABEL: func.func @aligned_extui_i4_to_i32_2d(298func.func @aligned_extui_i4_to_i32_2d(%a: vector<8x32xi4>) -> vector<8x32xi32> {299// CHECK-SAME:                                %[[VAL_0:.*]]: vector<8x32xi4>) -> vector<8x32xi32> {300// CHECK:           %[[I4_BITS:.*]] = arith.constant dense<4> : vector<8x16xi8>301// CHECK:           %[[LOWBITS_MASK:.*]] = arith.constant dense<15> : vector<8x16xi8>302// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[VAL_0]] : vector<8x32xi4> to vector<8x16xi8>303// CHECK:           %[[LOW:.*]] = arith.andi %[[BITCAST]], %[[LOWBITS_MASK]] : vector<8x16xi8>304// CHECK:           %[[HIGH:.*]] = arith.shrui %[[BITCAST]], %[[I4_BITS]] : vector<8x16xi8>305// CHECK:           %[[INTERLEAVE:.*]] = vector.interleave %[[LOW]], %[[HIGH]] : vector<8x16xi8>306// CHECK:           %[[I32:.*]] = arith.extui %[[INTERLEAVE]] : vector<8x32xi8> to vector<8x32xi32>307  %0 = arith.extui %a : vector<8x32xi4> to vector<8x32xi32>308  return %0 : vector<8x32xi32>309}310 311// CHECK-LABEL: func.func @aligned_extui_i2_to_i32_2d(312func.func @aligned_extui_i2_to_i32_2d(%a: vector<8x32xi2>) -> vector<8x32xi32> {313// CHECK-SAME:      %[[IN:.*]]: vector<8x32xi2>) -> vector<8x32xi32> {314// CHECK:           %[[CST_6:.*]] = arith.constant dense<6> : vector<8x8xi8>315// CHECK:           %[[CST_4:.*]] = arith.constant dense<4> : vector<8x8xi8>316// CHECK:           %[[CST_2:.*]] = arith.constant dense<2> : vector<8x8xi8>317// CHECK:           %[[LOWBITS_MASK:.*]] = arith.constant dense<3> : vector<8x8xi8>318// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[IN]] : vector<8x32xi2> to vector<8x8xi8>319// Extract bits 0-1320// CHECK:           %[[ELEM0:.*]] = arith.andi %[[BITCAST]], %[[LOWBITS_MASK]] : vector<8x8xi8>321// Extract bits 2-3322// CHECK:           %[[SHR_2:.*]] = arith.shrui %[[BITCAST]], %[[CST_2]] : vector<8x8xi8>323// CHECK:           %[[ELEM1:.*]] = arith.andi %[[SHR_2]], %[[LOWBITS_MASK]] : vector<8x8xi8>324// Extract bits 4-5325// CHECK:           %[[SHR_4:.*]] = arith.shrui %[[BITCAST]], %[[CST_4]] : vector<8x8xi8>326// CHECK:           %[[ELEM2:.*]] = arith.andi %[[SHR_4]], %[[LOWBITS_MASK]] : vector<8x8xi8>327// Extract bits 6-7328// CHECK:           %[[ELEM3:.*]] = arith.shrui %[[BITCAST]], %[[CST_6]] : vector<8x8xi8>329// CHECK:           %[[INTERLEAVE02:.*]] = vector.interleave %[[ELEM0]], %[[ELEM2]] : vector<8x8xi8>330// CHECK:           %[[INTERLEAVE13:.*]] = vector.interleave %[[ELEM1]], %[[ELEM3]] : vector<8x8xi8>331// CHECK:           %[[INTERLEAVE:.*]] = vector.interleave %[[INTERLEAVE02]], %[[INTERLEAVE13]] : vector<8x16xi8>332// CHECK:           %[[RESULT:.*]] = arith.extui %[[INTERLEAVE]] : vector<8x32xi8> to vector<8x32xi32>333  %0 = arith.extui %a : vector<8x32xi2> to vector<8x32xi32>334  return %0 : vector<8x32xi32>335}336 337///----------------------------------------------------------------------------------------338/// arith.sitofp339///340/// [Pattern: RewriteAlignedSubByteIntExt]341///----------------------------------------------------------------------------------------342 343// CHECK-LABEL: func.func @aligned_sitofp(344func.func @aligned_sitofp(%a: vector<8xi4>) -> vector<8xf32> {345// CHECK-SAME:    %[[IN:.*]]: vector<8xi4>) -> vector<8xf32> {346// CHECK:           %[[I4_BITS:.*]] = arith.constant dense<4> : vector<4xi8>347// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[IN]] : vector<8xi4> to vector<4xi8>348// CHECK:           %[[SHL_LOW:.*]] = arith.shli %[[BITCAST]], %[[I4_BITS]] : vector<4xi8>349// CHECK:           %[[LOW:.*]] = arith.shrsi %[[SHL_LOW]], %[[I4_BITS]] : vector<4xi8>350// CHECK:           %[[HIGH:.*]] = arith.shrsi %[[BITCAST]], %[[I4_BITS]] : vector<4xi8>351// CHECK:           %[[INTERLEAVE:.*]] = vector.interleave %[[LOW]], %[[HIGH]] : vector<4xi8>352// CHECK:           %[[F32:.*]] = arith.sitofp %[[INTERLEAVE]] : vector<8xi8> to vector<8xf32>353  %0 = arith.sitofp %a : vector<8xi4> to vector<8xf32>354  return %0 : vector<8xf32>355}356 357// CHECK-LABEL: func.func @aligned_sitofp_2d(358func.func @aligned_sitofp_2d(%a: vector<8x32xi4>) -> vector<8x32xf32> {359// CHECK-SAME:    %[[IN:.*]]: vector<8x32xi4>) -> vector<8x32xf32> {360// CHECK:           %[[I4_BITS:.*]] = arith.constant dense<4> : vector<8x16xi8>361// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[IN]] : vector<8x32xi4> to vector<8x16xi8>362// CHECK:           %[[SHL_LOW:.*]] = arith.shli %[[BITCAST]], %[[I4_BITS]] : vector<8x16xi8>363// CHECK:           %[[LOW:.*]] = arith.shrsi %[[SHL_LOW]], %[[I4_BITS]] : vector<8x16xi8>364// CHECK:           %[[HIGH:.*]] = arith.shrsi %[[BITCAST]], %[[I4_BITS]] : vector<8x16xi8>365// CHECK:           %[[INTERLEAVE:.*]] = vector.interleave %[[LOW]], %[[HIGH]] : vector<8x16xi8>366// CHECK:           %[[F32:.*]] = arith.sitofp %[[INTERLEAVE]] : vector<8x32xi8> to vector<8x32xf32>367  %0 = arith.sitofp %a : vector<8x32xi4> to vector<8x32xf32>368  return %0 : vector<8x32xf32>369}370 371///----------------------------------------------------------------------------------------372/// arith.uitofp373///374/// [Pattern: RewriteAlignedSubByteIntExt]375///----------------------------------------------------------------------------------------376 377// CHECK-LABEL: func.func @aligned_uitofp(378func.func @aligned_uitofp(%a: vector<8xi4>) -> vector<8xf32> {379// CHECK-SAME:    %[[IN:.*]]: vector<8xi4>) -> vector<8xf32> {380// CHECK:           %[[I4_BITS:.*]] = arith.constant dense<4> : vector<4xi8>381// CHECK:           %[[LOWBITS_MASK:.*]] = arith.constant dense<15> : vector<4xi8>382// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[IN]] : vector<8xi4> to vector<4xi8>383// CHECK:           %[[LOW:.*]] = arith.andi %[[BITCAST]], %[[LOWBITS_MASK]] : vector<4xi8>384// CHECK:           %[[HIGH:.*]] = arith.shrui %[[BITCAST]], %[[I4_BITS]] : vector<4xi8>385// CHECK:           %[[INTERLEAVE:.*]] = vector.interleave %[[LOW]], %[[HIGH]] : vector<4xi8>386// CHECK:           %[[F32:.*]] = arith.uitofp %[[INTERLEAVE]] : vector<8xi8> to vector<8xf32>387  %0 = arith.uitofp %a : vector<8xi4> to vector<8xf32>388  return %0 : vector<8xf32>389}390 391// CHECK-LABEL: func.func @aligned_uitofp_2d(392func.func @aligned_uitofp_2d(%a: vector<8x32xi4>) -> vector<8x32xf32> {393// CHECK-SAME:    %[[IN:.*]]: vector<8x32xi4>) -> vector<8x32xf32> {394// CHECK:           %[[I4_BITS:.*]] = arith.constant dense<4> : vector<8x16xi8>395// CHECK:           %[[LOWBITS_MASK:.*]] = arith.constant dense<15> : vector<8x16xi8>396// CHECK:           %[[BITCAST:.*]] = vector.bitcast %[[IN]] : vector<8x32xi4> to vector<8x16xi8>397// CHECK:           %[[LOW:.*]] = arith.andi %[[BITCAST]], %[[LOWBITS_MASK]] : vector<8x16xi8>398// CHECK:           %[[HIGH:.*]] = arith.shrui %[[BITCAST]], %[[I4_BITS]] : vector<8x16xi8>399// CHECK:           %[[INTERLEAVE:.*]] = vector.interleave %[[LOW]], %[[HIGH]] : vector<8x16xi8>400// CHECK:           %[[F32:.*]] = arith.uitofp %[[INTERLEAVE]] : vector<8x32xi8> to vector<8x32xf32>401  %0 = arith.uitofp %a : vector<8x32xi4> to vector<8x32xf32>402  return %0 : vector<8x32xf32>403}404 405module attributes {transform.with_named_sequence} {406  transform.named_sequence @__transform_main(%module_op: !transform.any_op {transform.readonly}) {407    %f = transform.structured.match ops{["func.func"]} in %module_op408        : (!transform.any_op) -> !transform.any_op409 410    transform.apply_patterns to %f {411      transform.apply_patterns.vector.rewrite_narrow_types412    } : !transform.any_op413    transform.yield414  }415}416