[PATCH] D76132: [LoopUnrollAndJam] Changed safety checks to consider more than 2-levels loop nest.

Bardia Mahjour via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 30 14:00:23 PDT 2020


bmahjour added a comment.

After a tiring search through the literature I've finally found a paper that states a theorem specifically about safety of unroll-and-jam. See //Callahan et al.  1988. Estimating Interlock And Improving Balance For Pipelined Architectures//, section 3.5, theorem 4. The theorem generally agrees with the approach of checking for lexicographical positivity, but unfortunately it doesn't say anything about cases where the direction vector elements in between  the `k` (unrolled level) and `j` (inner level carrying a negative dependence) are non-zero. Another paper, //S. Carr and K. Kennedy. 1994. Improving the Ratio of Memory operations to Floating-Point Operations in Loops// appears to interpret it as if any negative entry in the direction vector between the unrolled level and the inner-most level is not legal. I find the latter too conservative, for instance if we have:

  loop i
    loop j
      loop k
        A(i+1, j+1, k-1) = A(i, j, k)

the direction vector would be `[< < >]` and the unroll-and-jam would be legal. Checking for lexicographical positivity, as proposed in @Meinersbur 's solution, correctly identifies it as a legal case. The first paper (and others too) also suggest that unroll-and-jam can be viewed as an interchange followed by inner-loop unrolling followed by another interchange. The legality checks for interchange seem to also be overly conservative, for example in this case:

  loop i
    loop j
      A(i, j+1) = A(i, j)

After the first interchange and inner loop unrolling we get:

  loop j
    loop i
      A(i, j+1) = A(i, j)
      A(i+1, j+1) = A(i+1, j)

now there is an interchange preventing dependence from the first statement to the second with direction vector `[< >]`. We know, however that if we unrolled `i` in the original nest, there would be no fusion-preventing dependencies between the unrolled iterations at j-level, so unrol-and-jam is legal.

In conclusion, I find the lexicographical positivity test to be the most accurate and I cannot come up with a counter example that exposes a correctness bug, so I tend to agree with it more than anything else.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76132





More information about the llvm-commits mailing list