Loops should be rotated only once. Passes regression test and llvm test-suite.
Patch wrote by Aditya Kumar and Sebastian Pop.
Differential D21237
LoopRotation: remove iterative calls to rotateLoops sebpop on Jun 10 2016, 12:36 PM. Authored by
Details
Diff Detail Event TimelineComment Actions As the code is written, the function rotateLoop only execute once. // Rotate if either the loop latch does *not* exit the loop, or if the loop // latch was just simplified. if (L->isLoopExiting(OrigLatch) && !SimplifiedLatch) return false; Furthermore a testcase that contains more than 1 loop exit does not get rotated correctly: only the first condition gets rotated. void foo (int *p, int a, int b) { while (a % b && b / a) { *p = a++; p++; } } We are working on fixing the rotation of this loop in a separate patch. Comment Actions @sanjoy: yeah, that's my patch D20181. I missed your LGTM, so I haven't committed it though. @sebpop: it's interesting, I'm working on that too actually. How do you plan to handle that and how far have you progressed with it? I hope to get something working soonish. @dberlin: it's kind of a cleanup. We don't call it more than once anyway, so this is just unnecessary complication in the code. Comment Actions @mzolotukhin, yeah, i was added as a reviewer, but had no context, so just Comment Actions Thanks for your patch: it looks similar, so you have one more LGTM ;-) We haven't got very far: we just have seen this oddity today. Comment Actions I committed D20181 in r272439.
Yeah, these clean-ups are always getting in the way. I really think we should improve LoopSimplifyCFG and introduce LoopInstSimplify that would take care of that (I have that on my todo list, but I'm not sure if I can make it in a near future).
Right, my idea was to make loop-rotation more generic, thus enabling it on more complicated loops. It has some interesting corner cases though: for instance you can end up with several nested loops after rotating a single loop, but that's details, which we'll figure out in the process:) Comment Actions
I discussed about this with Aditya, and we think that a better idea is llvm-commits mailing list Comment Actions Can you please elaborate how jump-threading can handle loop-rotation? Are you talking about some particular case, or in general? Michael Comment Actions In general, loop rotation is just "split the header block into two versions", which is precisely the sort of transform jump threading does. Actually, the only reason JumpThreading doesn't rotate loops at the moment is that it's explicitly suppressed for loop headers. Comment Actions Of course loop rotation and jump threading are both forms of tail-duplication. So what! That doesn't mean they should be the same pass. These things are done for different reasons. Loop rotation's job is to put loops into a canonical form for the sake of all other downstream loop passes. When two passes share common transformations, they should share a utility. They should not be combined into one pass unless they It is very likely that LLVM clients who care about compile time will run -loop-rotate, and not -jump-threading. Comment Actions I stand corrected: loop-rotation and jump-thread should remain in separate passes. Maybe we can improve the current code by using the same code generation functionality: |