1 // RUN: mlir-opt --split-input-file --convert-cf-to-spirv --verify-diagnostics %s | FileCheck %s
3 //===----------------------------------------------------------------------===//
5 //===----------------------------------------------------------------------===//
8 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [], []>, #spirv.resource_limits<>>
11 // CHECK-LABEL: func @simple_loop
12 func.func @simple_loop(%begin: i32, %end: i32, %step: i32) {
13 // CHECK-NEXT: spirv.Branch ^bb1
16 // CHECK-NEXT: ^bb1: // pred: ^bb0
17 // CHECK-NEXT: spirv.Branch ^bb2({{.*}} : i32)
19 cf.br ^bb2(%begin : i32)
21 // CHECK: ^bb2({{.*}}: i32): // 2 preds: ^bb1, ^bb3
22 // CHECK: spirv.BranchConditional {{.*}}, ^bb3, ^bb4
23 ^bb2(%0: i32): // 2 preds: ^bb1, ^bb3
24 %1 = arith.cmpi slt, %0, %end : i32
25 cf.cond_br %1, ^bb3, ^bb4
27 // CHECK: ^bb3: // pred: ^bb2
28 // CHECK: spirv.Branch ^bb2({{.*}} : i32)
30 %2 = arith.addi %0, %step : i32
33 // CHECK: ^bb4: // pred: ^bb2
42 // Handle blocks whose arguments require type conversion.
44 // CHECK-LABEL: func.func @main_graph
45 func.func @main_graph(%arg0: index) {
46 %c3 = arith.constant 1 : index
47 // CHECK: spirv.Branch ^bb1({{.*}} : i32)
48 cf.br ^bb1(%arg0 : index)
49 // CHECK: ^bb1({{.*}}: i32): // 2 preds: ^bb0, ^bb2
50 ^bb1(%0: index): // 2 preds: ^bb0, ^bb2
51 %1 = arith.cmpi slt, %0, %c3 : index
52 // CHECK: spirv.BranchConditional {{.*}}, ^bb2, ^bb3
53 cf.cond_br %1, ^bb2, ^bb3
55 // CHECK: spirv.Branch ^bb1({{.*}} : i32)
56 cf.br ^bb1(%c3 : index)