1 // RUN: mlir-translate -test-spirv-roundtrip -split-input-file %s | FileCheck %s
3 // Selection with both then and else branches
5 spv.module Logical GLSL450 requires #spv.vce<v1.0, [Shader], []> {
6 spv.func @selection(%cond: i1) -> () "None" {
7 // CHECK: spv.Branch ^bb1
9 %zero = spv.constant 0: i32
10 %one = spv.constant 1: i32
11 %two = spv.constant 2: i32
12 %var = spv.Variable init(%zero) : !spv.ptr<i32, Function>
14 // CHECK-NEXT: spv.selection control(Flatten)
15 // CHECK-NEXT: spv.constant 0
16 // CHECK-NEXT: spv.Variable
17 spv.selection control(Flatten) {
18 // CHECK-NEXT: spv.BranchConditional %{{.*}} [5, 10], ^bb1, ^bb2
19 spv.BranchConditional %cond [5, 10], ^then, ^else
23 // CHECK-NEXT: spv.constant 1
24 // CHECK-NEXT: spv.Store
25 spv.Store "Function" %var, %one : i32
26 // CHECK-NEXT: spv.Branch ^bb3
31 // CHECK-NEXT: spv.constant 2
32 // CHECK-NEXT: spv.Store
33 spv.Store "Function" %var, %two : i32
34 // CHECK-NEXT: spv.Branch ^bb3
39 // CHECK-NEXT: spv.mlir.merge
46 spv.func @main() -> () "None" {
49 spv.EntryPoint "GLCompute" @main
50 spv.ExecutionMode @main "LocalSize", 1, 1, 1
55 // Selection with only then branch
56 // Selection in function entry block
58 spv.module Logical GLSL450 requires #spv.vce<v1.0, [Shader], []> {
59 // CHECK: spv.func @selection(%[[ARG:.*]]: i1
60 spv.func @selection(%cond: i1) -> (i32) "None" {
61 // CHECK: spv.Branch ^bb1
63 // CHECK-NEXT: spv.selection
65 // CHECK-NEXT: spv.BranchConditional %[[ARG]], ^bb1, ^bb2
66 spv.BranchConditional %cond, ^then, ^merge
70 %zero = spv.constant 0 : i32
71 spv.ReturnValue %zero : i32
75 // CHECK-NEXT: spv.mlir.merge
79 %one = spv.constant 1 : i32
80 spv.ReturnValue %one : i32
83 spv.func @main() -> () "None" {
86 spv.EntryPoint "GLCompute" @main
87 spv.ExecutionMode @main "LocalSize", 1, 1, 1