• 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 @maskedstore16(%base: memref<?xf32>,
7                    %mask: vector<16xi1>, %value: vector<16xf32>) {
8  vector.maskedstore %base, %mask, %value
9    : vector<16xi1>, vector<16xf32> into memref<?xf32>
10  return
11}
12
13func @printmem16(%A: memref<?xf32>) {
14  %c0 = constant 0: index
15  %c1 = constant 1: index
16  %c16 = constant 16: index
17  %z = constant 0.0: f32
18  %m = vector.broadcast %z : f32 to vector<16xf32>
19  %mem = scf.for %i = %c0 to %c16 step %c1
20    iter_args(%m_iter = %m) -> (vector<16xf32>) {
21    %c = load %A[%i] : memref<?xf32>
22    %i32 = index_cast %i : index to i32
23    %m_new = vector.insertelement %c, %m_iter[%i32 : i32] : vector<16xf32>
24    scf.yield %m_new : vector<16xf32>
25  }
26  vector.print %mem : vector<16xf32>
27  return
28}
29
30func @entry() {
31  // Set up memory.
32  %f0 = constant 0.0: f32
33  %c0 = constant 0: index
34  %c1 = constant 1: index
35  %c16 = constant 16: index
36  %A = alloc(%c16) : memref<?xf32>
37  scf.for %i = %c0 to %c16 step %c1 {
38    store %f0, %A[%i] : memref<?xf32>
39  }
40
41  // Set up value vector.
42  %v = vector.broadcast %f0 : f32 to vector<16xf32>
43  %val = scf.for %i = %c0 to %c16 step %c1
44    iter_args(%v_iter = %v) -> (vector<16xf32>) {
45    %i32 = index_cast %i : index to i32
46    %fi = sitofp %i32 : i32 to f32
47    %v_new = vector.insertelement %fi, %v_iter[%i32 : i32] : vector<16xf32>
48    scf.yield %v_new : vector<16xf32>
49  }
50
51  // Set up masks.
52  %t = constant 1: i1
53  %none = vector.constant_mask [0] : vector<16xi1>
54  %some = vector.constant_mask [8] : vector<16xi1>
55  %more = vector.insert %t, %some[13] : i1 into vector<16xi1>
56  %all = vector.constant_mask [16] : vector<16xi1>
57
58  //
59  // Masked store tests.
60  //
61
62  vector.print %val : vector<16xf32>
63  // CHECK: ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 )
64
65  call @printmem16(%A) : (memref<?xf32>) -> ()
66  // CHECK: ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
67
68  call @maskedstore16(%A, %none, %val)
69    : (memref<?xf32>, vector<16xi1>, vector<16xf32>) -> ()
70  call @printmem16(%A) : (memref<?xf32>) -> ()
71  // CHECK: ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
72
73  call @maskedstore16(%A, %some, %val)
74    : (memref<?xf32>, vector<16xi1>, vector<16xf32>) -> ()
75  call @printmem16(%A) : (memref<?xf32>) -> ()
76  // CHECK: ( 0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0 )
77
78  call @maskedstore16(%A, %more, %val)
79    : (memref<?xf32>, vector<16xi1>, vector<16xf32>) -> ()
80  call @printmem16(%A) : (memref<?xf32>) -> ()
81  // CHECK: ( 0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 13, 0, 0 )
82
83  call @maskedstore16(%A, %all, %val)
84    : (memref<?xf32>, vector<16xi1>, vector<16xf32>) -> ()
85  call @printmem16(%A) : (memref<?xf32>) -> ()
86  // CHECK: ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 )
87
88  return
89}
90