Skip to content

Commit 05901e9

Browse files
authored
[mlir][spirv] Add tests for scf.while and scf.for in convert-to-spirv pass (#102528)
This PR adds lit tests that check for `scf.while` and `scf.for` conversions for the `convert-to-spirv` pass, introduced in #95942.
1 parent 652707a commit 05901e9

File tree

1 file changed

+33
-0
lines changed
  • mlir/test/Conversion/ConvertToSPIRV

1 file changed

+33
-0
lines changed

mlir/test/Conversion/ConvertToSPIRV/scf.mlir

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ func.func @if_yield(%arg0: i1) -> f32 {
3333
}
3434

3535
// CHECK-LABEL: @while
36+
// CHECK: spirv.mlir.loop {
37+
// CHECK: spirv.Branch ^[[HEADER:.*]](%{{.*}} : i32)
38+
// CHECK: ^[[HEADER]]
39+
// CHECK: spirv.BranchConditional %{{.*}}, ^[[BODY:.*]](%{{.*}} : i32), ^[[MERGE:.*]]
40+
// CHECK: ^[[BODY]]
41+
// CHECK: spirv.Branch
42+
// CHECK: ^[[MERGE]]
43+
// CHECK: spirv.mlir.merge
44+
// CHECK: }
45+
// CHECK: spirv.Load "Function"
3646
func.func @while(%arg0: i32, %arg1: i32) -> i32 {
3747
%c2_i32 = arith.constant 2 : i32
3848
%0 = scf.while (%arg3 = %arg0) : (i32) -> (i32) {
@@ -45,3 +55,26 @@ func.func @while(%arg0: i32, %arg1: i32) -> i32 {
4555
}
4656
return %0 : i32
4757
}
58+
59+
// CHECK-LABEL: @for
60+
// CHECK: spirv.mlir.loop {
61+
// CHECK: spirv.Branch ^[[HEADER:.*]](%{{.*}}, %{{.*}}, %{{.*}} : i32, f32, f32)
62+
// CHECK: ^[[HEADER]]
63+
// CHECK: spirv.BranchConditional %{{.*}}, ^[[BODY:.*]], ^[[MERGE:.*]]
64+
// CHECK: ^[[BODY]]
65+
// CHECK: spirv.Branch ^[[HEADER]]
66+
// CHECK: ^[[MERGE]]
67+
// CHECK: spirv.mlir.merge
68+
// CHECK: }
69+
func.func @for() {
70+
%lb = arith.constant 4 : index
71+
%ub = arith.constant 42 : index
72+
%step = arith.constant 2 : index
73+
%s0 = arith.constant 0.0 : f32
74+
%s1 = arith.constant 1.0 : f32
75+
%result:2 = scf.for %i0 = %lb to %ub step %step iter_args(%si = %s0, %sj = %s1) -> (f32, f32) {
76+
%sn = arith.addf %si, %si : f32
77+
scf.yield %sn, %sn: f32, f32
78+
}
79+
return
80+
}

0 commit comments

Comments
 (0)