• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: mlir-opt -test-extract-fixed-outer-loops='test-outer-loop-sizes=7' %s | FileCheck %s --check-prefixes=COMMON,TILE_7
2// RUN: mlir-opt -test-extract-fixed-outer-loops='test-outer-loop-sizes=7,4' %s | FileCheck %s --check-prefixes=COMMON,TILE_74
3
4// COMMON-LABEL: @rectangular
5func @rectangular(%arg0: memref<?x?xf32>) {
6  %c2 = constant 2 : index
7  %c44 = constant 44 : index
8  %c1 = constant 1 : index
9  // Range of the original loop:
10  //   (upper - lower + step - 1) / step
11  // where step is known to be %c1.
12  // COMMON:      %[[diff:.*]] = subi %c44, %c2
13  // COMMON:      %[[adjustment:.*]] = subi %c1, %c1_{{.*}}
14  // COMMON-NEXT: %[[diff_adj:.*]] = addi %[[diff]], %[[adjustment]]
15  // COMMON-NEXT: %[[range:.*]] = divi_signed %[[diff_adj]], %c1
16
17  // Ceildiv to get the parametric tile size.
18  // COMMON:       %[[sum:.*]] = addi %[[range]], %c6
19  // COMMON-NEXT:  %[[size:.*]] = divi_signed %[[sum]], %c7
20  // New outer step (original is %c1).
21  // COMMON-NEXT:      %[[step:.*]] = muli %c1, %[[size]]
22
23  // Range of the second original loop
24  //   (upper - lower + step - 1) / step
25  // where step is known to be %c2.
26  // TILE_74:      %[[diff2:.*]] = subi %c44, %c1
27  // TILE_74:      %[[adjustment2:.*]] = subi %c2, %c1_{{.*}}
28  // TILE_74-NEXT: %[[diff2_adj:.*]] = addi %[[diff2]], %[[adjustment2]]
29  // TILE_74-NEXT: %[[range2:.*]] = divi_signed %[[diff2_adj]], %c2
30
31  // Ceildiv to get the parametric tile size for the second original scf.
32  // TILE_74:      %[[sum2:.*]] = addi %[[range2]], %c3
33  // TILE_74-NEXT: %[[size2:.*]] = divi_signed %[[sum2]], %c4
34  // New inner step (original is %c2).
35  // TILE_74-NEXT:     %[[step2:.*]] = muli %c2, %[[size2]]
36
37  // Updated outer loop(s) use new steps.
38  // COMMON: scf.for %[[i:.*]] = %c2 to %c44 step %[[step]]
39  // TILE_74:scf.for %[[j:.*]] = %c1 to %c44 step %[[step2]]
40 scf.for %i = %c2 to %c44 step %c1 {
41    // Upper bound for the inner loop min(%i + %step, %c44).
42    // COMMON:      %[[stepped:.*]] = addi %[[i]], %[[step]]
43    // COMMON-NEXT: cmpi "slt", %c44, %[[stepped]]
44    // COMMON-NEXT: %[[ub:.*]] = select {{.*}}, %c44, %[[stepped]]
45    //
46    // TILE_74:      %[[stepped2:.*]] = addi %[[j]], %[[step2]]
47    // TILE_74-NEXT: cmpi "slt", %c44, %[[stepped2]]
48    // TILE_74-NEXT: %[[ub2:.*]] = select {{.*}}, %c44, %[[stepped2]]
49
50    // Created inner scf.
51    // COMMON:scf.for %[[ii:.*]] = %[[i]] to %[[ub:.*]] step %c1
52
53    // This loop is not modified in TILE_7 case.
54    // TILE_7: scf.for %[[j:.*]] = %c1 to %c44 step %c2
55    //
56    // But is modified in TILE_74 case.
57    // TILE_74:scf.for %[[jj:.*]] = %[[j]] to %[[ub2]] step %c2
58   scf.for %j = %c1 to %c44 step %c2 {
59      // The right iterator are used.
60      // TILE_7:  load %arg0[%[[ii]], %[[j]]]
61      // TILE_74: load %arg0[%[[ii]], %[[jj]]]
62      load %arg0[%i, %j]: memref<?x?xf32>
63    }
64  }
65  return
66}
67
68// COMMON-LABEL: @triangular
69func @triangular(%arg0: memref<?x?xf32>) {
70  %c2 = constant 2 : index
71  %c44 = constant 44 : index
72  %c1 = constant 1 : index
73  // Range of the original outer loop:
74  //   (upper - lower + step - 1) / step
75  // where step is known to be %c1.
76  // COMMON:      %[[diff:.*]] = subi %c44, %c2
77  // COMMON:      %[[adjustment:.*]] = subi %c1, %c1_{{.*}}
78  // COMMON-NEXT: %[[diff_adj:.*]] = addi %[[diff]], %[[adjustment]]
79  // COMMON-NEXT: %[[range:.*]] = divi_signed %[[diff_adj]], %c1
80
81  // Ceildiv to get the parametric tile size.
82  // COMMON:       %[[sum:.*]] = addi %[[range]], %c6
83  // COMMON-NEXT:  %[[size:.*]] = divi_signed %[[sum]], %c7
84  // New outer step (original is %c1).
85  // COMMON-NEXT:  %[[step:.*]] = muli %c1, %[[size]]
86
87  // Constant adjustment for inner loop has been hoisted out.
88  // TILE_74:      %[[adjustment2:.*]] = subi %c2, %c1_{{.*}}
89
90  // New outer scf.
91  // COMMON: scf.for %[[i:.*]] = %c2 to %c44 step %[[step]]
92
93  // Range of the original inner loop
94  //   (upper - lower + step - 1) / step
95  // where step is known to be %c2.
96  // TILE_74:      %[[diff2:.*]] = subi %[[i]], %c1
97  // TILE_74-NEXT: %[[diff2_adj:.*]] = addi %[[diff2]], %[[adjustment2]]
98  // TILE_74-NEXT: %[[range2:.*]] = divi_signed %[[diff2_adj]], %c2
99
100  // Ceildiv to get the parametric tile size for the second original scf.
101  // TILE_74:      %[[sum2:.*]] = addi %[[range2]], %c3
102  // TILE_74-NEXT: %[[size2:.*]] = divi_signed %[[sum2]], %c4
103  // New inner step (original is %c2).
104  // TILE_74-NEXT:     %[[step2:.*]] = muli %c2, %[[size2]]
105
106  // New inner scf.
107  // TILE_74:scf.for %[[j:.*]] = %c1 to %[[i]] step %[[step2]]
108 scf.for %i = %c2 to %c44 step %c1 {
109    // Upper bound for the inner loop min(%i + %step, %c44).
110    // COMMON:      %[[stepped:.*]] = addi %[[i]], %[[step]]
111    // COMMON-NEXT: cmpi "slt", %c44, %[[stepped]]
112    // COMMON-NEXT: %[[ub:.*]] = select {{.*}}, %c44, %[[stepped]]
113    // TILE_74:      %[[stepped2:.*]] = addi %[[j]], %[[step2]]
114    // TILE_74-NEXT: cmpi "slt", %[[i]], %[[stepped2]]
115    // TILE_74-NEXT: %[[ub2:.*]] = select {{.*}}, %[[i]], %[[stepped2]]
116    //
117    // Created inner scf.
118    // COMMON:scf.for %[[ii:.*]] = %[[i]] to %[[ub:.*]] step %c1
119
120    // This loop is not modified in TILE_7 case.
121    // TILE_7: scf.for %[[j:.*]] = %c1 to %[[ii]] step %c2
122    //
123    // But is modified in TILE_74 case.
124    // TILE_74:scf.for %[[jj:.*]] = %[[j]] to %[[ub2]] step %c2
125   scf.for %j = %c1 to %i step %c2 {
126      // The right iterator are used.
127      // TILE_7:  load %arg0[%[[ii]], %[[j]]]
128      // TILE_74: load %arg0[%[[ii]], %[[jj]]]
129      load %arg0[%i, %j]: memref<?x?xf32>
130    }
131  }
132  return
133}
134