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