Skip debugging intrinsics when sinking unused invariants.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99324 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling
2010-03-23 21:15:59 +00:00
parent 927b88f771
commit 87a10f5b2f

View File

@@ -553,22 +553,26 @@ void IndVarSimplify::SinkUnusedInvariants(Loop *L) {
// New instructions were inserted at the end of the preheader. // New instructions were inserted at the end of the preheader.
if (isa<PHINode>(I)) if (isa<PHINode>(I))
break; break;
// Don't move instructions which might have side effects, since the side // Don't move instructions which might have side effects, since the side
// effects need to complete before instructions inside the loop. Also // effects need to complete before instructions inside the loop. Also don't
// don't move instructions which might read memory, since the loop may // move instructions which might read memory, since the loop may modify
// modify memory. Note that it's okay if the instruction might have // memory. Note that it's okay if the instruction might have undefined
// undefined behavior: LoopSimplify guarantees that the preheader // behavior: LoopSimplify guarantees that the preheader dominates the exit
// dominates the exit block. // block.
if (I->mayHaveSideEffects() || I->mayReadFromMemory()) if (I->mayHaveSideEffects() || I->mayReadFromMemory())
continue; continue;
// Skip debug info intrinsics. // Skip debug info intrinsics.
if (isa<DbgInfoIntrinsic>(I)) if (isa<DbgInfoIntrinsic>(I))
continue; continue;
// Don't sink static AllocaInsts out of the entry block, which would // Don't sink static AllocaInsts out of the entry block, which would
// turn them into dynamic allocas! // turn them into dynamic allocas!
if (AllocaInst *AI = dyn_cast<AllocaInst>(I)) if (AllocaInst *AI = dyn_cast<AllocaInst>(I))
if (AI->isStaticAlloca()) if (AI->isStaticAlloca())
continue; continue;
// Determine if there is a use in or before the loop (direct or // Determine if there is a use in or before the loop (direct or
// otherwise). // otherwise).
bool UsedInLoop = false; bool UsedInLoop = false;
@@ -585,19 +589,29 @@ void IndVarSimplify::SinkUnusedInvariants(Loop *L) {
break; break;
} }
} }
// If there is, the def must remain in the preheader. // If there is, the def must remain in the preheader.
if (UsedInLoop) if (UsedInLoop)
continue; continue;
// Otherwise, sink it to the exit block. // Otherwise, sink it to the exit block.
Instruction *ToMove = I; Instruction *ToMove = I;
bool Done = false; bool Done = false;
if (I != Preheader->begin())
--I; if (I != Preheader->begin()) {
else // Skip debug info intrinsics.
do {
--I;
} while (isa<DbgInfoIntrinsic>(I) && I != Preheader->begin());
if (isa<DbgInfoIntrinsic>(I) && I == Preheader->begin())
Done = true;
} else {
Done = true; Done = true;
}
ToMove->moveBefore(InsertPt); ToMove->moveBefore(InsertPt);
if (Done) if (Done) break;
break;
InsertPt = ToMove; InsertPt = ToMove;
} }
} }