LoopUnroll doesn't seem to be in a state to handle this, and we end discovering later, when we end up with a broken dominator :(
(see https://bugs.llvm.org/show_bug.cgi?id=28103#c3)
Fixes PR28103.
Differential D32261
[LoopUnroll] Don't try to unroll non-rotated loops davide on Apr 19 2017, 5:19 PM. Authored by
Details LoopUnroll doesn't seem to be in a state to handle this, and we end discovering later, when we end up with a broken dominator :( Fixes PR28103.
Diff Detail
Event Timeline
Comment Actions I don't know if this patch makes the situation better or worse. It seems to touch on the tip of an iceberg. The underlying problem is: What can or should happen when a loop is irreducible? It the answer is "don't unroll", then this is the fix your actually looking for. Obviously this loop is irreducible since it has a retreat edge from sink to body2, but body2 does not dominate sink. I'm also curious if this loop is in the source code already or if some pass in the compiler actually generated. FWIW, unless the compiler has a problem irreducible loops should be rare. And when the user writes an irreducible loop, I think it is OK when compiler optimizations turn conservative. -Gerolf
Comment Actions
There is no "underlying problem" here. An LLVM "Loop*" always refers to a natural loop; unrolling a Loop is always a well-defined operation (unless we're dealing with something weird like indirectbr). See LoopInfo.h. Our current implementation of loop unrolling only knows how to unroll loops with exactly one latch which is a conditional branch that exits the loop, but that isn't fundamental to the algorithm. We could unroll loops with a more complicated latch, or multiple latches; it's just a matter of teaching the algorithm how to fix up the latches correctly. Comment Actions Unless I'm reading the test in the PR incorrectly (which I might) the input contains already the loop (and it's not generated by the compiler). Comment Actions Thanks for addressing my previous remarks! The change looks good to me (modulo Eli's remark regarding the check).
Your reasoning makes perfect sense to me. Michael
|