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

Chris Lattner lattner at cs.uiuc.edu
Sun Apr 4 21:11:02 PDT 2004


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.177 -> 1.178

---
Log message:

Fix InstCombine/2004-04-04-InstCombineReplaceAllUsesWith.ll



---
Diffs of the changes:  (+15 -3)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.177 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.178
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.177	Sun Apr  4 20:29:05 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Sun Apr  4 21:10:19 2004
@@ -151,8 +151,15 @@
     //
     Instruction *ReplaceInstUsesWith(Instruction &I, Value *V) {
       AddUsersToWorkList(I);         // Add all modified instrs to worklist
-      I.replaceAllUsesWith(V);
-      return &I;
+      if (&I != V) {
+        I.replaceAllUsesWith(V);
+        return &I;
+      } else {
+        // If we are replacing the instruction with itself, this must be in a
+        // segment of unreachable code, so just clobber the instruction.
+        I.replaceAllUsesWith(Constant::getNullValue(I.getType()));
+        return &I;
+      }
     }
 
     // EraseInstFromFunction - When dealing with an instruction that has side
@@ -424,7 +431,12 @@
 
       // Make what used to be the LHS of the root be the user of the root...
       Value *ExtraOperand = TmpLHSI->getOperand(1);
-      Root.replaceAllUsesWith(TmpLHSI);          // Users now use TmpLHSI
+      if (&Root != TmpLHSI)
+        Root.replaceAllUsesWith(TmpLHSI);        // Users now use TmpLHSI
+      else {
+        Root.replaceAllUsesWith(Constant::getNullValue(TmpLHSI->getType()));
+        return 0;
+      }
       TmpLHSI->setOperand(1, &Root);             // TmpLHSI now uses the root
       BB->getInstList().remove(&Root);           // Remove root from the BB
       BB->getInstList().insert(TmpLHSI, &Root);  // Insert root before TmpLHSI





More information about the llvm-commits mailing list