Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit e53b49a

Browse files
author
Michael Zolotukhin
committed
Revert "[LoopUnroll] Properly update loop-info when cloning prologues and epilogues."
This reverts commit r280901. This caused a bunch of failures, reverting it until I investigate them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280905 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d9fa490 commit e53b49a

File tree

2 files changed

+11
-98
lines changed

2 files changed

+11
-98
lines changed

lib/Transforms/Utils/LoopUnrollRuntime.cpp

Lines changed: 11 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -291,68 +291,26 @@ static void CloneLoopBlocks(Loop *L, Value *NewIter,
291291
Function *F = Header->getParent();
292292
LoopBlocksDFS::RPOIterator BlockBegin = LoopBlocks.beginRPO();
293293
LoopBlocksDFS::RPOIterator BlockEnd = LoopBlocks.endRPO();
294+
Loop *NewLoop = nullptr;
294295
Loop *ParentLoop = L->getParentLoop();
295-
296-
// The map from original loops to their cloned copies.
297-
SmallDenseMap<const Loop *, Loop *, 4> NewLoops;
296+
if (CreateRemainderLoop) {
297+
NewLoop = new Loop();
298+
if (ParentLoop)
299+
ParentLoop->addChildLoop(NewLoop);
300+
else
301+
LI->addTopLevelLoop(NewLoop);
302+
}
298303

299304
// For each block in the original loop, create a new copy,
300305
// and update the value map with the newly created values.
301306
for (LoopBlocksDFS::RPOIterator BB = BlockBegin; BB != BlockEnd; ++BB) {
302307
BasicBlock *NewBB = CloneBasicBlock(*BB, VMap, "." + suffix, F);
303308
NewBlocks.push_back(NewBB);
304309

305-
// Figure out which loop NewBB is in.
306-
auto findClonedLoop = [&](const Loop *OldLoop) {
307-
Loop *&NewLoop = NewLoops[OldLoop];
308-
// If we've encountered this loop before, return it right away.
309-
if (NewLoop)
310-
return NewLoop;
311-
312-
// If BB is from L, and we're not creating a remainder, the loop for
313-
// NewBB will be ParentLoop, which might be null. Update NewLoops map and
314-
// return ParentLoop.
315-
if (OldLoop == L && !CreateRemainderLoop)
316-
return (NewLoop = ParentLoop);
317-
318-
// Now we know that there should be a cloned counterpart for OldLoop, but
319-
// we haven't seen it yet. Note that OldLoop might be L if we're
320-
// generating a remainder loop, or it can be an inner loop of L - in this
321-
// case we'll recreate the loop structure of L in its clone.
322-
323-
// This is a first block belonging to OldLoop encountered in our RPO
324-
// traversal.
325-
assert(*BB == OldLoop->getHeader() && "Header should be first in RPO");
326-
327-
NewLoop = new Loop;
328-
Loop *OldLoopParent = OldLoop->getParentLoop();
329-
// If OldLoop has a parent loop, we have two options:
330-
// 1. ParentLoop is the parent of L. It won't be cloned, and it will
331-
// be a parent for NewLoop too.
332-
// 2. ParentLoop is not a parent of L. In this case, it should be one
333-
// of the cloned loops and we should be able to find it in our map.
334-
//
335-
// If OldLoop doesn't have a parent, then NewLoop should be yet another
336-
// top-level loop.
337-
if (OldLoopParent) {
338-
Loop *NewLoopParent = ParentLoop == OldLoopParent
339-
? ParentLoop
340-
: NewLoops.lookup(OldLoopParent);
341-
assert(NewLoopParent && "Expected parent loop before sub-loop in RPO");
342-
NewLoopParent->addChildLoop(NewLoop);
343-
} else
344-
LI->addTopLevelLoop(NewLoop);
345-
return NewLoop;
346-
};
347-
348-
Loop *NewLoop = findClonedLoop(LI->getLoopFor(*BB));
349-
350-
assert(NewLoop ||
351-
(!CreateRemainderLoop && !ParentLoop) &&
352-
"NewLoop can only be null if we are cloning top-level loop "
353-
"without creating a remainder loop.");
354310
if (NewLoop)
355311
NewLoop->addBasicBlockToLoop(NewBB, *LI);
312+
else if (ParentLoop)
313+
ParentLoop->addBasicBlockToLoop(NewBB, *LI);
356314

357315
VMap[*BB] = NewBB;
358316
if (Header == *BB) {
@@ -411,8 +369,7 @@ static void CloneLoopBlocks(Loop *L, Value *NewIter,
411369
NewPHI->setIncomingValue(idx, V);
412370
}
413371
}
414-
if (CreateRemainderLoop) {
415-
Loop *NewLoop = NewLoops[L];
372+
if (NewLoop) {
416373
// Add unroll disable metadata to disable future unrolling for this loop.
417374
SmallVector<Metadata *, 4> MDs;
418375
// Reserve first location for self reference to the LoopID metadata node.

test/Transforms/LoopUnroll/pr28888.ll

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)