Skip to content

Commit d0fd214

Browse files
author
Yang Bai
committed
rename TestConstantFold to TestSingleFold
1 parent f85fa78 commit d0fd214

File tree

12 files changed

+68
-45
lines changed

12 files changed

+68
-45
lines changed

mlir/test/Dialect/Affine/constant-fold.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -test-constant-fold -split-input-file %s | FileCheck %s
1+
// RUN: mlir-opt -test-single-fold -split-input-file %s | FileCheck %s
22

33
// CHECK-LABEL: func @affine_apply
44
func.func @affine_apply(%variable : index) -> (index, index, index) {

mlir/test/Dialect/Linalg/mesh-spmdization.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: mlir-opt \
2-
// RUN: --pass-pipeline="builtin.module(func.func(mesh-spmdization,test-constant-fold))" \
2+
// RUN: --pass-pipeline="builtin.module(func.func(mesh-spmdization,test-single-fold))" \
33
// RUN: --split-input-file \
44
// RUN: %s | FileCheck %s
55

mlir/test/Dialect/Mesh/spmdization.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: mlir-opt \
2-
// RUN: --pass-pipeline="builtin.module(func.func(mesh-spmdization,test-constant-fold))" \
2+
// RUN: --pass-pipeline="builtin.module(func.func(mesh-spmdization,test-single-fold))" \
33
// RUN: %s | FileCheck %s
44

55
mesh.mesh @mesh_1d(shape = 2)

mlir/test/Dialect/Tensor/mesh-spmdization.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: mlir-opt \
2-
// RUN: --pass-pipeline="builtin.module(func.func(mesh-spmdization,test-constant-fold))" \
2+
// RUN: --pass-pipeline="builtin.module(func.func(mesh-spmdization,test-single-fold))" \
33
// RUN: %s | FileCheck %s
44

55
mesh.mesh @mesh_1d_4(shape = 4)

mlir/test/Dialect/Tosa/constant_folding.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt --test-constant-fold %s | FileCheck %s
1+
// RUN: mlir-opt --test-single-fold %s | FileCheck %s
22

33
// CHECK-LABEL: func @test_const
44
func.func @test_const(%arg0 : index) -> tensor<4xi32> {
Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt %s -split-input-file -test-constant-fold | FileCheck %s
1+
// RUN: mlir-opt %s -split-input-file -test-single-fold | FileCheck %s
22

33
// CHECK-LABEL: fold_extract_transpose_negative
44
func.func @fold_extract_transpose_negative(%arg0: vector<4x4xf16>) -> vector<4x4xf16> {
@@ -12,28 +12,4 @@ func.func @fold_extract_transpose_negative(%arg0: vector<4x4xf16>) -> vector<4x4
1212
return %2 : vector<4x4xf16>
1313
}
1414

15-
// -----
1615

17-
// CHECK-LABEL: fold_extract_in_single_pass
18-
// CHECK-SAME: (%{{.*}}: vector<4xf16>, %[[ARG1:.+]]: f16)
19-
func.func @fold_extract_in_single_pass(%arg0: vector<4xf16>, %arg1: f16) -> f16 {
20-
%0 = vector.insert %arg1, %arg0 [1] : f16 into vector<4xf16>
21-
%c1 = arith.constant 1 : index
22-
// Verify that the fold is finished in a single pass even if the index is dynamic.
23-
%1 = vector.extract %0[%c1] : f16 from vector<4xf16>
24-
// CHECK: return %[[ARG1]] : f16
25-
return %1 : f16
26-
}
27-
28-
// -----
29-
30-
// CHECK-LABEL: fold_insert_in_single_pass
31-
func.func @fold_insert_in_single_pass() -> vector<2xf16> {
32-
%cst = arith.constant dense<0.000000e+00> : vector<2xf16>
33-
%c1 = arith.constant 1 : index
34-
%c2 = arith.constant 2.5 : f16
35-
// Verify that the fold is finished in a single pass even if the index is dynamic.
36-
// CHECK: arith.constant dense<[0.000000e+00, 2.500000e+00]> : vector<2xf16>
37-
%0 = vector.insert %c2, %cst [%c1] : f16 into vector<2xf16>
38-
return %0 : vector<2xf16>
39-
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: mlir-opt %s -split-input-file -test-single-fold | FileCheck %s
2+
3+
// The tests in this file verify that fold() methods can handle complex
4+
// optimization scenarios without requiring multiple folding iterations.
5+
// This is important because:
6+
//
7+
// 1. OpBuilder::createOrFold() only calls fold() once, so operations must
8+
// be fully optimized in that single call
9+
// 2. Multiple rounds of folding would incur higher performance costs,
10+
// so it's more efficient to complete all optimizations in one pass
11+
//
12+
// These tests ensure that folding implementations are robust and complete,
13+
// avoiding situations where operations are left in intermediate states
14+
// that could be further optimized.
15+
16+
// CHECK-LABEL: fold_extract_in_single_pass
17+
// CHECK-SAME: (%{{.*}}: vector<4xf16>, %[[ARG1:.+]]: f16)
18+
func.func @fold_extract_in_single_pass(%arg0: vector<4xf16>, %arg1: f16) -> f16 {
19+
%0 = vector.insert %arg1, %arg0 [1] : f16 into vector<4xf16>
20+
%c1 = arith.constant 1 : index
21+
// Verify that the fold is finished in a single pass even if the index is dynamic.
22+
%1 = vector.extract %0[%c1] : f16 from vector<4xf16>
23+
// CHECK: return %[[ARG1]] : f16
24+
return %1 : f16
25+
}
26+
27+
// -----
28+
29+
// CHECK-LABEL: fold_insert_in_single_pass
30+
func.func @fold_insert_in_single_pass() -> vector<2xf16> {
31+
%cst = arith.constant dense<0.000000e+00> : vector<2xf16>
32+
%c1 = arith.constant 1 : index
33+
%c2 = arith.constant 2.5 : f16
34+
// Verify that the fold is finished in a single pass even if the index is dynamic.
35+
// CHECK: arith.constant dense<[0.000000e+00, 2.500000e+00]> : vector<2xf16>
36+
%0 = vector.insert %c2, %cst [%c1] : f16 into vector<2xf16>
37+
return %0 : vector<2xf16>
38+
}

mlir/test/Transforms/constant-fold-debuginfo.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt %s -split-input-file -test-constant-fold -mlir-print-debuginfo | FileCheck %s
1+
// RUN: mlir-opt %s -split-input-file -test-single-fold -mlir-print-debuginfo | FileCheck %s
22

33
// CHECK-LABEL: func @fold_and_merge
44
func.func @fold_and_merge() -> (i32, i32) {

mlir/test/Transforms/constant-fold.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -test-constant-fold | FileCheck %s
1+
// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -test-single-fold | FileCheck %s
22

33
// -----
44

mlir/test/lib/Transforms/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ endif()
2626
add_mlir_library(MLIRTestTransforms
2727
TestCommutativityUtils.cpp
2828
TestCompositePass.cpp
29-
TestConstantFold.cpp
3029
TestControlFlowSink.cpp
3130
TestInlining.cpp
3231
TestInliningCallback.cpp
3332
TestMakeIsolatedFromAbove.cpp
33+
TestSingleFold.cpp
3434
TestTransformsOps.cpp
3535
${MLIRTestTransformsPDLSrc}
3636

0 commit comments

Comments
 (0)