1 // RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
3 // CHECK-LABEL: @if_yield
4 // CHECK: %[[VAR:.*]] = spirv.Variable : !spirv.ptr<f32, Function>
5 // CHECK: spirv.mlir.selection {
6 // CHECK-NEXT: spirv.BranchConditional {{%.*}}, [[TRUE:\^.*]], [[FALSE:\^.*]]
7 // CHECK-NEXT: [[TRUE]]:
8 // CHECK: %[[C0TRUE:.*]] = spirv.Constant 0.000000e+00 : f32
9 // CHECK: %[[RETTRUE:.*]] = spirv.Constant 0.000000e+00 : f32
10 // CHECK-DAG: spirv.Store "Function" %[[VAR]], %[[RETTRUE]] : f32
11 // CHECK: spirv.Branch ^[[MERGE:.*]]
12 // CHECK-NEXT: [[FALSE]]:
13 // CHECK: %[[C0FALSE:.*]] = spirv.Constant 1.000000e+00 : f32
14 // CHECK: %[[RETFALSE:.*]] = spirv.Constant 2.71828175 : f32
15 // CHECK-DAG: spirv.Store "Function" %[[VAR]], %[[RETFALSE]] : f32
16 // CHECK: spirv.Branch ^[[MERGE]]
17 // CHECK-NEXT: ^[[MERGE]]:
18 // CHECK: spirv.mlir.merge
20 // CHECK-DAG: %[[OUT:.*]] = spirv.Load "Function" %[[VAR]] : f32
21 // CHECK: spirv.ReturnValue %[[OUT]] : f32
22 func.func @if_yield(%arg0: i1) -> f32 {
23 %0 = scf.if %arg0 -> f32 {
24 %c0 = arith.constant 0.0 : f32
25 %res = math.sqrt %c0 : f32
28 %c0 = arith.constant 1.0 : f32
29 %res = math.exp %c0 : f32
35 // CHECK-LABEL: @while
36 // CHECK: spirv.mlir.loop {
37 // CHECK: spirv.Branch ^[[HEADER:.*]](%{{.*}} : i32)
39 // CHECK: spirv.BranchConditional %{{.*}}, ^[[BODY:.*]](%{{.*}} : i32), ^[[MERGE:.*]]
41 // CHECK: spirv.Branch
43 // CHECK: spirv.mlir.merge
45 // CHECK: spirv.Load "Function"
46 func.func @while(%arg0: i32, %arg1: i32) -> i32 {
47 %c2_i32 = arith.constant 2 : i32
48 %0 = scf.while (%arg3 = %arg0) : (i32) -> (i32) {
49 %1 = arith.cmpi slt, %arg3, %arg1 : i32
50 scf.condition(%1) %arg3 : i32
53 %1 = arith.muli %arg5, %c2_i32 : i32
60 // CHECK: spirv.mlir.loop {
61 // CHECK: spirv.Branch ^[[HEADER:.*]](%{{.*}}, %{{.*}}, %{{.*}} : i32, f32, f32)
63 // CHECK: spirv.BranchConditional %{{.*}}, ^[[BODY:.*]], ^[[MERGE:.*]]
65 // CHECK: spirv.Branch ^[[HEADER]]
67 // CHECK: spirv.mlir.merge
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