1 // RUN: mlir-opt -convert-spirv-to-llvm -split-input-file -verify-diagnostics %s | FileCheck %s
3 //===----------------------------------------------------------------------===//
5 //===----------------------------------------------------------------------===//
7 spv.module Logical GLSL450 {
8 spv.func @branch_without_arguments() -> () "None" {
16 spv.func @branch_with_arguments() -> () "None" {
17 %0 = spv.Constant 0 : i32
18 %1 = spv.Constant true
19 // CHECK: llvm.br ^bb1(%{{.*}}, %{{.*}} : i32, i1)
20 spv.Branch ^label(%0, %1: i32, i1)
21 // CHECK: ^bb1(%{{.*}}: i32, %{{.*}}: i1)
22 ^label(%arg0: i32, %arg1: i1):
29 //===----------------------------------------------------------------------===//
30 // spv.BranchConditional
31 //===----------------------------------------------------------------------===//
33 spv.module Logical GLSL450 {
34 spv.func @cond_branch_without_arguments() -> () "None" {
35 // CHECK: %[[COND:.*]] = llvm.mlir.constant(true) : i1
36 %cond = spv.Constant true
37 // CHECK: lvm.cond_br %[[COND]], ^bb1, ^bb2
38 spv.BranchConditional %cond, ^true, ^false
47 spv.func @cond_branch_with_arguments_nested() -> () "None" {
48 // CHECK: %[[COND1:.*]] = llvm.mlir.constant(true) : i1
49 %cond = spv.Constant true
50 %0 = spv.Constant 0 : i32
51 // CHECK: %[[COND2:.*]] = llvm.mlir.constant(false) : i1
52 %false = spv.Constant false
53 // CHECK: llvm.cond_br %[[COND1]], ^bb1(%{{.*}}, %[[COND2]] : i32, i1), ^bb2
54 spv.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 spv.BranchConditional %arg1, ^inner_true, ^inner_false(%arg0, %arg0: i32, i32)
65 // CHECK: ^bb4(%{{.*}}: i32, %{{.*}}: i32):
66 ^inner_false(%arg3: i32, %arg4: i32):
70 spv.func @cond_branch_with_weights(%cond: i1) -> () "None" {
71 // CHECK: llvm.cond_br %{{.*}} weights(dense<[1, 2]> : vector<2xi32>), ^bb1, ^bb2
72 spv.BranchConditional %cond [1, 2], ^true, ^false
84 //===----------------------------------------------------------------------===//
86 //===----------------------------------------------------------------------===//
88 spv.module Logical GLSL450 {
89 // CHECK-LABEL: @infinite_loop
90 spv.func @infinite_loop(%count : i32) -> () "None" {
91 // CHECK: llvm.br ^[[BB1:.*]]
93 // CHECK: %[[COND:.*]] = llvm.mlir.constant(true) : i1
94 // CHECK: llvm.cond_br %[[COND]], ^[[BB2:.*]], ^[[BB4:.*]]
96 // CHECK: llvm.br ^[[BB3:.*]]
98 // CHECK: llvm.br ^[[BB1:.*]]
100 // CHECK: llvm.br ^[[BB5:.*]]
102 // CHECK: llvm.return
106 %cond = spv.Constant true
107 spv.BranchConditional %cond, ^body, ^merge
123 //===----------------------------------------------------------------------===//
124 // spv.mlir.selection
125 //===----------------------------------------------------------------------===//
127 spv.module Logical GLSL450 {
128 spv.func @selection_empty() -> () "None" {
129 // CHECK: llvm.return
135 spv.func @selection_with_merge_block_only() -> () "None" {
136 %cond = spv.Constant true
137 // CHECK: llvm.return
139 spv.BranchConditional %cond, ^merge, ^merge
146 spv.func @selection_with_true_block_only() -> () "None" {
147 // CHECK: %[[COND:.*]] = llvm.mlir.constant(true) : i1
148 %cond = spv.Constant true
149 // CHECK: llvm.cond_br %[[COND]], ^bb1, ^bb2
151 spv.BranchConditional %cond, ^true, ^merge
154 // CHECK: llvm.br ^bb2
158 // CHECK: llvm.br ^bb3
162 // CHECK-NEXT: llvm.return
166 spv.func @selection_with_both_true_and_false_block() -> () "None" {
167 // CHECK: %[[COND:.*]] = llvm.mlir.constant(true) : i1
168 %cond = spv.Constant true
169 // CHECK: llvm.cond_br %[[COND]], ^bb1, ^bb2
171 spv.BranchConditional %cond, ^true, ^false
174 // CHECK: llvm.br ^bb3
178 // CHECK: llvm.br ^bb3
182 // CHECK: llvm.br ^bb4
186 // CHECK-NEXT: llvm.return
190 spv.func @selection_with_early_return(%arg0: i1) -> i32 "None" {
191 // CHECK: %[[ZERO:.*]] = llvm.mlir.constant(0 : i32) : i32
192 %0 = spv.Constant 0 : i32
193 // CHECK: llvm.cond_br %{{.*}}, ^bb1(%[[ZERO]] : i32), ^bb2
195 spv.BranchConditional %arg0, ^true(%0 : i32), ^merge
196 // CHECK: ^bb1(%[[ARG:.*]]: i32):
198 // CHECK: llvm.return %[[ARG]] : i32
199 spv.ReturnValue %arg1 : i32
202 // CHECK: llvm.br ^bb3
206 %one = spv.Constant 1 : i32
207 spv.ReturnValue %one : i32