diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index bcc17f1b98a..60583385317 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -563,10 +563,12 @@ bool InstCombiner::SimplifyDemandedBits(Value *V, uint64_t Mask, // extend instead of a sign extend. if ((Mask & ((1ULL << SrcBits)-1)) == 0) { // Convert to unsigned first. - Value *NewVal; + Instruction *NewVal; NewVal = new CastInst(I->getOperand(0), SrcTy->getUnsignedVersion(), - I->getOperand(0)->getName(), I); - NewVal = new CastInst(I->getOperand(0), I->getType(), I->getName()); + I->getOperand(0)->getName()); + InsertNewInstBefore(NewVal, *I); + NewVal = new CastInst(NewVal, I->getType(), I->getName()); + InsertNewInstBefore(NewVal, *I); return UpdateValueUsesWith(I, NewVal); }