From: Chris Lattner Date: Mon, 15 Jan 2007 07:30:06 +0000 (+0000) Subject: Implement InstCombine/phi.ll:test7, deletion of trivial value loops for X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=ff9f13a4b2b7030b027006e0d970ef059db5c587;p=oota-llvm.git Implement InstCombine/phi.ll:test7, deletion of trivial value loops for induction variables. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33234 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 978b2e95ccc..04a6e83c063 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -7595,13 +7595,27 @@ Instruction *InstCombiner::visitPHINode(PHINode &PN) { // If this is a trivial cycle in the PHI node graph, remove it. Basically, if // this PHI only has a single use (a PHI), and if that PHI only has one use (a // PHI)... break the cycle. - if (PN.hasOneUse()) - if (PHINode *PU = dyn_cast(PN.use_back())) { + if (PN.hasOneUse()) { + Instruction *PHIUser = cast(PN.use_back()); + if (PHINode *PU = dyn_cast(PHIUser)) { std::set PotentiallyDeadPHIs; PotentiallyDeadPHIs.insert(&PN); if (DeadPHICycle(PU, PotentiallyDeadPHIs)) return ReplaceInstUsesWith(PN, UndefValue::get(PN.getType())); } + + // If this phi has a single use, and if that use just computes a value for + // the next iteration of a loop, delete the phi. This occurs with unused + // induction variables, e.g. "for (int j = 0; ; ++j);". Detecting this + // common case here is good because the only other things that catch this + // are induction variable analysis (sometimes) and ADCE, which is only run + // late. + if (PHIUser->hasOneUse() && + (isa(PHIUser) || isa(PHIUser)) && + PHIUser->use_back() == &PN) { + return ReplaceInstUsesWith(PN, UndefValue::get(PN.getType())); + } + } return 0; }