diff --git a/llvm/lib/Transforms/ExprTypeConvert.cpp b/llvm/lib/Transforms/ExprTypeConvert.cpp index d75a8ac68cbf..b61903578dc4 100644 --- a/llvm/lib/Transforms/ExprTypeConvert.cpp +++ b/llvm/lib/Transforms/ExprTypeConvert.cpp @@ -357,6 +357,10 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) { ValueMapCache::ExprMapTy::iterator VMCI = VMC.ExprMap.find(V); if (VMCI != VMC.ExprMap.end()) { assert(VMCI->second->getType() == Ty); + + if (Instruction *I = dyn_cast(V)) + ValueHandle IHandle(VMC, I); // Remove I if it is unused now! + return VMCI->second; } @@ -1084,13 +1088,11 @@ static void RecursiveDelete(ValueMapCache &Cache, Instruction *I) { #endif for (User::op_iterator OI = I->op_begin(), OE = I->op_end(); - OI != OE; ++OI) { - Instruction *U = dyn_cast(*OI); - if (U) { + OI != OE; ++OI) + if (Instruction *U = dyn_cast(*OI)) { *OI = 0; - RecursiveDelete(Cache, dyn_cast(U)); + RecursiveDelete(Cache, U); } - } I->getParent()->getInstList().remove(I);