diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index f8bd3f372038..a4e382d9c858 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -1773,13 +1773,14 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, bool& ModifiedDT) { // Substituting this can cause recursive simplifications, which can // invalidate our iterator. Use a WeakVH to hold onto it in case this // happens. - WeakVH IterHandle(&*CurInstIterator); + Value *CurValue = &*CurInstIterator; + WeakVH IterHandle(CurValue); replaceAndRecursivelySimplify(CI, RetVal, TLInfo, nullptr); // If the iterator instruction was recursively deleted, start over at the // start of the block. - if (IterHandle != CurInstIterator.getNodePtrUnchecked()) { + if (IterHandle != CurValue) { CurInstIterator = BB->begin(); SunkAddrs.clear(); } @@ -3945,12 +3946,13 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr, if (Repl->use_empty()) { // This can cause recursive deletion, which can invalidate our iterator. // Use a WeakVH to hold onto it in case this happens. - WeakVH IterHandle(&*CurInstIterator); + Value *CurValue = &*CurInstIterator; + WeakVH IterHandle(CurValue); BasicBlock *BB = CurInstIterator->getParent(); RecursivelyDeleteTriviallyDeadInstructions(Repl, TLInfo); - if (IterHandle != CurInstIterator.getNodePtrUnchecked()) { + if (IterHandle != CurValue) { // If the iterator instruction was recursively deleted, start over at the // start of the block. CurInstIterator = BB->begin();