From ea9403f2aa078e840a49792d906390395f0cd2f6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 11 Dec 2003 22:23:32 +0000 Subject: [PATCH] Fix LICM/2003-12-11-SinkingToPHI.ll, and quite possibly all of the other known problems in the universe. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10409 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LICM.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp index 0d8a848cc0d..3365e64af05 100644 --- a/lib/Transforms/Scalar/LICM.cpp +++ b/lib/Transforms/Scalar/LICM.cpp @@ -337,9 +337,18 @@ bool LICM::canSinkOrHoistInst(Instruction &I) { /// exit blocks of the loop. /// bool LICM::isNotUsedInLoop(Instruction &I) { - for (Value::use_iterator UI = I.use_begin(), E = I.use_end(); UI != E; ++UI) - if (CurLoop->contains(cast(*UI)->getParent())) + for (Value::use_iterator UI = I.use_begin(), E = I.use_end(); UI != E; ++UI) { + Instruction *User = cast(*UI); + if (PHINode *PN = dyn_cast(User)) { + // PHI node uses occur in predecessor blocks! + for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) + if (PN->getIncomingValue(i) == &I) + if (CurLoop->contains(PN->getIncomingBlock(i))) + return false; + } else if (CurLoop->contains(User->getParent())) { return false; + } + } return true; }