diff options
| author | Chris Lattner <sabre@nondot.org> | 2007-01-15 07:30:06 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2007-01-15 07:30:06 +0000 |
| commit | c8dcede292a8bb6b699dd5664d3795d5839e0a15 (patch) | |
| tree | ab44f920de1e94e579483635f88113e7f904f002 /llvm/lib/Transforms | |
| parent | aed9f046f37c8c56b286238e735628aab6ba361a (diff) | |
| download | bcm5719-llvm-c8dcede292a8bb6b699dd5664d3795d5839e0a15.tar.gz bcm5719-llvm-c8dcede292a8bb6b699dd5664d3795d5839e0a15.zip | |
Implement InstCombine/phi.ll:test7, deletion of trivial value loops for
induction variables.
llvm-svn: 33234
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 978b2e95ccc..04a6e83c063 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/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<PHINode>(PN.use_back())) { + if (PN.hasOneUse()) { + Instruction *PHIUser = cast<Instruction>(PN.use_back()); + if (PHINode *PU = dyn_cast<PHINode>(PHIUser)) { std::set<PHINode*> 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<BinaryOperator>(PHIUser) || isa<GetElementPtrInst>(PHIUser)) && + PHIUser->use_back() == &PN) { + return ReplaceInstUsesWith(PN, UndefValue::get(PN.getType())); + } + } return 0; } |

