[PATCH] D75013: [LoopTerminology] Rotated Loops

Stefanos Baziotis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 22 13:04:46 PST 2020


baziotis created this revision.
baziotis added reviewers: Meinersbur, kbarton, fhahn, etiotto.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Information gathered from:

- Writing Loop Optimizations in LLVM <https://youtu.be/3pRhvQi7Z10?t=287>
- Loop Fusion, Loop Distribution and their Place in the Loop Optimization Pipeline <https://youtu.be/-JQr9aNagQo?t=330>
- Loop Transformations in LLVM: The Good, The Bad and the Ugly <https://youtu.be/QpvZt9w-Jik?t=521>
- Reading code in https://llvm.org/doxygen/LoopRotationUtils_8cpp_source.html#l00655


https://reviews.llvm.org/D75013

Files:
  llvm/docs/LoopTerminology.rst


Index: llvm/docs/LoopTerminology.rst
===================================================================
--- llvm/docs/LoopTerminology.rst
+++ llvm/docs/LoopTerminology.rst
@@ -155,4 +155,44 @@
 "More Canonical" Loops
 ======================
 
-TBD
+Rotated Loops
+-------------
+
+Loops are rotated by the loop-rotate pass. The purpose
+of this transformation is to convert loops into
+do/while style loops. Example:
+
+.. code-block:: C
+
+  for (int i = 0; i < n; i += 1)
+    Stmt(i)
+
+is transformed to:
+
+.. code-block:: C
+
+  int i = 0;
+  do {
+    Stmt(i);
+    i += 1;
+  } while (i < n);
+
+**Warning**: This transformation is valid only if the compiler
+can prove that the loop body will be executed at least once. Otherwise,
+it has to insert a guard which will test it at runtime. In the example
+above, that would be:
+
+.. code-block:: C
+
+  int i = 0;
+  if (n > 0) {
+    do {
+      Stmt(i);
+      i += 1;
+    } while (i < n);
+  }
+
+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`
+pass.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75013.246087.patch
Type: text/x-patch
Size: 1138 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200222/ccdc2a0e/attachment.bin>


More information about the llvm-commits mailing list