Skip to content

Commit 34399dd

Browse files
committed
Fix LICM/2003-12-11-SinkingToPHI.ll, and quite possibly all of the other known problems in the universe.
llvm-svn: 10409
1 parent 99146bb commit 34399dd

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,18 @@ bool LICM::canSinkOrHoistInst(Instruction &I) {
337337
/// exit blocks of the loop.
338338
///
339339
bool LICM::isNotUsedInLoop(Instruction &I) {
340-
for (Value::use_iterator UI = I.use_begin(), E = I.use_end(); UI != E; ++UI)
341-
if (CurLoop->contains(cast<Instruction>(*UI)->getParent()))
340+
for (Value::use_iterator UI = I.use_begin(), E = I.use_end(); UI != E; ++UI) {
341+
Instruction *User = cast<Instruction>(*UI);
342+
if (PHINode *PN = dyn_cast<PHINode>(User)) {
343+
// PHI node uses occur in predecessor blocks!
344+
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
345+
if (PN->getIncomingValue(i) == &I)
346+
if (CurLoop->contains(PN->getIncomingBlock(i)))
347+
return false;
348+
} else if (CurLoop->contains(User->getParent())) {
342349
return false;
350+
}
351+
}
343352
return true;
344353
}
345354

0 commit comments

Comments
 (0)