InnerLoopVectorizer shouldn't handle a loop with cycles inside the loop
body, even if that cycle isn't a natural loop.
Fixes PR28541.
Differential D22952
[LoopVectorize] Detect loops in the innermost loop before creating InnerLoopVectorizer timshen on Jul 28 2016, 6:44 PM. Authored by
Details InnerLoopVectorizer shouldn't handle a loop with cycles inside the loop Fixes PR28541.
Diff Detail
Event Timeline
Comment Actions Where this check should be is related to PR28374. I think it should be checked when we initially gather the inner most loops in addInnerLoop.
Comment Actions I'm not sure. I mean, both ways make sense, but the way I see it is the inner-most "loop", in the sense that there are no loops (as opposed to cycles) living inside it. So adding it, and then performing a legality check makes sense to me. Comment Actions I guess it all depends on whether you think these checks are similar or not. I don't really see the difference between loops and cycles. For example, when I look at the testcase in C, I essentially see two nested loops even though the inner one is a bit weird (I guess it's multi-entry). I am not sure that it make sense to differentiate the two to the user either. Thus I'd like to have a single place where we check for the inner-most loop property (with LoopInfo and beyond) and where we properly report back to the user. This is currently addInnerLoop. (The other place is dead before the patch, AFAICT.) Comment Actions At a somewhat fundamental level, LLVM uses the term "loop" to mean "natural loop", and not any arbitrary cycle. Similarly, throughout LoopInfo and the loop pass manager we model "inner loop" as the innermost natural loop, regardless of whether there are cycles nested within it. So while I don't have a really strong opinion about how the vectorizer is factored (I don't really work on it) I would expect an LLVM API spelled "addInnerLoop" to mean "add inner natural loop" and not "add inner cycle which happens to be a natural loop" or "add inner loop that doesn't contain a cycle". It is possible we could work to change LLVM's terminology, but I think that'd be a pretty big shift. So, if you want to filter these things in "addInnerLoop" I'd suggest trying to find a more precise name. Comment Actions Sure, I would be certainly OK changing the name if that is misleading. I look at this more from the POV of which one is conservatively more correct? I think that in addInnerLoop, adding a loop that actually has another non-natural loop nested is more error-prone than not. I actually believe that we have other (inner-most) loop optimizations that have the same bug as the vectorizer that use a similar code to enumerate inner-most loops. Thus it would probably be better to have a central utility that gives you natural loops that are guaranteed to have an acyclic body (whatever the name is), i.e. inner-most in the most conservative sense. Comment Actions
Maybe we can do this in another patch, and have an exhaustive discussion there? I moved hasCycleInLoopBody out, so that the intended change to addInnerLoop is one-line. Comment Actions The LV change LGTM, although if anemet strongly prefers to move this out of the legality check, and into addInnerLoop, I can live with that. I really don't know enough about graph traits to pass judgement on that. One thing I can say is that I have the nagging suspicion LoopBodyTraits should live somewhere closer to LoopInfo, and not in LoopVectorizer.cpp.
Comment Actions Thanks, Michael. Yes, that would be my preference. We need to change the name though to avoid the ambiguity with loop <-> natural loop. AddLoopWithAcyclicBody?
This is new to me too but looks pretty interesting so will stare at it more tomorrow.
Comment Actions Updated comments for LoopBodyTraits.
Comment Actions Yes, the PR is a 3.9 blocker. There's no immediate rush, I'm just trying to make sure things keep moving along :-)
Comment Actions LGTM with the change below.
|