42 lines · plain
1// RUN: mlir-query %s -c "m anyOf(getAllDefinitions(hasOpName(\"arith.addf\"),2),getAllDefinitions(hasOpName(\"tensor.extract\"),1))" | FileCheck %s2 3#map = affine_map<(d0, d1) -> (d0, d1)>4func.func @slice_use_from_above(%arg0: tensor<5x5xf32>, %arg1: tensor<5x5xf32>) {5 %0 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel"]} ins(%arg0 : tensor<5x5xf32>) outs(%arg1 : tensor<5x5xf32>) {6 ^bb0(%in: f32, %out: f32):7 %2 = arith.addf %in, %in : f328 linalg.yield %2 : f329 } -> tensor<5x5xf32>10 %collapsed = tensor.collapse_shape %0 [[0, 1]] : tensor<5x5xf32> into tensor<25xf32>11 %1 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel"]} ins(%0 : tensor<5x5xf32>) outs(%arg1 : tensor<5x5xf32>) {12 ^bb0(%in: f32, %out: f32):13 %c2 = arith.constant 2 : index14 %extracted = tensor.extract %collapsed[%c2] : tensor<25xf32>15 %2 = arith.addf %extracted, %extracted : f3216 linalg.yield %2 : f3217 } -> tensor<5x5xf32>18 return19}20 21// CHECK: Match #1:22// CHECK: %[[LINALG:.*]] = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel"]} 23// CHECK-SAME: ins(%arg0 : tensor<5x5xf32>) outs(%arg1 : tensor<5x5xf32>)24 25// CHECK: {{.*}}.mlir:7:10: note: "root" binds here26// CHECK: %[[ADDF1:.*]] = arith.addf %in, %in : f3227 28// CHECK: Match #2:29// CHECK: %[[COLLAPSED:.*]] = tensor.collapse_shape %[[LINALG]] {{\[\[.*\]\]}} : tensor<5x5xf32> into tensor<25xf32>30// CHECK: %[[C2:.*]] = arith.constant {{.*}} : index31 32// CHECK: {{.*}}.mlir:14:18: note: "root" binds here33// CHECK: %[[EXTRACTED:.*]] = tensor.extract %[[COLLAPSED]][%[[C2]]] : tensor<25xf32>34 35// CHECK: Match #3:36// CHECK: %[[COLLAPSED:.*]] = tensor.collapse_shape %[[LINALG]] {{\[\[.*\]\]}} : tensor<5x5xf32> into tensor<25xf32>37// CHECK: %[[C2:.*]] = arith.constant {{.*}} : index38// CHECK: %[[EXTRACTED:.*]] = tensor.extract %[[COLLAPSED]][%[[C2]]] : tensor<25xf32>39 40// CHECK: {{.*}}.mlir:15:10: note: "root" binds here41// CHECK: %[[ADDF2:.*]] = arith.addf %[[EXTRACTED]], %[[EXTRACTED]] : f32 42