This is an archive of the discontinued LLVM Phabricator instance.

Search for all predecessors of loop header while getting loop metadata
Needs ReviewPublic

Authored by hiraditya on Sep 22 2016, 12:58 PM.

Details

Summary

The current implementation of getLoopID seems incorrect as it returns nullptr only after looking into the successors of first block in the loop.
In the setLoopID, there is no need to iterate over all the basic blocks of loop as loop metadata is only associated with predecessor (s) of loop header.

Diff Detail

Event Timeline

hiraditya updated this revision to Diff 72203.Sep 22 2016, 12:58 PM
hiraditya retitled this revision from to Search for all predecessors of loop header while getting loop metadata.
hiraditya updated this object.
hiraditya added reviewers: paul.redmond, sanjoy, sebpop.
hiraditya added a subscriber: llvm-commits.
mzolotukhin added inline comments.Oct 11 2016, 3:18 PM
llvm/lib/Analysis/LoopInfo.cpp
216–224

This comment is stale now.

249

Are you sure that we cannot have multiple branches? I think it's true for well-formed loops, but might be incorrect in a general case.

hiraditya added inline comments.Oct 12 2016, 8:08 AM
llvm/lib/Analysis/LoopInfo.cpp
249

I'll remove this assert. THanks,

hiraditya updated this revision to Diff 74396.Oct 12 2016, 9:28 AM

Addressed Michael's comments.

mzolotukhin added inline comments.Oct 12 2016, 12:09 PM
llvm/lib/Analysis/LoopInfo.cpp
214–215

AFAIU, this->contains would be as expensive, as iterating through all blocks (as we did in the original version). Moreover, now we'll do it several times while in the original code we did that only once. Are you sure it's worth it?

The issue you mentioned - getLoopID returns nullptr only after looking into the successors of the first block in the loop - still looks relevant though, so some fix is indeed needed.

244–245

Same question about the cost of this->contains versus original iterating over all blocks.

hiraditya added inline comments.Oct 19 2016, 10:41 AM
llvm/lib/Analysis/LoopInfo.cpp
214–215

AFAIU, this->contains would be as expensive, as iterating through all blocks

Only for loops with few basic blocks, because DenseBlockSet is a SmallPtrSet, whereas in the previous implementation it would iterate through all the basic blocks and all the successors of each BB in the loop.

spatel resigned from this revision.Sep 26 2017, 3:54 PM
sanjoy resigned from this revision.Jan 29 2022, 5:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 29 2022, 5:36 PM