diff options
| author | Chris Lattner <sabre@nondot.org> | 2004-04-05 02:10:19 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2004-04-05 02:10:19 +0000 |
| commit | 8953b90aaad4e2dbce5a44b7c7d9e1825fa21868 (patch) | |
| tree | 3aa5afae5473e37ea6a78a033f71a6e9c55f80e3 /llvm/lib | |
| parent | e79fd5c76635df53aa39c4c390333d86a40f84dd (diff) | |
| download | bcm5719-llvm-8953b90aaad4e2dbce5a44b7c7d9e1825fa21868.tar.gz bcm5719-llvm-8953b90aaad4e2dbce5a44b7c7d9e1825fa21868.zip | |
Fix InstCombine/2004-04-04-InstCombineReplaceAllUsesWith.ll
llvm-svn: 12658
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index a1e6c997dbb..aa260da9b54 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -151,8 +151,15 @@ namespace { // 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 @@ Instruction *AssociativeOpt(BinaryOperator &Root, const Functor &F) { // 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 |

