What is the benefit of merging them? LoopSimplify is certainly useful without LCSSA, and LCSSA is certainly useful without LoopSimplify's canonicalization. Also, and I don't know if this matters, but LoopSimplify can "fail" (for non-natural loops, at least), LCSSA cannot fail.
Do you have any measurement of this? I have no evidence that LCSSA is a remotely significant optimization time cost, but I've not gone looking.
Ok, I think this would be the more serious issue if it comes up in practice. I don't have any cases where it comes up in practice for early loop opts either though.
<snip>
LICM. There is already a fast path in LICM that is the exact path that LCSSA guarantees exists when sinking code into the exit blocks. The only thing missing is for LICM to actually *use* LCSSA instead of just trying to patch it up if it happens to find it in the loop. I think it would dramatically simplify the entire sinking code.
A good use of SSAUpdater: re-forming SSA values *within* a loop body due to mem2reg essentially. LICM has a little mini mem2reg pass in it that uses SSAUpdater. This is a great use and I can't imagine something simpler. The fact that we have LCSSA also makes it faster by bounding the space where it has to rewrite uses (to the edge of the current loop).
But if we have LCSSA, we should never need SSAUpdater for updating SSA form across the loop boundary in the way LICM does. Instead we should be able to place an instruction, RAUW it, and insert a PHI node for each operand. Done.Maybe a patch would be better to explain matters? As it happens, fixing LICM this way will also fix PR18753 and a host of other latent bugs where LICM invalidates LCSSA in some far-off loop and we crash later.
On Feb 1, 2014, at 4:33 AM, Chandler Carruth <chan...@gmail.com> wrote:It’s worth noting that LCSSA predates SSAUpdater. If I went back in time and knew what I knew now, I wouldn’t have gone with LCSSA.
> So, there are two primary ideas behind SSA form management in the loop optimizers of LLVM:
>
> - Require LCSSA form input, leverage its (very powerful) guarantees to simplify maintaining SSA form, and also maintain LCSSA form.
>
> - Don't bother with LCSSA form input, assume the worst, and use powerful incremental SSA formation utilities built on SSAUpdater to form SSA on demand when needed.
>
> (Note, there are plenty of places where SSAUpdater makes sense, so this isn't really about doing away with it at all.)
My gripes are three fold:
1) SSAUpdater can handle anything that LCSSA simplifies
2) that LCSSA is annoying to keep up to date
3) LCSSA burns compile time optimistically rewriting loop values, which are then later collapsed away even if nothing cares about those values.
My personal preference would be to get rid of LCSSA completely, but I don’t know how to stage that.
On Feb 7, 2014, at 12:05 PM, Andrew Trick <atr...@apple.com> wrote:
>>> (Note, there are plenty of places where SSAUpdater makes sense, so this isn't really about doing away with it at all.)
>>
>> It’s worth noting that LCSSA predates SSAUpdater. If I went back in time and knew what I knew now, I wouldn’t have gone with LCSSA.
>>
>> My gripes are three fold: 1) SSAUpdater can handle anything that LCSSA simplifies, 2) that LCSSA is annoying to keep up to date, 3) LCSSA burns compile time optimistically rewriting loop values, which are then later collapsed away even if nothing cares about those values.
>>
>> My personal preference would be to get rid of LCSSA completely, but I don’t know how to stage that.
>
> Until recently I felt exactly the same way. I didn’t want LCSSA just as another mechanism for updating SSA.
>
> I’m warming up to having it run during the early loop passes if it
> - significantly simplifies the LICM logic
> - greatly speeds up SSAUpdater within loops (maybe little net compile-time increase on average?)
> - compartmentalizes loop transforms and SSA update so we can debug loop opts one loop at a time
>
> I still don’t particularly like that we force all LLVM clients to perform LCSSA when all they end up doing is rotating and simplifying loops (no LICM/unroll). So it is a tradeoff.
I don't have a strong opinion here, just throwing out some thoughts. You've been working on the loop passes much more recently, so if you think it is worth holding on to (or worth using just for the early passes?) then go for it.
On Sat, Feb 8, 2014 at 2:36 PM, Chris Lattner <clat...@apple.com> wrote:
On Feb 7, 2014, at 12:05 PM, Andrew Trick <atr...@apple.com> wrote:
>>> (Note, there are plenty of places where SSAUpdater makes sense, so this isn't really about doing away with it at all.)
>>
>> It’s worth noting that LCSSA predates SSAUpdater. If I went back in time and knew what I knew now, I wouldn’t have gone with LCSSA.
>>
>> My gripes are three fold: 1) SSAUpdater can handle anything that LCSSA simplifies, 2) that LCSSA is annoying to keep up to date, 3) LCSSA burns compile time optimistically rewriting loop values, which are then later collapsed away even if nothing cares about those values.
>>
>> My personal preference would be to get rid of LCSSA completely, but I don’t know how to stage that.
>
> Until recently I felt exactly the same way. I didn’t want LCSSA just as another mechanism for updating SSA.
>
> I’m warming up to having it run during the early loop passes if it
> - significantly simplifies the LICM logicI've committed this in r201148 in order to fix several PRs. We can of course back it out and go down a different path if that's the end decision, but it seems better to not have asserts in the interim. =]
> I still don’t particularly like that we force all LLVM clients to perform LCSSA when all they end up doing is rotating and simplifying loops (no LICM/unroll). So it is a tradeoff.Again, LoopSimplify does not require LCSSA today. Nothing to do there. If we folded rotate into simplify (which we should probably do) then we would be done.
On Fri, Feb 7, 2014 at 11:29 AM, Chris Lattner <clat...@apple.com> wrote:
On Feb 1, 2014, at 4:33 AM, Chandler Carruth <chan...@gmail.com> wrote:It’s worth noting that LCSSA predates SSAUpdater. If I went back in time and knew what I knew now, I wouldn’t have gone with LCSSA.
> So, there are two primary ideas behind SSA form management in the loop optimizers of LLVM:
>
> - Require LCSSA form input, leverage its (very powerful) guarantees to simplify maintaining SSA form, and also maintain LCSSA form.
>
> - Don't bother with LCSSA form input, assume the worst, and use powerful incremental SSA formation utilities built on SSAUpdater to form SSA on demand when needed.
>
> (Note, there are plenty of places where SSAUpdater makes sense, so this isn't really about doing away with it at all.)
My gripes are three fold:1) SSAUpdater can handle anything that LCSSA simplifies
Yes, it can, but it is *significantly* less simple. I think the simplicity of reasoning and handling things with LCSSA is not without value.