• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 @gather8(%base: memref<?xf32>,
7              %indices: vector<8xi32>, %mask: vector<8xi1>) -> vector<8xf32> {
8  %g = vector.gather %base, %indices, %mask
9    : (memref<?xf32>, vector<8xi32>, vector<8xi1>) -> vector<8xf32>
10  return %g : vector<8xf32>
11}
12
13func @gather_pass_thru8(%base: memref<?xf32>,
14                        %indices: vector<8xi32>, %mask: vector<8xi1>,
15                        %pass_thru: vector<8xf32>) -> vector<8xf32> {
16  %g = vector.gather %base, %indices, %mask, %pass_thru
17    : (memref<?xf32>, vector<8xi32>, vector<8xi1>, vector<8xf32>) -> vector<8xf32>
18  return %g : vector<8xf32>
19}
20
21func @entry() {
22  // Set up memory.
23  %c0 = constant 0: index
24  %c1 = constant 1: index
25  %c10 = constant 10: index
26  %A = alloc(%c10) : memref<?xf32>
27  scf.for %i = %c0 to %c10 step %c1 {
28    %i32 = index_cast %i : index to i32
29    %fi = sitofp %i32 : i32 to f32
30    store %fi, %A[%i] : memref<?xf32>
31  }
32
33  // Set up idx vector.
34  %i0 = constant 0: i32
35  %i1 = constant 1: i32
36  %i2 = constant 2: i32
37  %i3 = constant 3: i32
38  %i4 = constant 4: i32
39  %i5 = constant 5: i32
40  %i6 = constant 6: i32
41  %i9 = constant 9: i32
42  %0 = vector.broadcast %i0 : i32 to vector<8xi32>
43  %1 = vector.insert %i6, %0[1] : i32 into vector<8xi32>
44  %2 = vector.insert %i1, %1[2] : i32 into vector<8xi32>
45  %3 = vector.insert %i3, %2[3] : i32 into vector<8xi32>
46  %4 = vector.insert %i5, %3[4] : i32 into vector<8xi32>
47  %5 = vector.insert %i4, %4[5] : i32 into vector<8xi32>
48  %6 = vector.insert %i9, %5[6] : i32 into vector<8xi32>
49  %idx = vector.insert %i2, %6[7] : i32 into vector<8xi32>
50
51  // Set up pass thru vector.
52  %u = constant -7.0: f32
53  %pass = vector.broadcast %u : f32 to vector<8xf32>
54
55  // Set up masks.
56  %t = constant 1: i1
57  %none = vector.constant_mask [0] : vector<8xi1>
58  %all = vector.constant_mask [8] : vector<8xi1>
59  %some = vector.constant_mask [4] : vector<8xi1>
60  %more = vector.insert %t, %some[7] : i1 into vector<8xi1>
61
62  //
63  // Gather tests.
64  //
65
66  %g1 = call @gather8(%A, %idx, %all)
67    : (memref<?xf32>, vector<8xi32>, vector<8xi1>)
68    -> (vector<8xf32>)
69  vector.print %g1 : vector<8xf32>
70  // CHECK: ( 0, 6, 1, 3, 5, 4, 9, 2 )
71
72  %g2 = call @gather_pass_thru8(%A, %idx, %none, %pass)
73    : (memref<?xf32>, vector<8xi32>, vector<8xi1>, vector<8xf32>)
74    -> (vector<8xf32>)
75  vector.print %g2 : vector<8xf32>
76  // CHECK: ( -7, -7, -7, -7, -7, -7, -7, -7 )
77
78  %g3 = call @gather_pass_thru8(%A, %idx, %some, %pass)
79    : (memref<?xf32>, vector<8xi32>, vector<8xi1>, vector<8xf32>)
80    -> (vector<8xf32>)
81  vector.print %g3 : vector<8xf32>
82  // CHECK: ( 0, 6, 1, 3, -7, -7, -7, -7 )
83
84  %g4 = call @gather_pass_thru8(%A, %idx, %more, %pass)
85    : (memref<?xf32>, vector<8xi32>, vector<8xi1>, vector<8xf32>)
86    -> (vector<8xf32>)
87  vector.print %g4 : vector<8xf32>
88  // CHECK: ( 0, 6, 1, 3, -7, -7, -7, 2 )
89
90  %g5 = call @gather_pass_thru8(%A, %idx, %all, %pass)
91    : (memref<?xf32>, vector<8xi32>, vector<8xi1>, vector<8xf32>)
92    -> (vector<8xf32>)
93  vector.print %g5 : vector<8xf32>
94  // CHECK: ( 0, 6, 1, 3, 5, 4, 9, 2 )
95
96  return
97}
98