xref: /llvm-project/mlir/test/Dialect/Linalg/runtime-verification.mlir (revision d94aeb507d71d72f4153b4c87c77fcb5187b3e9a)
1// RUN: mlir-opt %s -generate-runtime-verification | FileCheck %s
2
3// Most of the tests for linalg runtime-verification are implemented as integration tests.
4
5#identity = affine_map<(d0) -> (d0)>
6
7// CHECK-LABEL: @static_dims
8func.func @static_dims(%arg0: tensor<5xf32>, %arg1: tensor<5xf32>) -> (tensor<5xf32>) {
9    // CHECK: %[[TRUE:.*]] = index.bool.constant true
10    // CHECK: cf.assert %[[TRUE]]
11    %result = tensor.empty() : tensor<5xf32>
12    %0 = linalg.generic {
13      indexing_maps = [#identity, #identity, #identity],
14      iterator_types = ["parallel"]
15    } ins(%arg0, %arg1 : tensor<5xf32>, tensor<5xf32>)
16      outs(%result : tensor<5xf32>) {
17      ^bb0(%gen_arg1: f32, %gen_arg2: f32, %out: f32) :
18        %tmp1 = arith.addf %gen_arg1, %gen_arg2 : f32
19        linalg.yield %tmp1 : f32
20    } -> tensor<5xf32>
21    return %0 : tensor<5xf32>
22}
23
24// -----
25
26#map = affine_map<() -> ()>
27
28// CHECK-LABEL: @scalars
29func.func @scalars(%arg0: tensor<f32>, %arg1: tensor<f32>) -> (tensor<f32>) {
30    // No runtime checks are required if the operands are all scalars
31    // CHECK-NOT: cf.assert
32    %result = tensor.empty() : tensor<f32>
33    %0 = linalg.generic {
34      indexing_maps = [#map, #map, #map],
35      iterator_types = []
36    } ins(%arg0, %arg1 : tensor<f32>, tensor<f32>)
37      outs(%result : tensor<f32>) {
38      ^bb0(%gen_arg1: f32, %gen_arg2: f32, %out: f32) :
39        %tmp1 = arith.addf %gen_arg1, %gen_arg2 : f32
40        linalg.yield %tmp1 : f32
41    } -> tensor<f32>
42    return %0 : tensor<f32>
43}
44