From 1df203d78e478bea989736fd9f1657adea70db0d Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 17 Jun 2019 14:13:29 +0000 Subject: InferAddressSpaces: Fix cloning original addrspacecast If an addrspacecast needed to be inserted again, this was creating a clone of the original cast for each user. Just use the original, which also saves losing the value name. llvm-svn: 363562 --- llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp index 36115e96cf4..5f0e2001c73 100644 --- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp +++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp @@ -1006,8 +1006,12 @@ bool InferAddressSpaces::rewriteWithNewAddressSpaces( } // Otherwise, replaces the use with flat(NewV). - if (Instruction *I = dyn_cast(V)) { - BasicBlock::iterator InsertPos = std::next(I->getIterator()); + if (Instruction *Inst = dyn_cast(V)) { + // Don't create a copy of the original addrspacecast. + if (U == V && isa(V)) + continue; + + BasicBlock::iterator InsertPos = std::next(Inst->getIterator()); while (isa(InsertPos)) ++InsertPos; U.set(new AddrSpaceCastInst(NewV, V->getType(), "", &*InsertPos)); -- cgit v1.2.3