1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
// RUN: mlir-opt -convert-spirv-to-llvm='use-opaque-pointers=1' -split-input-file -verify-diagnostics %s | FileCheck %s
//===----------------------------------------------------------------------===//
// spirv.Branch
//===----------------------------------------------------------------------===//
spirv.module Logical GLSL450 {
spirv.func @branch_without_arguments() -> () "None" {
// CHECK: llvm.br ^bb1
spirv.Branch ^label
// CHECK: ^bb1
^label:
spirv.Return
}
spirv.func @branch_with_arguments() -> () "None" {
%0 = spirv.Constant 0 : i32
%1 = spirv.Constant true
// CHECK: llvm.br ^bb1(%{{.*}}, %{{.*}} : i32, i1)
spirv.Branch ^label(%0, %1: i32, i1)
// CHECK: ^bb1(%{{.*}}: i32, %{{.*}}: i1)
^label(%arg0: i32, %arg1: i1):
spirv.Return
}
}
// -----
//===----------------------------------------------------------------------===//
// spirv.BranchConditional
//===----------------------------------------------------------------------===//
spirv.module Logical GLSL450 {
spirv.func @cond_branch_without_arguments() -> () "None" {
// CHECK: %[[COND:.*]] = llvm.mlir.constant(true) : i1
%cond = spirv.Constant true
// CHECK: lvm.cond_br %[[COND]], ^bb1, ^bb2
spirv.BranchConditional %cond, ^true, ^false
// CHECK: ^bb1:
^true:
spirv.Return
// CHECK: ^bb2:
^false:
spirv.Return
}
spirv.func @cond_branch_with_arguments_nested() -> () "None" {
// CHECK: %[[COND1:.*]] = llvm.mlir.constant(true) : i1
%cond = spirv.Constant true
%0 = spirv.Constant 0 : i32
// CHECK: %[[COND2:.*]] = llvm.mlir.constant(false) : i1
%false = spirv.Constant false
// CHECK: llvm.cond_br %[[COND1]], ^bb1(%{{.*}}, %[[COND2]] : i32, i1), ^bb2
spirv.BranchConditional %cond, ^outer_true(%0, %false: i32, i1), ^outer_false
// CHECK: ^bb1(%{{.*}}: i32, %[[COND:.*]]: i1):
^outer_true(%arg0: i32, %arg1: i1):
// CHECK: llvm.cond_br %[[COND]], ^bb3, ^bb4(%{{.*}}, %{{.*}} : i32, i32)
spirv.BranchConditional %arg1, ^inner_true, ^inner_false(%arg0, %arg0: i32, i32)
// CHECK: ^bb2:
^outer_false:
spirv.Return
// CHECK: ^bb3:
^inner_true:
spirv.Return
// CHECK: ^bb4(%{{.*}}: i32, %{{.*}}: i32):
^inner_false(%arg3: i32, %arg4: i32):
spirv.Return
}
spirv.func @cond_branch_with_weights(%cond: i1) -> () "None" {
// CHECK: llvm.cond_br %{{.*}} weights([1, 2]), ^bb1, ^bb2
spirv.BranchConditional %cond [1, 2], ^true, ^false
// CHECK: ^bb1:
^true:
spirv.Return
// CHECK: ^bb2:
^false:
spirv.Return
}
}
// -----
//===----------------------------------------------------------------------===//
// spirv.mlir.loop
//===----------------------------------------------------------------------===//
spirv.module Logical GLSL450 {
// CHECK-LABEL: @infinite_loop
spirv.func @infinite_loop(%count : i32) -> () "None" {
// CHECK: llvm.br ^[[BB1:.*]]
// CHECK: ^[[BB1]]:
// CHECK: %[[COND:.*]] = llvm.mlir.constant(true) : i1
// CHECK: llvm.cond_br %[[COND]], ^[[BB2:.*]], ^[[BB4:.*]]
// CHECK: ^[[BB2]]:
// CHECK: llvm.br ^[[BB3:.*]]
// CHECK: ^[[BB3]]:
// CHECK: llvm.br ^[[BB1:.*]]
// CHECK: ^[[BB4]]:
// CHECK: llvm.br ^[[BB5:.*]]
// CHECK: ^[[BB5]]:
// CHECK: llvm.return
spirv.mlir.loop {
spirv.Branch ^header
^header:
%cond = spirv.Constant true
spirv.BranchConditional %cond, ^body, ^merge
^body:
// Do nothing
spirv.Branch ^continue
^continue:
// Do nothing
spirv.Branch ^header
^merge:
spirv.mlir.merge
}
spirv.Return
}
}
// -----
//===----------------------------------------------------------------------===//
// spirv.mlir.selection
//===----------------------------------------------------------------------===//
spirv.module Logical GLSL450 {
spirv.func @selection_empty() -> () "None" {
// CHECK: llvm.return
spirv.mlir.selection {
}
spirv.Return
}
spirv.func @selection_with_merge_block_only() -> () "None" {
%cond = spirv.Constant true
// CHECK: llvm.return
spirv.mlir.selection {
spirv.BranchConditional %cond, ^merge, ^merge
^merge:
spirv.mlir.merge
}
spirv.Return
}
spirv.func @selection_with_true_block_only() -> () "None" {
// CHECK: %[[COND:.*]] = llvm.mlir.constant(true) : i1
%cond = spirv.Constant true
// CHECK: llvm.cond_br %[[COND]], ^bb1, ^bb2
spirv.mlir.selection {
spirv.BranchConditional %cond, ^true, ^merge
// CHECK: ^bb1:
^true:
// CHECK: llvm.br ^bb2
spirv.Branch ^merge
// CHECK: ^bb2:
^merge:
// CHECK: llvm.br ^bb3
spirv.mlir.merge
}
// CHECK: ^bb3:
// CHECK-NEXT: llvm.return
spirv.Return
}
spirv.func @selection_with_both_true_and_false_block() -> () "None" {
// CHECK: %[[COND:.*]] = llvm.mlir.constant(true) : i1
%cond = spirv.Constant true
// CHECK: llvm.cond_br %[[COND]], ^bb1, ^bb2
spirv.mlir.selection {
spirv.BranchConditional %cond, ^true, ^false
// CHECK: ^bb1:
^true:
// CHECK: llvm.br ^bb3
spirv.Branch ^merge
// CHECK: ^bb2:
^false:
// CHECK: llvm.br ^bb3
spirv.Branch ^merge
// CHECK: ^bb3:
^merge:
// CHECK: llvm.br ^bb4
spirv.mlir.merge
}
// CHECK: ^bb4:
// CHECK-NEXT: llvm.return
spirv.Return
}
spirv.func @selection_with_early_return(%arg0: i1) -> i32 "None" {
// CHECK: %[[ZERO:.*]] = llvm.mlir.constant(0 : i32) : i32
%0 = spirv.Constant 0 : i32
// CHECK: llvm.cond_br %{{.*}}, ^bb1(%[[ZERO]] : i32), ^bb2
spirv.mlir.selection {
spirv.BranchConditional %arg0, ^true(%0 : i32), ^merge
// CHECK: ^bb1(%[[ARG:.*]]: i32):
^true(%arg1: i32):
// CHECK: llvm.return %[[ARG]] : i32
spirv.ReturnValue %arg1 : i32
// CHECK: ^bb2:
^merge:
// CHECK: llvm.br ^bb3
spirv.mlir.merge
}
// CHECK: ^bb3:
%one = spirv.Constant 1 : i32
spirv.ReturnValue %one : i32
}
}
|