// RUN: mlir-opt %s -scf-bufferize | FileCheck %s // CHECK-LABEL: func @if( // CHECK-SAME: %[[PRED:.*]]: i1, // CHECK-SAME: %[[TRUE_TENSOR:.*]]: tensor, // CHECK-SAME: %[[FALSE_TENSOR:.*]]: tensor) -> tensor { // CHECK: %[[RESULT_MEMREF:.*]] = scf.if %[[PRED]] -> (memref) { // CHECK: %[[TRUE_MEMREF:.*]] = tensor_to_memref %[[TRUE_TENSOR]] : memref // CHECK: scf.yield %[[TRUE_MEMREF]] : memref // CHECK: } else { // CHECK: %[[FALSE_MEMREF:.*]] = tensor_to_memref %[[FALSE_TENSOR]] : memref // CHECK: scf.yield %[[FALSE_MEMREF]] : memref // CHECK: } // CHECK: %[[RESULT_TENSOR:.*]] = tensor_load %[[RESULT_MEMREF:.*]] : memref // CHECK: return %[[RESULT_TENSOR]] : tensor // CHECK: } func @if(%pred: i1, %true_val: tensor, %false_val: tensor) -> tensor { %0 = scf.if %pred -> (tensor) { scf.yield %true_val : tensor } else { scf.yield %false_val : tensor } return %0 : tensor } // CHECK-LABEL: func @for( // CHECK-SAME: %[[TENSOR:.*]]: tensor, // CHECK-SAME: %[[LB:.*]]: index, %[[UB:.*]]: index, // CHECK-SAME: %[[STEP:.*]]: index) -> tensor { // CHECK: %[[MEMREF:.*]] = tensor_to_memref %[[TENSOR]] : memref // CHECK: %[[RESULT_MEMREF:.*]] = scf.for %[[VAL_6:.*]] = %[[LB]] to %[[UB]] step %[[STEP]] iter_args(%[[ITER:.*]] = %[[MEMREF]]) -> (memref) { // CHECK: %[[TENSOR_ITER:.*]] = tensor_load %[[ITER]] : memref // CHECK: %[[MEMREF_YIELDED:.*]] = tensor_to_memref %[[TENSOR_ITER]] : memref // CHECK: scf.yield %[[MEMREF_YIELDED]] : memref // CHECK: } // CHECK: %[[VAL_8:.*]] = tensor_load %[[VAL_9:.*]] : memref // CHECK: return %[[VAL_8]] : tensor // CHECK: } func @for(%arg0: tensor, %lb: index, %ub: index, %step: index) -> tensor { %ret = scf.for %iv = %lb to %ub step %step iter_args(%iter = %arg0) -> tensor { scf.yield %iter : tensor } return %ret : tensor } // Check whether this converts at all. // // It would previously fail altogether. // CHECK-LABEL: func @if_correct_recursive_legalization_behavior // CHECK: "test.munge_tensor" func @if_correct_recursive_legalization_behavior(%pred: i1, %tensor: tensor) -> tensor { %0 = scf.if %pred -> (tensor) { %1 = "test.munge_tensor"(%tensor) : (tensor) -> (tensor) scf.yield %1: tensor } else { %1 = "test.munge_tensor"(%tensor) : (tensor) -> (tensor) scf.yield %1 : tensor } return %0 : tensor } // CHECK-LABEL: func @for_correct_recursive_legalization_behavior( // CHECK-SAME: %[[TENSOR:.*]]: tensor, // CHECK-SAME: %[[INDEX:.*]]: index) -> tensor { // CHECK: %[[MEMREF:.*]] = tensor_to_memref %[[TENSOR]] : memref // CHECK: %[[RESULT:.*]] = scf.for %[[IV:.*]] = %[[INDEX]] to %[[INDEX]] step %[[INDEX]] iter_args(%[[MEMREF_ITER:.*]] = %[[MEMREF]]) -> (memref) { // CHECK: %[[TENSOR_ITER:.*]] = tensor_load %[[MEMREF_ITER]] : memref // CHECK: %[[TENSOR_MUNGED:.*]] = "test.munge_tensor"(%[[TENSOR_ITER]]) : (tensor) -> tensor // CHECK: %[[MEMREF_MUNGED:.*]] = tensor_to_memref %[[TENSOR_MUNGED]] : memref // CHECK: scf.yield %[[MEMREF_MUNGED]] : memref // CHECK: } // CHECK: %[[TENSOR:.*]] = tensor_load %[[RESULT:.*]] : memref // CHECK: return %[[TENSOR]] : tensor // CHECK: } func @for_correct_recursive_legalization_behavior(%arg0: tensor, %index: index) -> tensor { %ret = scf.for %iv = %index to %index step %index iter_args(%iter = %arg0) -> tensor { %0 = "test.munge_tensor"(%iter) : (tensor) -> (tensor) scf.yield %0 : tensor } return %ret : tensor }