From: David Blaikie Date: Fri, 17 Apr 2015 22:32:16 +0000 (+0000) Subject: [opaque pointer type] Avoid creating (and then unwrapping) a pointer type to compute... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=40294c3e49a3f925c82b41c34af17a4202ce25d8 [opaque pointer type] Avoid creating (and then unwrapping) a pointer type to compute the result type of a GEP git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235234 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/IR/Instructions.h b/include/llvm/IR/Instructions.h index 5d53b252c14..ff9254372ea 100644 --- a/include/llvm/IR/Instructions.h +++ b/include/llvm/IR/Instructions.h @@ -924,12 +924,14 @@ public: /// GetGEPReturnType - Returns the pointer type returned by the GEP /// instruction, which may be a vector of pointers. static Type *getGEPReturnType(Value *Ptr, ArrayRef IdxList) { - Type *PtrTy = - PointerType::get(checkGEPType(getIndexedType( - cast(Ptr->getType()->getScalarType()) - ->getElementType(), - IdxList)), - Ptr->getType()->getPointerAddressSpace()); + return getGEPReturnType( + cast(Ptr->getType()->getScalarType())->getElementType(), + Ptr, IdxList); + } + static Type *getGEPReturnType(Type *ElTy, Value *Ptr, + ArrayRef IdxList) { + Type *PtrTy = PointerType::get(checkGEPType(getIndexedType(ElTy, IdxList)), + Ptr->getType()->getPointerAddressSpace()); // Vector GEP if (Ptr->getType()->isVectorTy()) { unsigned NumElem = cast(Ptr->getType())->getNumElements(); @@ -993,7 +995,9 @@ GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr, ArrayRef IdxList, unsigned Values, const Twine &NameStr, Instruction *InsertBefore) - : Instruction(getGEPReturnType(Ptr, IdxList), GetElementPtr, + : Instruction(PointeeType ? getGEPReturnType(PointeeType, Ptr, IdxList) + : getGEPReturnType(Ptr, IdxList), + GetElementPtr, OperandTraits::op_end(this) - Values, Values, InsertBefore) { init(Ptr, IdxList, NameStr);