1// RUN: mlir-opt %s -convert-vector-to-llvm | FileCheck %s
2// RUN: mlir-opt %s -convert-vector-to-llvm='reassociate-fp-reductions' | FileCheck %s --check-prefix=REASSOC
3
4//
5// CHECK-LABEL: llvm.func @reduce_add_f32(
6// CHECK-SAME: %[[A:.*]]: !llvm.vec<16 x float>)
7//      CHECK: %[[C:.*]] = llvm.mlir.constant(0.000000e+00 : f32) : !llvm.float
8//      CHECK: %[[V:.*]] = "llvm.intr.vector.reduce.fadd"(%[[C]], %[[A]])
9// CHECK-SAME: {reassoc = false} : (!llvm.float, !llvm.vec<16 x float>) -> !llvm.float
10//      CHECK: llvm.return %[[V]] : !llvm.float
11//
12// REASSOC-LABEL: llvm.func @reduce_add_f32(
13// REASSOC-SAME: %[[A:.*]]: !llvm.vec<16 x float>)
14//      REASSOC: %[[C:.*]] = llvm.mlir.constant(0.000000e+00 : f32) : !llvm.float
15//      REASSOC: %[[V:.*]] = "llvm.intr.vector.reduce.fadd"(%[[C]], %[[A]])
16// REASSOC-SAME: {reassoc = true} : (!llvm.float, !llvm.vec<16 x float>) -> !llvm.float
17//      REASSOC: llvm.return %[[V]] : !llvm.float
18//
19func @reduce_add_f32(%arg0: vector<16xf32>) -> f32 {
20  %0 = vector.reduction "add", %arg0 : vector<16xf32> into f32
21  return %0 : f32
22}
23
24//
25// CHECK-LABEL: llvm.func @reduce_mul_f32(
26// CHECK-SAME: %[[A:.*]]: !llvm.vec<16 x float>)
27//      CHECK: %[[C:.*]] = llvm.mlir.constant(1.000000e+00 : f32) : !llvm.float
28//      CHECK: %[[V:.*]] = "llvm.intr.vector.reduce.fmul"(%[[C]], %[[A]])
29// CHECK-SAME: {reassoc = false} : (!llvm.float, !llvm.vec<16 x float>) -> !llvm.float
30//      CHECK: llvm.return %[[V]] : !llvm.float
31//
32// REASSOC-LABEL: llvm.func @reduce_mul_f32(
33// REASSOC-SAME: %[[A:.*]]: !llvm.vec<16 x float>)
34//      REASSOC: %[[C:.*]] = llvm.mlir.constant(1.000000e+00 : f32) : !llvm.float
35//      REASSOC: %[[V:.*]] = "llvm.intr.vector.reduce.fmul"(%[[C]], %[[A]])
36// REASSOC-SAME: {reassoc = true} : (!llvm.float, !llvm.vec<16 x float>) -> !llvm.float
37//      REASSOC: llvm.return %[[V]] : !llvm.float
38//
39func @reduce_mul_f32(%arg0: vector<16xf32>) -> f32 {
40  %0 = vector.reduction "mul", %arg0 : vector<16xf32> into f32
41  return %0 : f32
42}
43