This is an archive of the discontinued LLVM Phabricator instance.

[LoopUnroll] Properly update loop-info when cloning prologues and epilogues.
ClosedPublic

Authored by mzolotukhin on Sep 2 2016, 1:05 PM.

Details

Summary

When cloning blocks for prologue/epilogue we need to replicate the loop
structure from the original loop. It wasn't a problem for the innermost
loops, but it led to an incorrect loop info when we unrolled a loop with
a child loop - in this case created prologue-loop had a child loop, but
loop info didn't reflect that.

This fixes PR28888.

Diff Detail

Repository
rL LLVM

Event Timeline

mzolotukhin updated this revision to Diff 70213.Sep 2 2016, 1:05 PM
mzolotukhin retitled this revision from to [LoopUnroll] Properly update loop-info when cloning prologues and epilogues..
mzolotukhin updated this object.
mzolotukhin added reviewers: chandlerc, sanjoy, hfinkel.
mzolotukhin added subscribers: silvas, llvm-commits.

Hi Michael,

The fix is good. I have some suggestions in inline comments.

Thanks,
Evgeny

lib/Transforms/Utils/LoopUnrollRuntime.cpp
306 ↗(On Diff #70213)

Since
line 632: LoopBlocksDFS LoopBlocks(L);
Is there a case when LI->getLoopFor(*BB) is not L?

309 ↗(On Diff #70213)

Should be simplified to just:
if (CreateRemainderLoop) {

evstupac added inline comments.Sep 7 2016, 3:33 PM
lib/Transforms/Utils/LoopUnrollRuntime.cpp
306 ↗(On Diff #70213)

I see when we clone loop nest.
Please ignore this.

chandlerc accepted this revision.Sep 7 2016, 4:33 PM
chandlerc edited edge metadata.

Really nice. LGTM with straight forward comments / refactorings below.

lib/Transforms/Utils/LoopUnrollRuntime.cpp
307–309 ↗(On Diff #70213)

Factoring this into a helper or a lambda would make it more readable IMO because you could use early returns.

This revision is now accepted and ready to land.Sep 7 2016, 4:33 PM

Thanks for the review! I'll commit it soon.

Michael

lib/Transforms/Utils/LoopUnrollRuntime.cpp
307–309 ↗(On Diff #70213)

That's a good idea. I'll see if it makes the code better before I commit.

309 ↗(On Diff #70213)

I assume that this comment can also be ignored now, but I'll expand on this just in case.

If we unroll a loop with inner loops, then even if the remainder is not a loop itself, it will contain cloned inner loops. This check catches exactly this case: if the block BB belongs not to the L (but to some of its children), then we'll need to create cloned version of this inner loop in the remainder.

This revision was automatically updated to reflect the committed changes.