[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner sabre at nondot.org
Sun Jan 14 23:30:21 PST 2007



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.599 -> 1.600
---
Log message:

Implement InstCombine/phi.ll:test7, deletion of trivial value loops for
induction variables.


---
Diffs of the changes:  (+16 -2)

 InstructionCombining.cpp |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.599 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.600
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.599	Mon Jan 15 01:02:54 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Mon Jan 15 01:30:06 2007
@@ -7595,13 +7595,27 @@
   // 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;
 }






More information about the llvm-commits mailing list