@@ -106,6 +106,20 @@ bool LoopPipelinerInternal::initializeLoopInfo(
106106  lb = forOp.getLowerBound ();
107107  step = forOp.getStep ();
108108
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+ 
109123  dynamicLoop = true ;
110124  auto  upperBoundCst = getConstantIntValue (ub);
111125  auto  lowerBoundCst = getConstantIntValue (lb);
@@ -124,7 +138,7 @@ bool LoopPipelinerInternal::initializeLoopInfo(
124138      return  false ;
125139    }
126140    int64_t  numIteration = llvm::divideCeilSigned (ubImm - lbImm, stepImm);
127-     if  (numIteration > maxStage) {
141+     if  (numIteration >=  maxStage) {
128142      dynamicLoop = false ;
129143    } else  if  (!options.supportDynamicLoops ) {
130144      LDBG (" --fewer loop iterations than pipeline stages -> BAIL"  );
@@ -137,19 +151,6 @@ bool LoopPipelinerInternal::initializeLoopInfo(
137151    LDBG (" --no epilogue or predicate set -> BAIL"  );
138152    return  false ;
139153  }
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-   }
153154
154155  //  All operations need to have a stage.
155156  for  (Operation &op : forOp.getBody ()->without_terminator ()) {
0 commit comments