xref: /llvm-project/mlir/test/Integration/Dialect/Vector/CPU/reductions-f32-reassoc.mlir (revision eb206e9ea84eff0a0596fed2de8316d924f946d1)
1// RUN: mlir-opt %s -convert-vector-to-scf -convert-scf-to-cf \
2// RUN:             -convert-vector-to-llvm='reassociate-fp-reductions' \
3// RUN:             -convert-func-to-llvm -convert-arith-to-llvm \
4// RUN:             -convert-cf-to-llvm -reconcile-unrealized-casts | \
5// RUN: mlir-runner -e entry -entry-point-result=void  \
6// RUN:   -shared-libs=%mlir_c_runner_utils | \
7// RUN: FileCheck %s
8
9func.func @entry() {
10  // Construct test vector, numerically very stable.
11  %f1 = arith.constant 1.0: f32
12  %f2 = arith.constant 2.0: f32
13  %f3 = arith.constant 3.0: f32
14  %v0 = vector.broadcast %f1 : f32 to vector<64xf32>
15  %v1 = vector.insert %f2, %v0[11] : f32 into vector<64xf32>
16  %v2 = vector.insert %f3, %v1[52] : f32 into vector<64xf32>
17  vector.print %v2 : vector<64xf32>
18  //
19  // test vector:
20  //
21  // CHECK: ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 )
22
23  // Various vector reductions. Not full functional unit tests, but
24  // a simple integration test to see if the code runs end-to-end.
25  %0 = vector.reduction <add>, %v2 : vector<64xf32> into f32
26  vector.print %0 : f32
27  // CHECK: 67
28  %1 = vector.reduction <mul>, %v2 : vector<64xf32> into f32
29  vector.print %1 : f32
30  // CHECK: 6
31  %2 = vector.reduction <minimumf>, %v2 : vector<64xf32> into f32
32  vector.print %2 : f32
33  // CHECK: 1
34  %3 = vector.reduction <maximumf>, %v2 : vector<64xf32> into f32
35  vector.print %3 : f32
36  // CHECK: 3
37  %4 = vector.reduction <minnumf>, %v2 : vector<64xf32> into f32
38  vector.print %4 : f32
39  // CHECK: 1
40  %5 = vector.reduction <maxnumf>, %v2 : vector<64xf32> into f32
41  vector.print %5 : f32
42  // CHECK: 3
43
44  return
45}
46