1 // RUN: mlir-opt -convert-spirv-to-llvm -split-input-file -verify-diagnostics %s | FileCheck %s
3 //===----------------------------------------------------------------------===//
5 //===----------------------------------------------------------------------===//
7 spirv.module Logical GLSL450 {
8 spirv.func @branch_without_arguments() -> () "None" {
16 spirv.func @branch_with_arguments() -> () "None" {
17 %0 = spirv.Constant 0 : i32
18 %1 = spirv.Constant true
19 // CHECK: llvm.br ^bb1(%{{.*}}, %{{.*}} : i32, i1)
20 spirv.Branch ^label(%0, %1: i32, i1)
21 // CHECK: ^bb1(%{{.*}}: i32, %{{.*}}: i1)
22 ^label(%arg0: i32, %arg1: i1):
29 //===----------------------------------------------------------------------===//
30 // spirv.BranchConditional
31 //===----------------------------------------------------------------------===//
33 spirv.module Logical GLSL450 {
34 spirv.func @cond_branch_without_arguments() -> () "None" {
35 // CHECK: %[[COND:.*]] = llvm.mlir.constant(true) : i1
36 %cond = spirv.Constant true
37 // CHECK: lvm.cond_br %[[COND]], ^bb1, ^bb2
38 spirv.BranchConditional %cond, ^true, ^false
47 spirv.func @cond_branch_with_arguments_nested() -> () "None" {
48 // CHECK: %[[COND1:.*]] = llvm.mlir.constant(true) : i1
49 %cond = spirv.Constant true
50 %0 = spirv.Constant 0 : i32
51 // CHECK: %[[COND2:.*]] = llvm.mlir.constant(false) : i1
52 %false = spirv.Constant false
53 // CHECK: llvm.cond_br %[[COND1]], ^bb1(%{{.*}}, %[[COND2]] : i32, i1), ^bb2
54 spirv.BranchConditional %cond, ^outer_true(%0, %false: i32, i1), ^outer_false
55 // CHECK: ^bb1(%{{.*}}: i32, %[[COND:.*]]: i1):
56 ^outer_true(%arg0: i32, %arg1: i1):
57 // CHECK: llvm.cond_br %[[COND]], ^bb3, ^bb4(%{{.*}}, %{{.*}} : i32, i32)
58 spirv.BranchConditional %arg1, ^inner_true, ^inner_false(%arg0, %arg0: i32, i32)
65 // CHECK: ^bb4(%{{.*}}: i32, %{{.*}}: i32):
66 ^inner_false(%arg3: i32, %arg4: i32):
70 spirv.func @cond_branch_with_weights(%cond: i1) -> () "None" {
71 // CHECK: llvm.cond_br %{{.*}} weights([1, 2]), ^bb1, ^bb2
72 spirv.BranchConditional %cond [1, 2], ^true, ^false
84 //===----------------------------------------------------------------------===//
86 //===----------------------------------------------------------------------===//
88 spirv.module Logical GLSL450 {
89 // CHECK-LABEL: @empty_loop
90 spirv.func @empty_loop() "None" {
97 // CHECK-LABEL: @infinite_loop
98 spirv.func @infinite_loop(%count : i32) -> () "None" {
99 // CHECK: llvm.br ^[[BB1:.*]]
101 // CHECK: %[[COND:.*]] = llvm.mlir.constant(true) : i1
102 // CHECK: llvm.cond_br %[[COND]], ^[[BB2:.*]], ^[[BB4:.*]]
104 // CHECK: llvm.br ^[[BB3:.*]]
106 // CHECK: llvm.br ^[[BB1:.*]]
108 // CHECK: llvm.br ^[[BB5:.*]]
110 // CHECK: llvm.return
114 %cond = spirv.Constant true
115 spirv.BranchConditional %cond, ^body, ^merge
118 spirv.Branch ^continue
131 //===----------------------------------------------------------------------===//
132 // spirv.mlir.selection
133 //===----------------------------------------------------------------------===//
135 spirv.module Logical GLSL450 {
136 spirv.func @selection_empty() -> () "None" {
137 // CHECK: llvm.return
138 spirv.mlir.selection {
143 spirv.func @selection_with_merge_block_only() -> () "None" {
144 %cond = spirv.Constant true
145 // CHECK: llvm.return
146 spirv.mlir.selection {
147 spirv.BranchConditional %cond, ^merge, ^merge
154 spirv.func @selection_with_true_block_only() -> () "None" {
155 // CHECK: %[[COND:.*]] = llvm.mlir.constant(true) : i1
156 %cond = spirv.Constant true
157 // CHECK: llvm.cond_br %[[COND]], ^bb1, ^bb2
158 spirv.mlir.selection {
159 spirv.BranchConditional %cond, ^true, ^merge
162 // CHECK: llvm.br ^bb2
166 // CHECK: llvm.br ^bb3
170 // CHECK-NEXT: llvm.return
174 spirv.func @selection_with_both_true_and_false_block() -> () "None" {
175 // CHECK: %[[COND:.*]] = llvm.mlir.constant(true) : i1
176 %cond = spirv.Constant true
177 // CHECK: llvm.cond_br %[[COND]], ^bb1, ^bb2
178 spirv.mlir.selection {
179 spirv.BranchConditional %cond, ^true, ^false
182 // CHECK: llvm.br ^bb3
186 // CHECK: llvm.br ^bb3
190 // CHECK: llvm.br ^bb4
194 // CHECK-NEXT: llvm.return
198 spirv.func @selection_with_early_return(%arg0: i1) -> i32 "None" {
199 // CHECK: %[[ZERO:.*]] = llvm.mlir.constant(0 : i32) : i32
200 %0 = spirv.Constant 0 : i32
201 // CHECK: llvm.cond_br %{{.*}}, ^bb1(%[[ZERO]] : i32), ^bb2
202 spirv.mlir.selection {
203 spirv.BranchConditional %arg0, ^true(%0 : i32), ^merge
204 // CHECK: ^bb1(%[[ARG:.*]]: i32):
206 // CHECK: llvm.return %[[ARG]] : i32
207 spirv.ReturnValue %arg1 : i32
210 // CHECK: llvm.br ^bb3
214 %one = spirv.Constant 1 : i32
215 spirv.ReturnValue %one : i32