From 1ed5396304ff6c29a043bed467f375efbff83d25 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Wed, 7 Dec 2016 21:47:32 +0000 Subject: [BDCE] Skip metadata while replacing uses. The fix committed in r288851 doesn't cover all the cases. In particular, if we have an instruction with side effects which has a no non-dbg use not depending on the bits, we still perform RAUW destroying the dbg.value's first argument. Prevent metadata from being replaced here to avoid the issue. Differential Revision: https://reviews.llvm.org/D27534 llvm-svn: 288987 --- llvm/lib/IR/Value.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'llvm/lib/IR') diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index 451cb09ea9f..91a999b5800 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -367,7 +367,7 @@ static bool contains(Value *Expr, Value *V) { } #endif // NDEBUG -void Value::replaceAllUsesWith(Value *New) { +void Value::doRAUW(Value *New, bool NoMetadata) { assert(New && "Value::replaceAllUsesWith() is invalid!"); assert(!contains(New, this) && "this->replaceAllUsesWith(expr(this)) is NOT valid!"); @@ -377,7 +377,7 @@ void Value::replaceAllUsesWith(Value *New) { // Notify all ValueHandles (if present) that this value is going away. if (HasValueHandle) ValueHandleBase::ValueIsRAUWd(this, New); - if (isUsedByMetadata()) + if (!NoMetadata && isUsedByMetadata()) ValueAsMetadata::handleRAUW(this, New); while (!use_empty()) { @@ -398,6 +398,14 @@ void Value::replaceAllUsesWith(Value *New) { BB->replaceSuccessorsPhiUsesWith(cast(New)); } +void Value::replaceAllUsesWith(Value *New) { + doRAUW(New, false /* NoMetadata */); +} + +void Value::replaceNonMetadataUsesWith(Value *New) { + doRAUW(New, true /* NoMetadata */); +} + // Like replaceAllUsesWith except it does not handle constants or basic blocks. // This routine leaves uses within BB. void Value::replaceUsesOutsideBlock(Value *New, BasicBlock *BB) { -- cgit v1.2.3