X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTransforms%2FScalar%2FLoopStrengthReduce.cpp;h=d825ea789b596a7862387ed18501df5f01227952;hb=cbfe5bbe88f5f2ee03a388585112f7609c8151ad;hp=dd459f5690657539ada48e41452bb9816989b30c;hpb=9b78763fce4cb418e7a2e672efb84bac25559b79;p=oota-llvm.git diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index dd459f56906..d825ea789b5 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -1810,31 +1810,28 @@ bool LoopStrengthReduce::runOnLoop(Loop *L, LPPassManager &LPM) { DeleteTriviallyDeadInstructions(DeadInsts); BasicBlock::iterator I = L->getHeader()->begin(); - PHINode *PN; - while ((PN = dyn_cast(I))) { - ++I; // Preincrement iterator to avoid invalidating it when deleting PN. - - // At this point, we know that we have killed one or more GEP - // instructions. It is worth checking to see if the cann indvar is also - // dead, so that we can remove it as well. The requirements for the cann - // indvar to be considered dead are: - // 1. the cann indvar has one use - // 2. the use is an add instruction - // 3. the add has one use - // 4. the add is used by the cann indvar - // If all four cases above are true, then we can remove both the add and - // the cann indvar. + while (PHINode *PN = dyn_cast(I++)) { + // At this point, we know that we have killed one or more IV users. + // It is worth checking to see if the cann indvar is also + // dead, so that we can remove it as well. + // + // We can remove a PHI if it is on a cycle in the def-use graph + // where each node in the cycle has degree one, i.e. only one use, + // and is an instruction with no side effects. + // // FIXME: this needs to eliminate an induction variable even if it's being // compared against some value to decide loop termination. if (PN->hasOneUse()) { - Instruction *BO = dyn_cast(*PN->use_begin()); - if (BO && (isa(BO) || isa(BO))) { - if (BO->hasOneUse() && PN == *(BO->use_begin())) { - DeadInsts.insert(BO); - // Break the cycle, then delete the PHI. + for (Instruction *J = dyn_cast(*PN->use_begin()); + J && J->hasOneUse() && !J->mayWriteToMemory(); + J = dyn_cast(*J->use_begin())) { + // If we find the original PHI, we've discovered a cycle. + if (J == PN) { + // Break the cycle and mark the PHI for deletion. SE->deleteValueFromRecords(PN); PN->replaceAllUsesWith(UndefValue::get(PN->getType())); - PN->eraseFromParent(); + DeadInsts.insert(PN); + break; } } }