[PATCH] D75013: [LoopTerminology] Rotated Loops

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 23 15:29:37 PST 2020


Meinersbur added inline comments.


================
Comment at: llvm/docs/LoopTerminology.rst:161-163
+Loops are rotated by the loop-rotate pass. The purpose
+of this transformation is to convert loops into
+do/while style loops. Example:
----------------
baziotis wrote:
> Meinersbur wrote:
> > Converting to do/while style is a description of loop-rotation. One of the purposes is to allow hoisting invariant loads into the preheader. In non-rotated loops, a load in the preaheader would be executed even if the memory was never accessed in the original loop.
> Oh, because you might do no iterations at all right? So, with the do-while, you'll do at least once. Regarding the wording, is this better?
> "Loops are rotated by the loop-rotate pass, which converts loops into do/while style loops."
> Then follow with examples and then mention the purposes. Also, should I add to the purposes that a latch block is an exiting block (and that this is useful to loop fusion) ? Although, as I stated in the comment, I have not completely understood this part with the latch.
Yes, it is better.

The latch being also an exiting block is kind-of the definition of loop rotation: the latch contains the condition on whether to execute another iteration or leave the loop, i.e. the condition if the `do` part of a while/do loop.
```
  /// Return true if the loop is in rotated form.
  ///
  /// This does not check if the loop was rotated by loop rotation, instead it
  /// only checks if the loop is in rotated form (has a valid latch that exists
  /// the loop).
  bool isRotatedForm() const {
    assert(!isInvalid() && "Loop not in a valid state!");
    BasicBlock *Latch = getLoopLatch();
    return Latch && isLoopExiting(Latch);
  }
```


================
Comment at: llvm/docs/LoopTerminology.rst:195-196
+
+This transformation canonicalizes the loop latch to have
+a single successor, which implies that the loop latch
+is also an exiting block. It is done by the `loop-rotate`
----------------
[serious] By definition, a latch has a backedge to the header. If the latch had just a single successor, there could not be another edge to outside the loop.

Using C code to describe the effect is higher level than the IR-level it is actually performed on. What a latch is is not obvious in the C code. LoopRotate also copies the header block, which might be interesting to mention.


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

https://reviews.llvm.org/D75013





More information about the llvm-commits mailing list