[PATCH] D68789: [LoopNest]: Analysis to discover properties of a loop nest.

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 30 09:21:24 PDT 2019


Meinersbur added inline comments.


================
Comment at: llvm/include/llvm/Analysis/LoopNestAnalysis.h:124
+  /// Return true if the loop nest is perfect and false otherwise.
+  bool isPerfect() const { return MaxPerfectDepth == getNestDepth(); }
+
----------------
etiotto wrote:
> Meinersbur wrote:
> > [discussion] I understand "perfectly nested" as a property of a set of loops. That is, in
> > ```
> >   for (int i)
> >     for (int j) {
> >       preStmt();
> >       for (int k) ...
> >       postStmt();
> >     }
> > ```
> > I'd understand the loop `i` and `j` to be a perfect loop nest. What code is in the body does not matter.
> Correct. In your example loops i and j are perfectly nested with respect to each other. Loop j and k on the other hand are not perfectly nested because of the present of stmts between the loops. The entire loop nest is imperfect because of that.
> 
> So the isPerfect member function returns true if and only if any adjacent pair of loops in the nest are perfectly nested with respect to each other (not only the othermost 2 loops). That is the only loop containing user code is the innermost loop. 
I am arguing that we should remove `isPerfect` entirely and replace by something that returns the maximum perfect loop nest depth. To avoid a difference whether in
```
for (int i)
  for (int j) {
    OutlinedBody(i,j);
  }
```
the function `OutlinedBody` is inlined or not.

Also, since this is a loop analysis, there should be a function determining whether the currently analyzed loop is the outermost loop nest. A loop pass could use this to skip optimizing a loop of depth 2 when when including another outer loop it could optimize a loop nest depth of 3 (since the order of optimization is determined by the LoopPassManager and can be arbitrary).


Repository:
  rL LLVM

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

https://reviews.llvm.org/D68789





More information about the llvm-commits mailing list