1// RUN: mlir-opt %s -convert-cf-to-llvm -split-input-file | FileCheck %s 2 3// Unstructured control flow is converted, but the enclosing op is not 4// converted. 5 6// CHECK-LABEL: func.func @cf_br( 7// CHECK-SAME: %[[arg0:.*]]: index) -> index { 8// CHECK: %[[cast0:.*]] = builtin.unrealized_conversion_cast %[[arg0]] : index to i64 9// CHECK: llvm.br ^[[bb1:.*]](%[[cast0]] : i64) 10// CHECK: ^[[bb1]](%[[arg1:.*]]: i64): 11// CHECK: %[[cast1:.*]] = builtin.unrealized_conversion_cast %[[arg1]] : i64 to index 12// CHECK: return %[[cast1]] : index 13// CHECK: } 14func.func @cf_br(%arg0: index) -> index { 15 cf.br ^bb1(%arg0 : index) 16^bb1(%arg1: index): 17 return %arg1 : index 18} 19 20// ----- 21 22// func.func and func.return types match. No unrealized_conversion_cast is 23// needed. 24 25// CHECK-LABEL: func.func @cf_br_type_match( 26// CHECK-SAME: %[[arg0:.*]]: i64) -> i64 { 27// CHECK: llvm.br ^[[bb1:.*]](%[[arg0:.*]] : i64) 28// CHECK: ^[[bb1]](%[[arg1:.*]]: i64): 29// CHECK: return %[[arg1]] : i64 30// CHECK: } 31func.func @cf_br_type_match(%arg0: i64) -> i64 { 32 cf.br ^bb1(%arg0 : i64) 33^bb1(%arg1: i64): 34 return %arg1 : i64 35} 36 37// ----- 38 39// Test case for cf.cond_br. 40 41// CHECK-LABEL: func.func @cf_cond_br 42// CHECK-COUNT-2: unrealized_conversion_cast {{.*}} : index to i64 43// CHECK: llvm.cond_br %{{.*}}, ^{{.*}}(%{{.*}} : i64), ^{{.*}}(%{{.*}} : i64) 44// CHECK: ^{{.*}}(%{{.*}}: i64): 45// CHECK: unrealized_conversion_cast {{.*}} : i64 to index 46// CHECK: ^{{.*}}(%{{.*}}: i64): 47// CHECK: unrealized_conversion_cast {{.*}} : i64 to index 48func.func @cf_cond_br(%cond: i1, %a: index, %b: index) -> index { 49 cf.cond_br %cond, ^bb1(%a : index), ^bb2(%b : index) 50^bb1(%arg1: index): 51 return %arg1 : index 52^bb2(%arg2: index): 53 return %arg2 : index 54} 55 56// ----- 57 58// Unreachable block (and IR in general) is not converted during a dialect 59// conversion. 60 61// CHECK-LABEL: func.func @unreachable_block() 62// CHECK: return 63// CHECK: ^[[bb1:.*]](%[[arg0:.*]]: index): 64// CHECK: cf.br ^[[bb1]](%[[arg0]] : index) 65func.func @unreachable_block() { 66 return 67^bb1(%arg0: index): 68 cf.br ^bb1(%arg0 : index) 69} 70