[PATCH] D22630: Loop rotation
Aditya Kumar via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 19 15:58:48 PDT 2016
hiraditya added a comment.
In https://reviews.llvm.org/D22630#574886, @mzolotukhin wrote:
> > Essentially, if the header and latch both are exiting, the loop will not rotate (as per your suggestion).
> Can you please explain why we need to rotate those loops? Then we can figure out heuristics that we can use here.
We need to rotate loops because of two reasons:
1. To make the loop in a canonical form.
2. To expose redundancies by cloning the basic blocks which are exiting out of the loop.
- If we add the check that (when a loop latch is exiting then don't rotate the loop), then the computations like load in all the basic blocks which are exiting the loop, except header cannot PRE'd.
- Even if a loop is in canonical form, we may still want to rotate it to expose redundancies.
>> The vectorizer already tags loops with metadata, so I assumed having it here should have been okay.
> The vectorizer is a different beast. When we vectorize a loop, we usually don't want other passes to touch it afterwards at all. That's why we use metadata, we kind of say "this loop is as good as we can get, leave it alone".
> In case of loop-rotation it's not the case - we are not sure that the loop is in the best position even in terms of rotation after one iteration of loop-rotate. Using metadata to avoid further rotation seems like an attempt to paper over a real problem, i.e. finding the best candidate for the bottom check for the loop versus trying to get lucky with that.
> When I suggested to rotate only loops that have not-exiting latch, that was my attempt to create a heuristics to find that 'best candidate' for the bottom check. Your testing shows that it's not good enough, so my question is what cases this heuristics misses. Probably we just need to take into account some additional characteristics of the loop and it'll work just fine.
I think putting a set of heuristics is not going to help because that way redundancies cannot be exposed in loops which appear to the loop rotation as rotated.
I can just remove/disable those test cases for now and may be improve on those test cases later.
More information about the llvm-commits