Index: llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h =================================================================== --- llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h +++ llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -423,7 +423,7 @@ // Assumes the address space is 0 when Ptr is nullptr. unsigned AS = (Ptr == nullptr ? 0 : Ptr->getType()->getPointerAddressSpace()); - auto GTI = gep_type_begin(PointerType::get(PointeeType, AS), Operands); + auto GTI = gep_type_begin(PointeeType, AS, Operands); for (auto I = Operands.begin(); I != Operands.end(); ++I, ++GTI) { // We assume that the cost of Scalar GEP with constant index and the // cost of Vector GEP with splat constant index are the same. Index: llvm/trunk/include/llvm/IR/GetElementPtrTypeIterator.h =================================================================== --- llvm/trunk/include/llvm/IR/GetElementPtrTypeIterator.h +++ llvm/trunk/include/llvm/IR/GetElementPtrTypeIterator.h @@ -33,12 +33,6 @@ generic_gep_type_iterator() {} public: - static generic_gep_type_iterator begin(Type *Ty, ItTy It) { - generic_gep_type_iterator I; - I.CurTy.setPointer(Ty); - I.OpIt = It; - return I; - } static generic_gep_type_iterator begin(Type *Ty, unsigned AddrSpace, ItTy It) { generic_gep_type_iterator I; @@ -125,13 +119,13 @@ template inline generic_gep_type_iterator - gep_type_begin(Type *Op0, ArrayRef A) { - return generic_gep_type_iterator::begin(Op0, A.begin()); + gep_type_begin(Type *Op0, unsigned AS, ArrayRef A) { + return generic_gep_type_iterator::begin(Op0, AS, A.begin()); } template inline generic_gep_type_iterator - gep_type_end(Type * /*Op0*/, ArrayRef A) { + gep_type_end(Type * /*Op0*/, unsigned /*AS*/, ArrayRef A) { return generic_gep_type_iterator::end(A.end()); } } // end namespace llvm Index: llvm/trunk/lib/IR/DataLayout.cpp =================================================================== --- llvm/trunk/lib/IR/DataLayout.cpp +++ llvm/trunk/lib/IR/DataLayout.cpp @@ -729,8 +729,11 @@ assert(Ty->isPointerTy() && "Illegal argument for getIndexedOffset()"); uint64_t Result = 0; + // We can use 0 as the address space as we don't need + // to get pointer types back from gep_type_iterator. + unsigned AS = 0; generic_gep_type_iterator - TI = gep_type_begin(ptrTy, Indices); + TI = gep_type_begin(ptrTy->getPointerElementType(), AS, Indices); for (unsigned CurIDX = 0, EndIDX = Indices.size(); CurIDX != EndIDX; ++CurIDX, ++TI) { if (StructType *STy = dyn_cast(*TI)) {