diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp index 8c6c0728097c..824da6395f2e 100644 --- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -98,49 +98,11 @@ using OffsetAndArgPart = std::pair; static Value *createByteGEP(IRBuilderBase &IRB, const DataLayout &DL, Value *Ptr, Type *ResElemTy, int64_t Offset) { - // For non-opaque pointers, try to create a "nice" GEP if possible, otherwise - // fall back to an i8 GEP to a specific offset. - unsigned AddrSpace = Ptr->getType()->getPointerAddressSpace(); - APInt OrigOffset(DL.getIndexTypeSizeInBits(Ptr->getType()), Offset); - if (!Ptr->getType()->isOpaquePointerTy()) { - Type *OrigElemTy = Ptr->getType()->getNonOpaquePointerElementType(); - if (OrigOffset == 0 && OrigElemTy == ResElemTy) - return Ptr; - - if (OrigElemTy->isSized()) { - APInt TmpOffset = OrigOffset; - Type *TmpTy = OrigElemTy; - SmallVector IntIndices = - DL.getGEPIndicesForOffset(TmpTy, TmpOffset); - if (TmpOffset == 0) { - // Try to add trailing zero indices to reach the right type. - while (TmpTy != ResElemTy) { - Type *NextTy = GetElementPtrInst::getTypeAtIndex(TmpTy, (uint64_t)0); - if (!NextTy) - break; - - IntIndices.push_back(APInt::getZero( - isa(TmpTy) ? 32 : OrigOffset.getBitWidth())); - TmpTy = NextTy; - } - - SmallVector Indices; - for (const APInt &Index : IntIndices) - Indices.push_back(IRB.getInt(Index)); - - if (OrigOffset != 0 || TmpTy == ResElemTy) { - Ptr = IRB.CreateGEP(OrigElemTy, Ptr, Indices); - return IRB.CreateBitCast(Ptr, ResElemTy->getPointerTo(AddrSpace)); - } - } - } + if (Offset != 0) { + APInt APOffset(DL.getIndexTypeSizeInBits(Ptr->getType()), Offset); + Ptr = IRB.CreateGEP(IRB.getInt8Ty(), Ptr, IRB.getInt(APOffset)); } - - if (OrigOffset != 0) { - Ptr = IRB.CreateBitCast(Ptr, IRB.getInt8PtrTy(AddrSpace)); - Ptr = IRB.CreateGEP(IRB.getInt8Ty(), Ptr, IRB.getInt(OrigOffset)); - } - return IRB.CreateBitCast(Ptr, ResElemTy->getPointerTo(AddrSpace)); + return Ptr; } /// DoPromotion - This method actually performs the promotion of the specified