This is an archive of the discontinued LLVM Phabricator instance.

[PM] Teach the LoopPassManager to automatically canonicalize loops by runnig LCSSA over them prior to running the loop pipeline.
ClosedPublic

Authored by chandlerc on Jan 15 2017, 1:50 AM.

Details

Summary

This also teaches the loop PM to verify that LCSSA form is preserved
throughout the pipeline's run across the loop nest.

Most of the test updates just leverage this new functionality. One has to be
relaxed with the new PM as IVUsers is less powerful when it sees LCSSA input.

Event Timeline

chandlerc updated this revision to Diff 84486.Jan 15 2017, 1:50 AM
chandlerc retitled this revision from to [PM] Teach the LoopPassManager to automatically canonicalize loops by runnig LCSSA over them prior to running the loop pipeline..
chandlerc updated this object.
chandlerc added a subscriber: llvm-commits.
davide added a subscriber: davide.Jan 15 2017, 2:07 AM
davide added inline comments.
include/llvm/Transforms/Scalar/LoopPassManager.h
315–317

These two can be a bit expensive. Maybe put them under #ifndef NDEBUG ?

sepavloff added inline comments.
include/llvm/Transforms/Scalar/LoopPassManager.h
315–317

In D28676 the same problem were solved by making VerifyLoopInfo global and running expensive checks only if -verify-loop-info is specified in command line. Maybe that change can be useful here?

davide added inline comments.Jan 16 2017, 12:33 AM
include/llvm/Transforms/Scalar/LoopPassManager.h
315–317

Maybe, eventually. But until all the bugs in the new PM are shaken properly my preference would be to run this check unconditionally for debug builds. (note, we do something similar for NewGVN and it revealed quite a few bugs, and these checks can be always be moved to LLVM_ENABLE_EXPENSIVE_CHECKS once we're satisfied with things and/or we think running the verification by default is crazy expensive).

davide added inline comments.Jan 16 2017, 12:38 AM
test/Analysis/IVUsers/quadradic-exit-value.ll
8

Why two prefixes here?

chandlerc marked 3 inline comments as done.Jan 16 2017, 5:37 PM
chandlerc added inline comments.
include/llvm/Transforms/Scalar/LoopPassManager.h
315–317

Agreed on all counts. Eventually we can turn this down, but for now I'd like to be aggressive.

test/Analysis/IVUsers/quadradic-exit-value.ll
8

Below, we only use the one prefix.

Without LCSSA, we get substantially more precise results here, whereas with it we get substantially more poor results. This is because of a combined weakness of SCEV and IVUsers which stems from SCEVExpander's inability to expand correctly in LCSSA form. =[ It's a mess.

I've talked to Michael (K) and Sanjoy about this and we have some ideas to fix this eventually, but not right away. (Fortunately, the only thing that cares today is LSR which is in the codegen phase and so not blocking anything.)

I wrote the FIXME above this to document what is going on here.

davide accepted this revision.Jan 16 2017, 5:41 PM

LGTM. I'm still in favour of having the LCSSA verification enabled *only* for debug builds, but if you want to have that unconditionally (i.e. also for release, for now), fair enough. Worst case we'll get terribly annoyed by the long compile times and disable it =)

This revision is now accepted and ready to land.Jan 16 2017, 5:41 PM
chandlerc updated this revision to Diff 84617.Jan 16 2017, 5:43 PM
chandlerc marked an inline comment as done.

Update addressing code review comments and cleaning things up.

Some minor comments , but I think this is good to go. I'll review the other related patch soon'ish.

include/llvm/Transforms/Scalar/LoopPassManager.h
52–54

Nit: unsorted (IR < Transforms)

test/Analysis/IVUsers/quadradic-exit-value.ll
8

Oh, sorry, I missed the fixme. Ignore my comment.

This revision was automatically updated to reflect the committed changes.
chandlerc marked an inline comment as done.