diff --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp index d3771c0903456..1b7cecc7ceb6a 100644 --- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp +++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp @@ -660,8 +660,6 @@ Value *InferAddressSpacesImpl::cloneInstructionWithNewAddressSpace( // Therefore, the inferred address space must be the source space, according // to our algorithm. assert(Src->getType()->getPointerAddressSpace() == NewAddrSpace); - if (Src->getType() != NewPtrType) - return new BitCastInst(Src, NewPtrType); return Src; } @@ -739,7 +737,7 @@ Value *InferAddressSpacesImpl::cloneInstructionWithNewAddressSpace( // If we had a no-op inttoptr/ptrtoint pair, we may still have inferred a // source address space from a generic pointer source need to insert a cast // back. - return CastInst::CreatePointerBitCastOrAddrSpaceCast(Src, NewPtrType); + return new AddrSpaceCastInst(Src, NewPtrType); } default: llvm_unreachable("Unexpected opcode"); @@ -764,7 +762,7 @@ static Value *cloneConstantExprWithNewAddressSpace( // to our algorithm. assert(CE->getOperand(0)->getType()->getPointerAddressSpace() == NewAddrSpace); - return ConstantExpr::getBitCast(CE->getOperand(0), TargetType); + return CE->getOperand(0); } if (CE->getOpcode() == Instruction::BitCast) { @@ -777,7 +775,7 @@ static Value *cloneConstantExprWithNewAddressSpace( assert(isNoopPtrIntCastPair(cast(CE), *DL, TTI)); Constant *Src = cast(CE->getOperand(0))->getOperand(0); assert(Src->getType()->getPointerAddressSpace() == NewAddrSpace); - return ConstantExpr::getBitCast(Src, TargetType); + return Src; } // Computes the operands of the new constant expression.