1// RUN: mlir-opt %s  -split-input-file -affine-loop-tile="tile-size=32" -verify-diagnostics | FileCheck %s
2
3// -----
4
5// There is no dependence violated in this case. No error should be raised.
6
7// CHECK-DAG: [[$LB:#map[0-9]+]] = affine_map<(d0) -> (d0)>
8// CHECK-DAG: [[$UB:#map[0-9]+]] = affine_map<(d0) -> (d0 + 32)>
9
10// CHECK-LABEL: func @legal_loop()
11func @legal_loop() {
12  %0 = alloc() : memref<64xf32>
13
14  affine.for %i = 0 to 64 {
15    %1 = affine.load %0[%i] : memref<64xf32>
16    %2 = addf %1, %1 : f32
17    affine.store %2, %0[%i] : memref<64xf32>
18  }
19
20  return
21}
22
23// CHECK:   affine.for %{{.*}} = 0 to 64 step 32 {
24// CHECK-NEXT:     affine.for %{{.*}} = [[$LB]](%{{.*}}) to [[$UB]](%{{.*}}) {
25
26// -----
27
28// There are dependences along the diagonal of the 2d iteration space,
29// specifically, they are of direction (+, -).
30// The default tiling method (hyper-rect) will violate tiling legality.
31// We expect a remark that points that issue out to be emitted.
32
33// CHECK-LABEL: func @illegal_loop_with_diag_dependence
34func @illegal_loop_with_diag_dependence() {
35  %A = alloc() : memref<64x64xf32>
36
37  affine.for %i = 0 to 64 {
38    // expected-remark@above {{tiled code is illegal due to dependences}}
39    affine.for %j = 0 to 64 {
40      %0 = affine.load %A[%j, %i] : memref<64x64xf32>
41      %1 = affine.load %A[%i, %j - 1] : memref<64x64xf32>
42      %2 = addf %0, %1 : f32
43      affine.store %2, %A[%i, %j] : memref<64x64xf32>
44    }
45  }
46
47  return
48}
49