[PATCH] D67081: [ModuloSchedule] Introduce PeelingModuloScheduleExpander

James Molloy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 3 03:04:21 PDT 2019


jmolloy added inline comments.


================
Comment at: llvm/lib/CodeGen/ModuloSchedule.cpp:1400
+    int NumStages = S.getNumStages();
+    int StageDiff = std::max(ConsumerStage - LoopProducerStage, 0);
+    NumPhis = Defaults.size() + StageDiff % NumStages;
----------------
ThomasRaoux wrote:
> I'm trying to understand this formula. 
> 
> For instance, if the ProducerStage is 2 and consumer stage is 0. When we pipeline we would run stage 2 iteration N with stage 0 iteration N+2, in this case wouldn't that mean we want 2 phi to get the value from stage 2 from iteration N? Maybe I'm missing something though.
Thanks for making me rethink this formula from the ground up. Some of these formulae have been quantatively formed rather than qualatitavely.

If ProducerStage > ConsumerStage, this can only be represented if ProducerStage - ConsumerStage == 1. Consider the following loop:

  p = phi(z, D) // D is the phi init value
  y = A p  // stage = 0
  z = B y   // stage = 1 (cannot be stage=2 as distance(B, A) = 1).

Then the unrolled schedule is:

  A0(D)
        A1(B0), B0
               A2(B1), B1

That is, B0 must be available in the same iteration as A1. Therefore the stage difference is bounded by 1 and additionally B0 must be produced before A1 in the rescheduled loop (Cycle(B) < Cycle(A)).

Note that this is only in the case where ProducerStage > ConsumerStage. In the opposite case we can always pad out the difference between stages with extra phis.

I've updated this formula and all the tests pass :)


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67081/new/

https://reviews.llvm.org/D67081





More information about the llvm-commits mailing list