xref: /llvm-project/mlir/test/Integration/Dialect/Vector/CPU/expand.mlir (revision eb206e9ea84eff0a0596fed2de8316d924f946d1)
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 %s
5
6func.func @expand16(%base: memref<?xf32>,
7               %mask: vector<16xi1>,
8               %pass_thru: vector<16xf32>) -> vector<16xf32> {
9  %c0 = arith.constant 0: index
10  %e = vector.expandload %base[%c0], %mask, %pass_thru
11    : memref<?xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
12  return %e : vector<16xf32>
13}
14
15func.func @expand16_at8(%base: memref<?xf32>,
16                   %mask: vector<16xi1>,
17                   %pass_thru: vector<16xf32>) -> vector<16xf32> {
18  %c8 = arith.constant 8: index
19  %e = vector.expandload %base[%c8], %mask, %pass_thru
20    : memref<?xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
21  return %e : vector<16xf32>
22}
23
24func.func @entry() {
25  // Set up memory.
26  %c0 = arith.constant 0: index
27  %c1 = arith.constant 1: index
28  %c16 = arith.constant 16: index
29  %A = memref.alloc(%c16) : memref<?xf32>
30  scf.for %i = %c0 to %c16 step %c1 {
31    %i32 = arith.index_cast %i : index to i32
32    %fi = arith.sitofp %i32 : i32 to f32
33    memref.store %fi, %A[%i] : memref<?xf32>
34  }
35
36  // Set up pass thru vector.
37  %u = arith.constant -7.0: f32
38  %v = arith.constant 7.7: f32
39  %pass = vector.broadcast %u : f32 to vector<16xf32>
40
41  // Set up masks.
42  %f = arith.constant 0: i1
43  %t = arith.constant 1: i1
44  %none = vector.constant_mask [0] : vector<16xi1>
45  %all = vector.constant_mask [16] : vector<16xi1>
46  %some1 = vector.constant_mask [4] : vector<16xi1>
47  %0 = vector.insert %f, %some1[0] : i1 into vector<16xi1>
48  %1 = vector.insert %t, %0[7] : i1 into vector<16xi1>
49  %2 = vector.insert %t, %1[11] : i1 into vector<16xi1>
50  %3 = vector.insert %t, %2[13] : i1 into vector<16xi1>
51  %some2 = vector.insert %t, %3[15] : i1 into vector<16xi1>
52  %some3 = vector.insert %f, %some2[2] : i1 into vector<16xi1>
53
54  //
55  // Expanding load tests.
56  //
57
58  %e1 = call @expand16(%A, %none, %pass)
59    : (memref<?xf32>, vector<16xi1>, vector<16xf32>) -> (vector<16xf32>)
60  vector.print %e1 : vector<16xf32>
61  // CHECK: ( -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7 )
62
63  %e2 = call @expand16(%A, %all, %pass)
64    : (memref<?xf32>, vector<16xi1>, vector<16xf32>) -> (vector<16xf32>)
65  vector.print %e2 : vector<16xf32>
66  // CHECK-NEXT: ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 )
67
68  %e3 = call @expand16(%A, %some1, %pass)
69    : (memref<?xf32>, vector<16xi1>, vector<16xf32>) -> (vector<16xf32>)
70  vector.print %e3 : vector<16xf32>
71  // CHECK-NEXT: ( 0, 1, 2, 3, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7 )
72
73  %e4 = call @expand16(%A, %some2, %pass)
74    : (memref<?xf32>, vector<16xi1>, vector<16xf32>) -> (vector<16xf32>)
75  vector.print %e4 : vector<16xf32>
76  // CHECK-NEXT: ( -7, 0, 1, 2, -7, -7, -7, 3, -7, -7, -7, 4, -7, 5, -7, 6 )
77
78  %e5 = call @expand16(%A, %some3, %pass)
79    : (memref<?xf32>, vector<16xi1>, vector<16xf32>) -> (vector<16xf32>)
80  vector.print %e5 : vector<16xf32>
81  // CHECK-NEXT: ( -7, 0, -7, 1, -7, -7, -7, 2, -7, -7, -7, 3, -7, 4, -7, 5 )
82
83  %4 = vector.insert %v, %pass[1] : f32 into vector<16xf32>
84  %5 = vector.insert %v, %4[2] : f32 into vector<16xf32>
85  %alt_pass = vector.insert %v, %5[14] : f32 into vector<16xf32>
86  %e6 = call @expand16(%A, %some3, %alt_pass)
87    : (memref<?xf32>, vector<16xi1>, vector<16xf32>) -> (vector<16xf32>)
88  vector.print %e6 : vector<16xf32>
89  // CHECK-NEXT: ( -7, 0, 7.7, 1, -7, -7, -7, 2, -7, -7, -7, 3, -7, 4, 7.7, 5 )
90
91  %e7 = call @expand16_at8(%A, %some1, %pass)
92    : (memref<?xf32>, vector<16xi1>, vector<16xf32>) -> (vector<16xf32>)
93  vector.print %e7 : vector<16xf32>
94  // CHECK-NEXT: ( 8, 9, 10, 11, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7 )
95
96  memref.dealloc %A : memref<?xf32>
97  return
98}
99