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

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 28 03:46:45 PDT 2020


Meinersbur added a comment.

In D76132#1944283 <https://reviews.llvm.org/D76132#1944283>, @Whitney wrote:

> My above example was not good. 
>  Consider this example:
>
>   for i
>     for j        <= unroll loop
>       for k
>          A[i][j][k]
>          A[i-1][j+1][k-1]
>   
>
> The dependence direction vector would be [LT, GT, LT].


This dependency vector would be an unconditional dependency violation (lexicographically negative; backwards in time)

Let's say the statements are S1 and S2.

No dependence between S1 and itself.
No dependence between S2 and itself.

S2(i2,j2,k2) depends on S1(i1,j1,k1) iff i1==i2-1(A[i1] and A[i2-1] access the same element), j1==j2+1, k1==k2-1 and (i1,j1,k1) <=_{lexicographic} (i2,j2,k2), 
in other words, the dependence vector is (+1,-1,+1) or (GT,LT,GT) [direction from S1->S2, since S1 is the source and S2 is the consumer].

For the iteration in the i-loop, S1 and S2 will never access the same element, hence we can reorder S1 and S2 within the outermost loops as we like.

> After unroll and jam loop-j:
> 
>   for i
>      for j  += 2
>        for k
>           A[i][j][k]
>           A[i-1][j+1][k-1]
>           A[i][j+1][k]
>           A[i-1][j+2][k-1]
> 
> 
> I think loop-j is safe to unroll and jam.
>  However if we only allow GT for loop-i, then this would be consider not safe.

But the dependency is strictly GT in the first element ?!?

Consider a case where the dependency in the i-loop is GE:

  for i
    for j        <= unroll loop
      for k
         A[i][j][k]
         A[c ? i : i-1][j-1][k]
  
  Here S2 conditionally accessed the element from the previous i-iteration or the same, depending on `c`. Thus the possibility of "EQ" requires us to check further.
  
  Michael


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