diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -122,13 +122,9 @@ Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) { Value *Removed = getIncomingValue(Idx); - // Move everything after this operand down. - // - // FIXME: we could just swap with the end of the list, then erase. However, - // clients might not expect this to happen. The code as it is thrashes the - // use/def lists, which is kinda lame. - std::copy(op_begin() + Idx + 1, op_end(), op_begin() + Idx); - std::copy(block_begin() + Idx + 1, block_end(), block_begin() + Idx); + // Swap ops to remove with last op. + *(op_begin() + Idx)->swap(*std::prev(op_end())); + std::iter_swap(block_begin() + Idx, std::prev(block_end())); // Nuke the last value. Op<-1>().set(nullptr);