1// RUN: mlir-opt %s -convert-scf-to-std -convert-vector-to-llvm -convert-std-to-llvm | \ 2// RUN: mlir-cpu-runner -e entry -entry-point-result=void \ 3// RUN: -shared-libs=%mlir_integration_test_dir/libmlir_c_runner_utils%shlibext | \ 4// RUN: FileCheck %s 5 6func @scatter8(%base: memref<?xf32>, 7 %indices: vector<8xi32>, 8 %mask: vector<8xi1>, %value: vector<8xf32>) { 9 vector.scatter %base, %indices, %mask, %value 10 : vector<8xi32>, vector<8xi1>, vector<8xf32> into memref<?xf32> 11 return 12} 13 14func @printmem8(%A: memref<?xf32>) { 15 %c0 = constant 0: index 16 %c1 = constant 1: index 17 %c8 = constant 8: index 18 %z = constant 0.0: f32 19 %m = vector.broadcast %z : f32 to vector<8xf32> 20 %mem = scf.for %i = %c0 to %c8 step %c1 21 iter_args(%m_iter = %m) -> (vector<8xf32>) { 22 %c = load %A[%i] : memref<?xf32> 23 %i32 = index_cast %i : index to i32 24 %m_new = vector.insertelement %c, %m_iter[%i32 : i32] : vector<8xf32> 25 scf.yield %m_new : vector<8xf32> 26 } 27 vector.print %mem : vector<8xf32> 28 return 29} 30 31func @entry() { 32 // Set up memory. 33 %c0 = constant 0: index 34 %c1 = constant 1: index 35 %c8 = constant 8: index 36 %A = alloc(%c8) : memref<?xf32> 37 scf.for %i = %c0 to %c8 step %c1 { 38 %i32 = index_cast %i : index to i32 39 %fi = sitofp %i32 : i32 to f32 40 store %fi, %A[%i] : memref<?xf32> 41 } 42 43 // Set up idx vector. 44 %i0 = constant 0: i32 45 %i1 = constant 1: i32 46 %i2 = constant 2: i32 47 %i3 = constant 3: i32 48 %i4 = constant 4: i32 49 %i5 = constant 5: i32 50 %i6 = constant 6: i32 51 %i7 = constant 7: i32 52 %0 = vector.broadcast %i7 : i32 to vector<8xi32> 53 %1 = vector.insert %i0, %0[1] : i32 into vector<8xi32> 54 %2 = vector.insert %i1, %1[2] : i32 into vector<8xi32> 55 %3 = vector.insert %i6, %2[3] : i32 into vector<8xi32> 56 %4 = vector.insert %i2, %3[4] : i32 into vector<8xi32> 57 %5 = vector.insert %i4, %4[5] : i32 into vector<8xi32> 58 %6 = vector.insert %i5, %5[6] : i32 into vector<8xi32> 59 %idx = vector.insert %i3, %6[7] : i32 into vector<8xi32> 60 61 // Set up value vector. 62 %f0 = constant 0.0: f32 63 %f1 = constant 1.0: f32 64 %f2 = constant 2.0: f32 65 %f3 = constant 3.0: f32 66 %f4 = constant 4.0: f32 67 %f5 = constant 5.0: f32 68 %f6 = constant 6.0: f32 69 %f7 = constant 7.0: f32 70 %7 = vector.broadcast %f0 : f32 to vector<8xf32> 71 %8 = vector.insert %f1, %7[1] : f32 into vector<8xf32> 72 %9 = vector.insert %f2, %8[2] : f32 into vector<8xf32> 73 %10 = vector.insert %f3, %9[3] : f32 into vector<8xf32> 74 %11 = vector.insert %f4, %10[4] : f32 into vector<8xf32> 75 %12 = vector.insert %f5, %11[5] : f32 into vector<8xf32> 76 %13 = vector.insert %f6, %12[6] : f32 into vector<8xf32> 77 %val = vector.insert %f7, %13[7] : f32 into vector<8xf32> 78 79 // Set up masks. 80 %t = constant 1: i1 81 %none = vector.constant_mask [0] : vector<8xi1> 82 %some = vector.constant_mask [4] : vector<8xi1> 83 %more = vector.insert %t, %some[7] : i1 into vector<8xi1> 84 %all = vector.constant_mask [8] : vector<8xi1> 85 86 // 87 // Scatter tests. 88 // 89 90 vector.print %idx : vector<8xi32> 91 // CHECK: ( 7, 0, 1, 6, 2, 4, 5, 3 ) 92 93 call @printmem8(%A) : (memref<?xf32>) -> () 94 // CHECK: ( 0, 1, 2, 3, 4, 5, 6, 7 ) 95 96 call @scatter8(%A, %idx, %none, %val) 97 : (memref<?xf32>, vector<8xi32>, vector<8xi1>, vector<8xf32>) -> () 98 call @printmem8(%A) : (memref<?xf32>) -> () 99 // CHECK: ( 0, 1, 2, 3, 4, 5, 6, 7 ) 100 101 call @scatter8(%A, %idx, %some, %val) 102 : (memref<?xf32>, vector<8xi32>, vector<8xi1>, vector<8xf32>) -> () 103 call @printmem8(%A) : (memref<?xf32>) -> () 104 // CHECK: ( 1, 2, 2, 3, 4, 5, 3, 0 ) 105 106 call @scatter8(%A, %idx, %more, %val) 107 : (memref<?xf32>, vector<8xi32>, vector<8xi1>, vector<8xf32>) -> () 108 call @printmem8(%A) : (memref<?xf32>) -> () 109 // CHECK: ( 1, 2, 2, 7, 4, 5, 3, 0 ) 110 111 call @scatter8(%A, %idx, %all, %val) 112 : (memref<?xf32>, vector<8xi32>, vector<8xi1>, vector<8xf32>) -> () 113 call @printmem8(%A) : (memref<?xf32>) -> () 114 // CHECK: ( 1, 2, 4, 7, 5, 6, 3, 0 ) 115 116 return 117} 118