Index: llvm/trunk/lib/IR/Value.cpp =================================================================== --- llvm/trunk/lib/IR/Value.cpp +++ llvm/trunk/lib/IR/Value.cpp @@ -773,6 +773,8 @@ void ValueHandleBase::ValueIsRAUWd(Value *Old, Value *New) { assert(Old->HasValueHandle &&"Should only be called if ValueHandles present"); assert(Old != New && "Changing value into itself!"); + assert(Old->getType() == New->getType() && + "replaceAllUses of value with new value of different type!"); // Get the linked list base, which is guaranteed to exist since the // HasValueHandle flag is set. Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp =================================================================== --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -1370,7 +1370,7 @@ if (!Caller->use_empty() && // void -> non-void is handled specially !NewRetTy->isVoidTy()) - return false; // Cannot transform this return value. + return false; // Cannot transform this return value. } if (!CallerPAL.isEmpty() && !Caller->use_empty()) { @@ -1589,8 +1589,14 @@ if (!Caller->use_empty()) ReplaceInstUsesWith(*Caller, NV); - else if (Caller->hasValueHandle()) - ValueHandleBase::ValueIsRAUWd(Caller, NV); + else if (Caller->hasValueHandle()) { + if (OldRetTy == NV->getType()) + ValueHandleBase::ValueIsRAUWd(Caller, NV); + else + // We cannot call ValueIsRAUWd with a different type, and the + // actual tracked value will disappear. + ValueHandleBase::ValueIsDeleted(Caller); + } EraseInstFromFunction(*Caller); return true;