brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.5 KiB · 6c2183f Raw
167 lines · plain
1// RUN: mlir-opt %s -test-lower-to-llvm | \2// RUN: mlir-runner -e entry -entry-point-result=void \3// RUN:   -shared-libs=%mlir_c_runner_utils | \4// RUN: FileCheck %s5 6func.func @extract_element_0d(%a: vector<f32>) {7  %1 = vector.extract %a[] : f32 from vector<f32>8  // CHECK: 429  vector.print %1: f3210  return11}12 13func.func @insert_element_0d(%a: f32, %b: vector<f32>) -> (vector<f32>) {14  %1 = vector.insert %a, %b[] : f32 into vector<f32>15  return %1: vector<f32>16}17 18func.func @print_vector_0d(%a: vector<f32>) {19  // CHECK: ( 42 )20  vector.print %a: vector<f32>21  return22}23 24func.func @broadcast_0d(%a: f32) {25  %1 = vector.broadcast %a : f32 to vector<f32>26  // CHECK: ( 42 )27  vector.print %1: vector<f32>28 29  %2 = vector.broadcast %1 : vector<f32> to vector<f32>30  // CHECK: ( 42 )31  vector.print %2: vector<f32>32 33  %3 = vector.broadcast %1 : vector<f32> to vector<1xf32>34  // CHECK: ( 42 )35  vector.print %3: vector<1xf32>36 37  %4 = vector.broadcast %1 : vector<f32> to vector<2xf32>38  // CHECK: ( 42, 42 )39  vector.print %4: vector<2xf32>40 41  %5 = vector.broadcast %1 : vector<f32> to vector<2x1xf32>42  // CHECK: ( ( 42 ), ( 42 ) )43  vector.print %5: vector<2x1xf32>44 45  %6 = vector.broadcast %1 : vector<f32> to vector<2x3xf32>46  // CHECK: ( ( 42, 42, 42 ), ( 42, 42, 42 ) )47  vector.print %6: vector<2x3xf32>48  return49}50 51func.func @bitcast_0d() {52  %0 = arith.constant 42 : i3253  %1 = arith.constant dense<0> : vector<i32>54  %2 = vector.insert %0, %1[] : i32 into vector<i32>55  %3 = vector.bitcast %2 : vector<i32> to vector<f32>56  %4 = vector.extract %3[] : f32 from vector<f32>57  %5 = arith.bitcast %4 : f32 to i3258  // CHECK: 4259  vector.print %5: i3260  return61}62 63func.func @constant_mask_0d() {64  %1 = vector.constant_mask [0] : vector<i1>65  // CHECK: ( 0 )66  vector.print %1: vector<i1>67  %2 = vector.constant_mask [1] : vector<i1>68  // CHECK: ( 1 )69  vector.print %2: vector<i1>70  return71}72 73func.func @arith_cmpi_0d(%smaller : vector<i32>, %bigger : vector<i32>) {74  %0 = arith.cmpi ult, %smaller, %bigger : vector<i32>75  // CHECK: ( 1 )76  vector.print %0: vector<i1>77 78  %1 = arith.cmpi ugt, %smaller, %bigger : vector<i32>79  // CHECK: ( 0 )80  vector.print %1: vector<i1>81 82  %2 = arith.cmpi eq, %smaller, %bigger : vector<i32>83  // CHECK: ( 0 )84  vector.print %2: vector<i1>85 86  return87}88 89func.func @create_mask_0d(%zero : index, %one : index) {90  %zero_mask = vector.create_mask %zero : vector<i1>91  // CHECK: ( 0 )92  vector.print %zero_mask : vector<i1>93 94  %one_mask = vector.create_mask %one : vector<i1>95  // CHECK: ( 1 )96  vector.print %one_mask : vector<i1>97 98  return99}100 101func.func @reduce_add(%arg0: vector<f32>) {102  %0 = vector.reduction <add>, %arg0 : vector<f32> into f32103  vector.print %0 : f32104  // CHECK: 5105  return106}107 108func.func @fma_0d(%four: vector<f32>) {109  %0 = vector.fma %four, %four, %four : vector<f32>110  // 4 * 4 + 4 = 20111  // CHECK: ( 20 )112  vector.print %0: vector<f32>113  return114}115 116func.func @transpose_0d(%arg: vector<i32>) {117  %1 = vector.transpose %arg, [] : vector<i32> to vector<i32>118  // CHECK: ( 42 )119  vector.print %1: vector<i32>120  return121}122 123func.func @shuffle_0d(%v0: vector<i32>, %v1: vector<i32>) {124  %1 = vector.shuffle %v0, %v1 [0, 1, 0] : vector<i32>, vector<i32>125  // CHECK: ( 42, 43, 42 )126  vector.print %1: vector<3xi32>127  return128}129 130func.func @entry() {131  %0 = arith.constant 42.0 : f32132  %1 = arith.constant dense<0.0> : vector<f32>133  %2 = call  @insert_element_0d(%0, %1) : (f32, vector<f32>) -> (vector<f32>)134  call  @extract_element_0d(%2) : (vector<f32>) -> ()135 136  %3 = arith.constant dense<42.0> : vector<f32>137  call  @print_vector_0d(%3) : (vector<f32>) -> ()138 139  %4 = arith.constant 42.0 : f32140 141  // Warning: these must be called in their textual order of definition in the142  // file to not mess up FileCheck.143  call  @broadcast_0d(%4) : (f32) -> ()144  call  @bitcast_0d() : () -> ()145  call  @constant_mask_0d() : () -> ()146 147  %smaller = arith.constant dense<42> : vector<i32>148  %bigger = arith.constant dense<4242> : vector<i32>149  call  @arith_cmpi_0d(%smaller, %bigger) : (vector<i32>, vector<i32>) -> ()150 151  %zero_idx = arith.constant 0 : index152  %one_idx = arith.constant 1 : index153  call  @create_mask_0d(%zero_idx, %one_idx) : (index, index) -> ()154 155  %red_array = arith.constant dense<5.0> : vector<f32>156  call  @reduce_add(%red_array) : (vector<f32>) -> ()157 158  %5 = arith.constant dense<4.0> : vector<f32>159  call  @fma_0d(%5) : (vector<f32>) -> ()160  %6 = arith.constant dense<42> : vector<i32>161  %7 = arith.constant dense<43> : vector<i32>162  call @transpose_0d(%6) : (vector<i32>) -> ()163  call @shuffle_0d(%6, %7) : (vector<i32>, vector<i32>) -> ()164 165  return166}167