diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 5e23514bf5ae0b..2285a91cbdf2bb 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1916,29 +1916,6 @@ Instruction *InstCombinerImpl::visitIntToPtr(IntToPtrInst &CI) { return nullptr; } -/// Implement the transforms for cast of pointer (bitcast/ptrtoint) -Instruction *InstCombinerImpl::commonPointerCastTransforms(CastInst &CI) { - Value *Src = CI.getOperand(0); - - if (GetElementPtrInst *GEP = dyn_cast(Src)) { - // If casting the result of a getelementptr instruction with no offset, turn - // this into a cast of the original pointer! - if (GEP->hasAllZeroIndices() && - // If CI is an addrspacecast and GEP changes the poiner type, merging - // GEP into CI would undo canonicalizing addrspacecast with different - // pointer types, causing infinite loops. - (!isa(CI) || - GEP->getType() == GEP->getPointerOperandType())) { - // Changing the cast operand is usually not a good idea but it is safe - // here because the pointer operand is being replaced with another - // pointer operand so the opcode doesn't need to change. - return replaceOperand(CI, 0, GEP->getOperand(0)); - } - } - - return commonCastTransforms(CI); -} - Instruction *InstCombinerImpl::visitPtrToInt(PtrToIntInst &CI) { // If the destination integer type is not the intptr_t type for this target, // do a ptrtoint to intptr_t then do a trunc or zext. This allows the cast @@ -1980,7 +1957,7 @@ Instruction *InstCombinerImpl::visitPtrToInt(PtrToIntInst &CI) { return InsertElementInst::Create(Vec, NewCast, Index); } - return commonPointerCastTransforms(CI); + return commonCastTransforms(CI); } /// This input value (which is known to have vector type) is being zero extended @@ -2702,11 +2679,9 @@ Instruction *InstCombinerImpl::visitBitCast(BitCastInst &CI) { if (Instruction *I = foldBitCastSelect(CI, Builder)) return I; - if (SrcTy->isPointerTy()) - return commonPointerCastTransforms(CI); return commonCastTransforms(CI); } Instruction *InstCombinerImpl::visitAddrSpaceCast(AddrSpaceCastInst &CI) { - return commonPointerCastTransforms(CI); + return commonCastTransforms(CI); } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index a53d67b2899b70..01c89ea06f2d9d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -131,7 +131,6 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final Instruction *FoldShiftByConstant(Value *Op0, Constant *Op1, BinaryOperator &I); Instruction *commonCastTransforms(CastInst &CI); - Instruction *commonPointerCastTransforms(CastInst &CI); Instruction *visitTrunc(TruncInst &CI); Instruction *visitZExt(ZExtInst &Zext); Instruction *visitSExt(SExtInst &Sext);