This is an archive of the discontinued LLVM Phabricator instance.

[LoopVectorize] Preserve CFG analyses if CFG wasn't modified
ClosedPublic

Authored by mkazantsev on Apr 17 2020, 5:07 AM.

Details

Summary

One of transforms the loop vectorizer makes is LCSSA formation. In some cases it
is the only transform it makes. We should not drop CFG analyzes if only LCSSA was
formed and no actual CFG changes was made.

We should think of expanding this logic to other passes as well, and maybe make
it a part of PM framework.

Diff Detail

Event Timeline

mkazantsev created this revision.Apr 17 2020, 5:07 AM
mkazantsev edited the summary of this revision. (Show Details)Apr 17 2020, 5:08 AM

I'd view it as a PoC for more general change; it seems that LV is not the only pass that drops analyzes because of transforms that should not lead to it. But until it's framed properly, we can go with a local solution.

fhahn added a comment.Apr 17 2020, 6:31 AM

I'd view it as a PoC for more general change; it seems that LV is not the only pass that drops analyzes because of transforms that should not lead to it. But until it's framed properly, we can go with a local solution.

Great to see work being done in that direction, thanks! Do you think it would be possible to add a test case with a loop that cannot be vectorized but it adds an LCSSA PHI and check the pass manager output to ensure it preserves a CFG analysis (besides DT which already is preserved)?

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
7995

It might simplifies things a bit if we would just let CFGChanged imply Changed.

mkazantsev marked an inline comment as done.Apr 19 2020, 6:25 PM

I'd view it as a PoC for more general change; it seems that LV is not the only pass that drops analyzes because of transforms that should not lead to it. But until it's framed properly, we can go with a local solution.

Great to see work being done in that direction, thanks! Do you think it would be possible to add a test case with a loop that cannot be vectorized but it adds an LCSSA PHI and check the pass manager output to ensure it preserves a CFG analysis (besides DT which already is preserved)?

I'll try.

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
7995

What exactly are you suggesting?

Added test.

fhahn accepted this revision.Apr 22 2020, 4:12 AM

LGTM, thanks!

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
7995

you could use Changed || CFGChanged to set Changed in LoopVectorizeResult I think, rather than having Changed |= CFGChanged |= .... in multiple places. Just a nit.

This revision is now accepted and ready to land.Apr 22 2020, 4:12 AM
mkazantsev marked an inline comment as done.Apr 24 2020, 2:16 AM
mkazantsev added inline comments.
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
7995

I don't really think it's a good idea, because in this case Changed would need a better name; we cannot just set CFGChanged at some point and not set Changed, the reader may think that this transform *only* changes CFG, which might be not true.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2020, 3:45 AM