// RUN: mlir-hlo-opt -mhlo-legalize-control-flow %s -o - | FileCheck %s // CHECK-LABEL: func @while(%arg0: tensor) -> tensor { func @while(%arg0: tensor) -> tensor { //CHECK: br ^bb1(%arg0 : tensor) //CHECK: ^bb1([[VAL0:%.+]]: tensor): //CHECK: [[VAL1:%.+]] = "mhlo.compare"([[VAL0]], [[VAL0]]) //CHECK: [[VAL2:%.+]] = tensor.extract [[VAL1]][] : tensor //CHECK: cond_br [[VAL2]], ^bb2([[VAL0]] : tensor), ^bb3([[VAL0]] : tensor) //CHECK: ^bb2([[VAL3:%.+]]: tensor): //CHECK: [[VAL4:%.+]] = mhlo.add [[VAL3]], [[VAL3]] //CHECK: br ^bb1([[VAL4]] : tensor) //CHECK: ^bb3([[VAL5:%.+]]: tensor): %0 = "mhlo.while"(%arg0) ( { ^bb0(%arg1: tensor): %1 = "mhlo.compare"(%arg1, %arg1) {comparison_direction = "LT", name = "compare.2"} : (tensor, tensor) -> tensor "mhlo.return"(%1) : (tensor) -> () }, { ^bb0(%arg1: tensor): %1 = mhlo.add %arg1, %arg1 {name = "compare.0"} : tensor "mhlo.return"(%1) : (tensor) -> () }) : (tensor) -> tensor // CHECK-NEXT: return [[VAL5]] return %0 : tensor } // CHECK-LABEL: func @conditional func @conditional(%arg0: tensor) -> tensor { // CHECK: [[C0:%.+]] = constant dense<1.000000e+01> : tensor %cst = constant dense<1.000000e+01> : tensor // CHECK: [[VAL0:%.+]] = "mhlo.compare"(%arg0, [[C0]]) {comparison_direction = "LT"} : (tensor, tensor) -> tensor %0 = "mhlo.compare"(%arg0, %cst) {comparison_direction = "LT"} : (tensor, tensor) -> tensor // CHECK: [[VAL1:%.+]] = tensor.extract [[VAL0]][] : tensor // CHECK: cond_br [[VAL1]], ^bb1(%arg0 : tensor), ^bb2(%arg0 : tensor) %1 = "mhlo.if"(%0, %arg0, %arg0) ( { ^bb0(%arg1: tensor): // CHECK: ^bb1([[VAL2:%.+]]: tensor): // CHECK: [[VAL3:%.+]] = "mhlo.log"([[VAL2]]) : (tensor) -> tensor // CHECK: br ^bb3([[VAL3]] : tensor) %2 = "mhlo.log"(%arg1) : (tensor) -> tensor "mhlo.return"(%2) : (tensor) -> () }, { ^bb0(%arg1: tensor): // CHECK: ^bb2([[VAL4:%.+]]: tensor): // CHECK: [[VAL5:%.+]] = "mhlo.exponential"([[VAL4]]) : (tensor) -> tensor // CHECK: br ^bb3([[VAL5]] : tensor) %2 = "mhlo.exponential"(%arg1) : (tensor) -> tensor "mhlo.return"(%2) : (tensor) -> () }) : (tensor, tensor, tensor) -> tensor // CHECK: ^bb3([[VAL6:%.+]]: tensor): // CHECK: return [[VAL6]] : tensor return %1 : tensor }