@@ -106,6 +106,20 @@ bool LoopPipelinerInternal::initializeLoopInfo(
106
106
lb = forOp.getLowerBound ();
107
107
step = forOp.getStep ();
108
108
109
+ std::vector<std::pair<Operation *, unsigned >> schedule;
110
+ options.getScheduleFn (forOp, schedule);
111
+ if (schedule.empty ()) {
112
+ LDBG (" --empty schedule -> BAIL" );
113
+ return false ;
114
+ }
115
+
116
+ opOrder.reserve (schedule.size ());
117
+ for (auto &opSchedule : schedule) {
118
+ maxStage = std::max (maxStage, opSchedule.second );
119
+ stages[opSchedule.first ] = opSchedule.second ;
120
+ opOrder.push_back (opSchedule.first );
121
+ }
122
+
109
123
dynamicLoop = true ;
110
124
auto upperBoundCst = getConstantIntValue (ub);
111
125
auto lowerBoundCst = getConstantIntValue (lb);
@@ -124,7 +138,7 @@ bool LoopPipelinerInternal::initializeLoopInfo(
124
138
return false ;
125
139
}
126
140
int64_t numIteration = llvm::divideCeilSigned (ubImm - lbImm, stepImm);
127
- if (numIteration > maxStage) {
141
+ if (numIteration >= maxStage) {
128
142
dynamicLoop = false ;
129
143
} else if (!options.supportDynamicLoops ) {
130
144
LDBG (" --fewer loop iterations than pipeline stages -> BAIL" );
@@ -137,19 +151,6 @@ bool LoopPipelinerInternal::initializeLoopInfo(
137
151
LDBG (" --no epilogue or predicate set -> BAIL" );
138
152
return false ;
139
153
}
140
- std::vector<std::pair<Operation *, unsigned >> schedule;
141
- options.getScheduleFn (forOp, schedule);
142
- if (schedule.empty ()) {
143
- LDBG (" --empty schedule -> BAIL" );
144
- return false ;
145
- }
146
-
147
- opOrder.reserve (schedule.size ());
148
- for (auto &opSchedule : schedule) {
149
- maxStage = std::max (maxStage, opSchedule.second );
150
- stages[opSchedule.first ] = opSchedule.second ;
151
- opOrder.push_back (opSchedule.first );
152
- }
153
154
154
155
// All operations need to have a stage.
155
156
for (Operation &op : forOp.getBody ()->without_terminator ()) {
0 commit comments