This is an archive of the discontinued LLVM Phabricator instance.

[OPENMP] llvm.loop.vectorize.enable metadata are lost after critical edge splitting
AbandonedPublic

Authored by zinovy.nis on Sep 30 2014, 5:57 AM.

Details

Reviewers
atrick
hfinkel
Summary

Critical edge splitting called by GVN and Loop Rotation leads to losing of llvm.loop.vectorize.enable metadata for loops as critical edge splitting replaces a branch, corresponding to the loop latch, with a new one.

My patch clones loop latch metadata to a new latch branch thus fixing the issue.

I also had to add LoopInfo analysis for GVN, as it's needed for latch metadata cloning.

Diff Detail

Event Timeline

zinovy.nis updated this revision to Diff 14216.Sep 30 2014, 5:57 AM
zinovy.nis retitled this revision from to [OPENMP] llvm.loop.vectorize.enable metadata are lost after critical edge splitting.
zinovy.nis updated this object.
zinovy.nis edited the test plan for this revision. (Show Details)
zinovy.nis added reviewers: chandlerc, atrick.
zinovy.nis set the repository for this revision to rL LLVM.
zinovy.nis added a subscriber: Unknown Object (MLST).
zinovy.nis updated this object.Sep 30 2014, 6:02 AM

I'm not completely sure but this sounds similar to what I did a couple
of weeks ago (http://reviews.llvm.org/D5344) however I didn't force
LoopInfo to be present but rather handled the case it isn't. For the
record, I don't know the benefits/drawbacks for either.

If we use your patch we could possibly add my test cases.

@jdoerfert, looks you are right, our patches are similar. But seems that your patch will not work when edge splitting is called from GVN, as currently LoopInfo analysis for GVN is not turned on. Is it so?

Correct, GVN is not a "definitive" user of LoopInfo, thus running GVN and critical edge splitting will remove the loop annotations, however that behaviour is at least well defined. In contrast calling BreakCriticalEdges from another "non LoopInfo user pass" might result in invalid loop annotations in your patch.

If we never want to remove metadata information we shouldn't add LoopInfo to the passes GVN needs, but to the passes BreakCriticalEdges needs. That way we can always rely on LoopInfo to "do the right thing" in BreakCriticalEdges without the need to remove annotations for the lack of information.

zinovy.nis added a comment.EditedSep 30 2014, 6:57 AM

OK, if we agree to add AU.addRequired<LoopInfo>(); for BreakCriticalEdges while removing it from GVN I'd be satisfied.

UPD. Sorry, it will not help as GVN doesn't call BreakCriticalEdges pass directly, but just calls a method from BreakCriticalEdges.cpp

OK, if we agree to add AU.addRequired<LoopInfo>(); for BreakCriticalEdges while removing it from GVN I'd be satisfied.

UPD. Sorry, it will not help as GVN doesn't call BreakCriticalEdges pass directly, but just calls a method from BreakCriticalEdges.cpp

Yeah, I just saw that too. So you need to add LoopInfo to the passes GVN needs as long as it calls the SplitCriticalEdge directly.

Yes, I had to do that.

atrick edited edge metadata.Sep 30 2014, 9:25 AM

If the problem here is that GVN is dropping the loop.vectortize metadata, adding LoopInfo as a required pass seems fundamentally wrong. Critical edge splitting is supposed to be something any pass can do on-the-fly without extra analysis. Of course, the whole problem would have been simpler if we just required annotated loops to have split edges to begin with, but that issue is out-of-scope for this bug.

I have some basic questions:

  • I haven't been paying close attention to the loop.vectorize metadata design. Why does it need to be on the loop backedge branch? It doesn't seem hard to discover the metadata on the last conditional branch leading to the backedge.
  • Even if you do need to move the metadata to a different branch, why is LoopInfo required? Is it because we can't tell if we're splitting the backedge or the loop exit? DomTree would often be sufficient to tell them apart.
In D5539#13, @atrick wrote:

If the problem here is that GVN is dropping the loop.vectortize metadata, adding LoopInfo as a required pass seems fundamentally wrong. Critical edge splitting is supposed to be something any pass can do on-the-fly without extra analysis. Of course, the whole problem would have been simpler if we just required annotated loops to have split edges to begin with, but that issue is out-of-scope for this bug.

GVN (and other transformations) use the static SplitCiticalEdge function instead of the BreakCriticalEdges pass. This function does rely on the Pass * argument to get LoopInfo and the DomTreeWrapperPass to update information. However, loop metadata isn't considered so far. Both patches try to fix that issue.

I have some basic questions:

  • I haven't been paying close attention to the loop.vectorize metadata design. Why does it need to be on the loop backedge branch? It doesn't seem hard to discover the metadata on the last conditional branch leading to the backedge.

I cannot help you here, I don't know why it is designed like this.

  • Even if you do need to move the metadata to a different branch, why is LoopInfo required? Is it because we can't tell if we're splitting the backedge or the loop exit? DomTree would often be sufficient to tell them apart.

Even if we would rely on the DomTree instead of the LoopInfo we have the same problems.

  1. Either musst be available over the Pass * argument of SplitCriticalEdges
  2. The SplitCriticlEdges need to be patched to use the available pass in order to preserve the loop metadata.
  3. We need to invalidate the metadata instead of making it invalid.

Is it incorrect to leave the loop metadata on the original branch when splitting the edge?

GVN already requires DomTree, so no change to the pipeline is needed if you use it.

In splitCriticalEdges, if LoopInfo is available you can use it. Otherwise you can use the DomTree. If the DomTree check fails (ie. both targets dominate the latch) then just invalidate the metadata.

I think there is a fundamental problem with the metadata design--it's ridiculous to assume that any pass that splits critical edges has LoopInfo--but that should at least workaround your problem.

  • Original Message -----

From: "Andrew Trick" <atrick@apple.com>
To: "zinovy nis" <zinovy.nis@gmail.com>, chandlerc@gmail.com, atrick@apple.com
Cc: llvm-commits@cs.uiuc.edu
Sent: Tuesday, September 30, 2014 4:29:08 PM
Subject: Re: [PATCH] [OPENMP] llvm.loop.vectorize.enable metadata are lost after critical edge splitting

Is it incorrect to leave the loop metadata on the original branch
when splitting the edge?

GVN already requires DomTree, so no change to the pipeline is needed
if you use it.

In splitCriticalEdges, if LoopInfo is available you can use it.
Otherwise you can use the DomTree. If the DomTree check fails (ie.
both targets dominate the latch) then just invalidate the metadata.

I think there is a fundamental problem with the metadata design--it's
ridiculous to assume that any pass that splits critical edges has
LoopInfo--but that should at least workaround your problem.

Is that a flaw in the design of the metadata, or just in the fact that the utility functions used to manipulate the metadata are part of LoopInfo?

-Hal

http://reviews.llvm.org/D5539


llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

In D5539#16, @hfinkel wrote:
  • Original Message -----

From: "Andrew Trick" <atrick@apple.com>
To: "zinovy nis" <zinovy.nis@gmail.com>, chandlerc@gmail.com, atrick@apple.com
Cc: llvm-commits@cs.uiuc.edu
Sent: Tuesday, September 30, 2014 4:29:08 PM
Subject: Re: [PATCH] [OPENMP] llvm.loop.vectorize.enable metadata are lost after critical edge splitting

Is it incorrect to leave the loop metadata on the original branch
when splitting the edge?

GVN already requires DomTree, so no change to the pipeline is needed
if you use it.

In splitCriticalEdges, if LoopInfo is available you can use it.
Otherwise you can use the DomTree. If the DomTree check fails (ie.
both targets dominate the latch) then just invalidate the metadata.

I think there is a fundamental problem with the metadata design--it's
ridiculous to assume that any pass that splits critical edges has
LoopInfo--but that should at least workaround your problem.

Is that a flaw in the design of the metadata, or just in the fact that the utility functions used to manipulate the metadata are part of LoopInfo?

-Hal

In my opininion the real probelem is the static SplitCriticalEdge function which is called with a black box Pass * instead of the two analysis passes it could actually use to update information.
It is intransparent to the user what passes should be provided to ensure the best result.

The "utility functions to manipulate the metadata" are actually only available in this and the other pending patch http://reviews.llvm.org/D5344 and both currently use LoopInfo. However, we could update them to handle metadata also with the DomTree. In any case the other patch already invalidates metadata if no analysis is present.

In D5539#15, @atrick wrote:

Is it incorrect to leave the loop metadata on the original branch when splitting the edge?

Yes, sometimes. At least if you considere llvm.loop metadata on non loop backedges to be invalid.

GVN already requires DomTree, so no change to the pipeline is needed if you use it.

We could implement the handling of metadata for both cases, if DomTree or LoopInfo are accessable via the Pass * given, then we do not need to change GVN.

In splitCriticalEdges, if LoopInfo is available you can use it. Otherwise you can use the DomTree. If the DomTree check fails (ie. both targets dominate the latch) then just invalidate the metadata.

I could update my patch if we decide to go this way. It would probably require the least change outside the actual SplitCriticalEdge function.

I think there is a fundamental problem with the metadata design--it's ridiculous to assume that any pass that splits critical edges has LoopInfo--but that should at least workaround your problem.

True, but some analysis is needed in order to preserve the metadata in a meaningful way and we always can invalide it as a fallback.

chandlerc resigned from this revision.Mar 29 2015, 1:40 PM
chandlerc edited reviewers, added: hfinkel; removed: chandlerc.

Leaving this review to Andy and Hal as they have abetter understanding of the issues around the loop metadata.

One thing I'll note -- it really does seem bad to require LoopInfo here....

Err, shouldn't loopinfo just be preserved here rather than required, like BreakCriticalEdges does?
If llvm.loop.vectorize.enable is considered part of the loopinfo pass, adding it as preserved and updating it if available, should have zero cost, unlike making it required.

SplitCriticalEdge already can take LoopInfo as an option nowadays, (see Options.LI), so you don't need to add it again. SplitCriticalEdge is already using it to maintain loopsimplify form. You should just update it if it's around

zinovy.nis abandoned this revision.Apr 1 2015, 7:36 AM