// RUN: mlir-opt -convert-elementwise-to-linalg -split-input-file %s | FileCheck %s // In-depth checking of the linalg.generic op for a very trivial case. // CHECK: #map = affine_map<() -> ()> // CHECK-LABEL: func @addf_rank0 func @addf_rank0(%arg0: tensor, %arg1: tensor) -> tensor { // CHECK: %{{.*}} = linalg.generic {indexing_maps = [#map, #map, #map], iterator_types = []} ins(%{{.*}}, %{{.*}} : tensor, tensor) { // CHECK: ^bb0(%[[LHS:.*]]: f32, %[[RHS:.*]]: f32): // CHECK: %[[YIELD:.*]] = addf %[[LHS]], %[[RHS]] : f32 // CHECK: linalg.yield %[[YIELD]] : f32 // CHECK: } -> tensor %0 = addf %arg0, %arg1 : tensor return %0 : tensor } // ----- // Check indexing maps and iterator types for the rank > 0 case. // CHECK: #map = affine_map<(d0) -> (d0)> // CHECK-LABEL: func @addf_rank1 func @addf_rank1(%arg0: tensor, %arg1: tensor) -> tensor { // CHECK: linalg.generic{{.*}}indexing_maps = [#map, #map, #map], iterator_types = ["parallel"] %0 = addf %arg0, %arg1 : tensor return %0 : tensor } // ----- // Check a unary op. // CHECK-LABEL: func @exp func @exp(%arg0: tensor) -> tensor { // CHECK: linalg.generic // CHECK: ^bb0(%[[SCALAR:.*]]: f32): // CHECK: %[[YIELD:.*]] = exp %[[SCALAR]] : f32 // CHECK: linalg.yield %[[YIELD]] : f32 %0 = exp %arg0 : tensor return %0 : tensor } // ----- // Check a case with varying operand types. // CHECK-LABEL: func @select func @select(%arg0: tensor, %arg1: tensor, %arg2: tensor) -> tensor { // CHECK: linalg.generic // CHECK: ^bb0(%[[PRED:.*]]: i1, %[[TRUE_VAL:.*]]: i32, %[[FALSE_VAL:.*]]: i32): // CHECK: select %[[PRED]], %[[TRUE_VAL]], %[[FALSE_VAL]] : i32 %0 = select %arg0, %arg1, %arg2 : tensor, tensor return %0 : tensor } // ----- // Spot-check an op that requires copying attributes properly to the created scalar op. // CHECK-LABEL: func @cmpf( func @cmpf(%arg0: tensor, %arg1: tensor) -> tensor { // CHECK: cmpf "olt", %{{.*}}, %{{.*}} : f32 %0 = cmpf "olt", %arg0, %arg1 : tensor return %0 : tensor }