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

Chris Lattner lattner at cs.uiuc.edu
Sun Oct 17 14:22:49 PDT 2004



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.271 -> 1.272
---
Log message:

hasConstantValue will soon return instructions that don't dominate the PHI node,
so prepare for this.


---
Diffs of the changes:  (+18 -4)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.271 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.272
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.271	Sat Oct 16 18:28:04 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Sun Oct 17 16:22:38 2004
@@ -3364,7 +3364,7 @@
       }
       AddUsersToWorkList(*Caller);
     } else {
-      NV = Constant::getNullValue(Caller->getType());
+      NV = UndefValue::get(Caller->getType());
     }
   }
 
@@ -3380,9 +3380,23 @@
 // PHINode simplification
 //
 Instruction *InstCombiner::visitPHINode(PHINode &PN) {
-  // FIXME: hasConstantValue should ignore undef values!
-  if (Value *V = hasConstantValue(&PN))
-    return ReplaceInstUsesWith(PN, V);
+  if (Value *V = hasConstantValue(&PN)) {
+    // If V is an instruction, we have to be certain that it dominates PN.
+    // However, because we don't have dom info, we can't do a perfect job.
+    if (Instruction *I = dyn_cast<Instruction>(V)) {
+      // We know that the instruction dominates the PHI if there are no undef
+      // values coming in.
+      for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
+        if (isa<UndefValue>(PN.getIncomingValue(i))) {
+          std::cerr << "HAD TO DISABLE PHI ELIM IN IC!\n";
+          V = 0;
+          break;
+        }
+    }
+
+    if (V)
+      return ReplaceInstUsesWith(PN, V);
+  }
 
   // If the only user of this instruction is a cast instruction, and all of the
   // incoming values are constants, change this PHI to merge together the casted






More information about the llvm-commits mailing list