[Mlir-commits] [mlir] [MLIR] [Vector] ConstantFold MultiDReduction (PR #122450)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Fri Jan 10 11:56:37 PST 2025
================
@@ -11,3 +11,57 @@ func.func @fold_extract_transpose_negative(%arg0: vector<4x4xf16>) -> vector<4x4
%2 = vector.extract %1[0] : vector<4x4xf16> from vector<1x4x4xf16>
return %2 : vector<4x4xf16>
}
+
+// CHECK-LABEL: fold_multid_reduction_f32_add
+func.func @fold_multid_reduction_f32_add() -> vector<1xf32> {
+ %cst_0 = arith.constant dense<0.000000e+00> : vector<1xf32>
+ %0 = arith.constant dense<1.000000e+00> : vector<1x128x128xf32>
+ // CHECK: %{{.*}} = arith.constant dense<1.638400e+04> : vector<1xf32>
+ %1 = vector.multi_reduction <add>, %0, %cst_0 [1, 2] : vector<1x128x128xf32> to vector<1xf32>
+ return %1 : vector<1xf32>
+}
+
+// CHECK-LABEL: fold_multid_reduction_f32_mul
+func.func @fold_multid_reduction_f32_mul() -> vector<1xf32> {
+ %cst_0 = arith.constant dense<1.000000e+00> : vector<1xf32>
+ %0 = arith.constant dense<2.000000e+00> : vector<1x2x2xf32>
+ // CHECK: %{{.*}} = arith.constant dense<1.600000e+01> : vector<1xf32>
+ %1 = vector.multi_reduction <mul>, %0, %cst_0 [1, 2] : vector<1x2x2xf32> to vector<1xf32>
+ return %1 : vector<1xf32>
+}
+
+// CHECK-LABEL: fold_multid_reduction_i32_add
+func.func @fold_multid_reduction_i32_add() -> vector<1xi32> {
+ %cst_1 = arith.constant dense<1> : vector<1xi32>
+ %0 = arith.constant dense<1> : vector<1x128x128xi32>
+ // CHECK: %{{.*}} = arith.constant dense<16385> : vector<1xi32>
+ %1 = vector.multi_reduction <add>, %0, %cst_1 [1, 2] : vector<1x128x128xi32> to vector<1xi32>
+ return %1 : vector<1xi32>
+}
+
+// CHECK-LABEL: fold_multid_reduction_i32_xor_odd
+func.func @fold_multid_reduction_i32_xor_odd() -> vector<1xi32> {
----------------
banach-space wrote:
```suggestion
func.func @fold_multid_reduction_i32_xor_odd_ num_elements() -> vector<1xi32> {
```
https://github.com/llvm/llvm-project/pull/122450
More information about the Mlir-commits
mailing list