[Mlir-commits] [mlir] [mlir][vector][nfc] Group all tests for `foldFromElementsToConstant` (PR #158578)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Mon Sep 15 02:47:57 PDT 2025
https://github.com/banach-space updated https://github.com/llvm/llvm-project/pull/158578
>From e9e1fc8182237de426f14d09243f2cd185e65371 Mon Sep 17 00:00:00 2001
From: Andrzej Warzynski <andrzej.warzynski at arm.com>
Date: Mon, 15 Sep 2025 08:26:51 +0000
Subject: [PATCH 1/2] [mlir][vector][nfc] Group all tests for
`foldFromElementsToConstant`
This patch merely moves + renames tests for Vector's
`foldFromElementsToConstant` - to better align with our testing guides:
* https://mlir.llvm.org/getting_started/TestingGuide/
Changes:
1. Make sure that all tests for `foldFromElementsToConstant` are
grouped together.
2. Use `@negative_` as a prefix for negative tests (*).
3. Use captigal letters for LIT variable names (*).
---
mlir/test/Dialect/Vector/canonicalize.mlir | 50 ++++++++++++++--------
1 file changed, 32 insertions(+), 18 deletions(-)
diff --git a/mlir/test/Dialect/Vector/canonicalize.mlir b/mlir/test/Dialect/Vector/canonicalize.mlir
index e7381e0c8997e..e10c930c8ba69 100644
--- a/mlir/test/Dialect/Vector/canonicalize.mlir
+++ b/mlir/test/Dialect/Vector/canonicalize.mlir
@@ -3326,8 +3326,12 @@ func.func @from_elements_to_elements_shuffle(%a: vector<4x2xf32>) -> vector<4x2x
// -----
-// CHECK-LABEL: func @from_elements_all_elements_constant(
-func.func @from_elements_all_elements_constant() -> vector<2x2xi32> {
+// +---------------------------------------------------------------------------
+// Tests for foldFromElementsToConstant
+// +---------------------------------------------------------------------------
+
+// CHECK-LABEL: func @from_elements_to_constant(
+func.func @from_elements_to_constant() -> vector<2x2xi32> {
%c0_i32 = arith.constant 0 : i32
%c1_i32 = arith.constant 1 : i32
%c2_i32 = arith.constant 2 : i32
@@ -3340,9 +3344,11 @@ func.func @from_elements_all_elements_constant() -> vector<2x2xi32> {
// -----
-// CHECK-LABEL: func @from_elements_partial_elements_constant(
+// One of the elements is not a constant, the folder should fail.
+
+// CHECK-LABEL: func @negative_from_elements_to_constant(
// CHECK-SAME: %[[A:.*]]: f32
-func.func @from_elements_partial_elements_constant(%arg0: f32) -> vector<2xf32> {
+func.func @negative_from_elements_to_constant(%arg0: f32) -> vector<2xf32> {
// CHECK: %[[C:.*]] = arith.constant 1.000000e+00 : f32
%c = arith.constant 1.0 : f32
// CHECK: %[[RES:.*]] = vector.from_elements %[[A]], %[[C]] : vector<2xf32>
@@ -3353,6 +3359,28 @@ func.func @from_elements_partial_elements_constant(%arg0: f32) -> vector<2xf32>
// -----
+// While all inputs in this example are constant, we cannot create a
+// DenselElemAttr containing llvm.mlir.addressof. Instead,
+// `foldFromElementsToConstant` bails out. Note that in this case, a different
+// folder is applied (`rewriteFromElementsAsBroadcast`).
+llvm.mlir.global constant @my_symbol() : i32
+
+// CHECK-LABEL: func @negative_from_address_to_constant
+// CHECK: %[[A:.*]] = llvm.mlir.addressof @my_symbol
+// CHECK: %[[B:.*]] = vector.broadcast %[[A]] : !llvm.ptr to vector<1x!llvm.ptr>
+// CHECK: return %[[B]]
+func.func @negative_from_elements_to_constant() -> vector<1x!llvm.ptr> {
+ %a = llvm.mlir.addressof @my_symbol : !llvm.ptr
+ %b = vector.from_elements %a : vector<1x!llvm.ptr>
+ return %b : vector<1x!llvm.ptr>
+}
+
+// +---------------------------------------------------------------------------
+// End of Tests for foldFromElementsToConstant
+// +---------------------------------------------------------------------------
+
+// -----
+
// CHECK-LABEL: func @vector_insert_const_regression(
// CHECK: llvm.mlir.undef
// CHECK: vector.insert
@@ -3726,17 +3754,3 @@ func.func @no_fold_insert_use_chain_mismatch_static_position(%arg : vector<4xf32
%v_1 = vector.insert %val, %v_0[1] : f32 into vector<4xf32>
return %v_1 : vector<4xf32>
}
-
-// -----
-
-llvm.mlir.global constant @my_symbol() : i32
-
-// CHECK-LABEL: func @from_address_of_regression
-// CHECK: %[[a:.*]] = llvm.mlir.addressof @my_symbol
-// CHECK: %[[b:.*]] = vector.broadcast %[[a]] : !llvm.ptr to vector<1x!llvm.ptr>
-// CHECK: return %[[b]]
-func.func @from_address_of_regression() -> vector<1x!llvm.ptr> {
- %a = llvm.mlir.addressof @my_symbol : !llvm.ptr
- %b = vector.from_elements %a : vector<1x!llvm.ptr>
- return %b : vector<1x!llvm.ptr>
-}
>From 97f094c1d28d8e39c0408501bb5b0aaee0d5f111 Mon Sep 17 00:00:00 2001
From: Andrzej Warzynski <andrzej.warzynski at arm.com>
Date: Mon, 15 Sep 2025 09:47:46 +0000
Subject: [PATCH 2/2] Fix typo
---
mlir/test/Dialect/Vector/canonicalize.mlir | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/test/Dialect/Vector/canonicalize.mlir b/mlir/test/Dialect/Vector/canonicalize.mlir
index e10c930c8ba69..05c88b8abfbb0 100644
--- a/mlir/test/Dialect/Vector/canonicalize.mlir
+++ b/mlir/test/Dialect/Vector/canonicalize.mlir
@@ -3365,7 +3365,7 @@ func.func @negative_from_elements_to_constant(%arg0: f32) -> vector<2xf32> {
// folder is applied (`rewriteFromElementsAsBroadcast`).
llvm.mlir.global constant @my_symbol() : i32
-// CHECK-LABEL: func @negative_from_address_to_constant
+// CHECK-LABEL: func @negative_from_elements_to_constant
// CHECK: %[[A:.*]] = llvm.mlir.addressof @my_symbol
// CHECK: %[[B:.*]] = vector.broadcast %[[A]] : !llvm.ptr to vector<1x!llvm.ptr>
// CHECK: return %[[B]]
More information about the Mlir-commits
mailing list