1// RUN: mlir-opt -convert-elementwise-to-linalg -split-input-file %s | FileCheck %s 2 3// In-depth checking of the linalg.generic op for a very trivial case. 4// CHECK: #map = affine_map<() -> ()> 5// CHECK-LABEL: func @addf_rank0 6func @addf_rank0(%arg0: tensor<f32>, %arg1: tensor<f32>) -> tensor<f32> { 7 // CHECK: %{{.*}} = linalg.generic {indexing_maps = [#map, #map, #map], iterator_types = []} ins(%{{.*}}, %{{.*}} : tensor<f32>, tensor<f32>) { 8 // CHECK: ^bb0(%[[LHS:.*]]: f32, %[[RHS:.*]]: f32): 9 // CHECK: %[[YIELD:.*]] = addf %[[LHS]], %[[RHS]] : f32 10 // CHECK: linalg.yield %[[YIELD]] : f32 11 // CHECK: } -> tensor<f32> 12 %0 = addf %arg0, %arg1 : tensor<f32> 13 return %0 : tensor<f32> 14} 15 16// ----- 17 18// Check indexing maps and iterator types for the rank > 0 case. 19// CHECK: #map = affine_map<(d0) -> (d0)> 20// CHECK-LABEL: func @addf_rank1 21func @addf_rank1(%arg0: tensor<?xf32>, %arg1: tensor<?xf32>) -> tensor<?xf32> { 22 // CHECK: linalg.generic{{.*}}indexing_maps = [#map, #map, #map], iterator_types = ["parallel"] 23 %0 = addf %arg0, %arg1 : tensor<?xf32> 24 return %0 : tensor<?xf32> 25} 26 27// ----- 28 29// Check a unary op. 30// CHECK-LABEL: func @exp 31func @exp(%arg0: tensor<f32>) -> tensor<f32> { 32 // CHECK: linalg.generic 33 // CHECK: ^bb0(%[[SCALAR:.*]]: f32): 34 // CHECK: %[[YIELD:.*]] = exp %[[SCALAR]] : f32 35 // CHECK: linalg.yield %[[YIELD]] : f32 36 %0 = exp %arg0 : tensor<f32> 37 return %0 : tensor<f32> 38} 39 40// ----- 41 42// Check a case with varying operand types. 43// CHECK-LABEL: func @select 44func @select(%arg0: tensor<i1>, %arg1: tensor<i32>, %arg2: tensor<i32>) -> tensor<i32> { 45 // CHECK: linalg.generic 46 // CHECK: ^bb0(%[[PRED:.*]]: i1, %[[TRUE_VAL:.*]]: i32, %[[FALSE_VAL:.*]]: i32): 47 // CHECK: select %[[PRED]], %[[TRUE_VAL]], %[[FALSE_VAL]] : i32 48 %0 = select %arg0, %arg1, %arg2 : tensor<i1>, tensor<i32> 49 return %0 : tensor<i32> 50} 51 52// ----- 53 54// Spot-check an op that requires copying attributes properly to the created scalar op. 55// CHECK-LABEL: func @cmpf( 56func @cmpf(%arg0: tensor<f32>, %arg1: tensor<f32>) -> tensor<i1> { 57 // CHECK: cmpf "olt", %{{.*}}, %{{.*}} : f32 58 %0 = cmpf "olt", %arg0, %arg1 : tensor<f32> 59 return %0 : tensor<i1> 60} 61