Index: include/llvm/Analysis/TargetTransformInfo.h =================================================================== --- include/llvm/Analysis/TargetTransformInfo.h +++ include/llvm/Analysis/TargetTransformInfo.h @@ -149,7 +149,7 @@ /// The contract for this function is the same as \c getOperationCost except /// that it supports an interface that provides extra information specific to /// the GEP operation. - int getGEPCost(Type *PointeeType, const Value *Ptr, + int getGEPCost(const GetElementPtrInst *GEP, ArrayRef Operands) const; /// \brief Estimate the cost of a function call when lowered. @@ -735,7 +735,7 @@ virtual ~Concept() = 0; virtual const DataLayout &getDataLayout() const = 0; virtual int getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy) = 0; - virtual int getGEPCost(Type *PointeeType, const Value *Ptr, + virtual int getGEPCost(const GetElementPtrInst *GEP, ArrayRef Operands) = 0; virtual int getCallCost(FunctionType *FTy, int NumArgs) = 0; virtual int getCallCost(const Function *F, int NumArgs) = 0; @@ -882,9 +882,9 @@ int getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy) override { return Impl.getOperationCost(Opcode, Ty, OpTy); } - int getGEPCost(Type *PointeeType, const Value *Ptr, + int getGEPCost(const GetElementPtrInst *GEP, ArrayRef Operands) override { - return Impl.getGEPCost(PointeeType, Ptr, Operands); + return Impl.getGEPCost(GEP, Operands); } int getCallCost(FunctionType *FTy, int NumArgs) override { return Impl.getCallCost(FTy, NumArgs); Index: include/llvm/Analysis/TargetTransformInfoImpl.h =================================================================== --- include/llvm/Analysis/TargetTransformInfoImpl.h +++ include/llvm/Analysis/TargetTransformInfoImpl.h @@ -103,7 +103,7 @@ } } - int getGEPCost(Type *PointeeType, const Value *Ptr, + int getGEPCost(const GetElementPtrInst *GEP, ArrayRef Operands) { // In the basic model, we just assume that all-constant GEPs will be folded // into their uses via addressing modes. @@ -566,13 +566,15 @@ using BaseT::getGEPCost; - int getGEPCost(Type *PointeeType, const Value *Ptr, + int getGEPCost(const GetElementPtrInst *GEP, ArrayRef Operands) { + assert(GEP); + const Value *Ptr = GEP->getPointerOperand(); const GlobalValue *BaseGV = nullptr; if (Ptr != nullptr) { // TODO: will remove this when pointers have an opaque type. assert(Ptr->getType()->getScalarType()->getPointerElementType() == - PointeeType && + GEP->getSourceElementType() && "explicit pointee type doesn't match operand's pointee type"); BaseGV = dyn_cast(Ptr->stripPointerCasts()); } @@ -580,7 +582,7 @@ int64_t BaseOffset = 0; int64_t Scale = 0; - auto GTI = gep_type_begin(PointeeType, Operands); + auto GTI = gep_type_begin(GEP); Type *TargetType; for (auto I = Operands.begin(); I != Operands.end(); ++I, ++GTI) { TargetType = GTI.getIndexedType(); @@ -639,8 +641,8 @@ if (const GEPOperator *GEP = dyn_cast(U)) { SmallVector Indices(GEP->idx_begin(), GEP->idx_end()); - return static_cast(this)->getGEPCost( - GEP->getSourceElementType(), GEP->getPointerOperand(), Indices); + return static_cast(this)->getGEPCost(cast(GEP), + Indices); } if (auto CS = ImmutableCallSite(U)) { Index: include/llvm/CodeGen/BasicTTIImpl.h =================================================================== --- include/llvm/CodeGen/BasicTTIImpl.h +++ include/llvm/CodeGen/BasicTTIImpl.h @@ -144,9 +144,9 @@ return getTLI()->isTypeLegal(VT); } - int getGEPCost(Type *PointeeType, const Value *Ptr, + int getGEPCost(const GetElementPtrInst *GEP, ArrayRef Operands) { - return BaseT::getGEPCost(PointeeType, Ptr, Operands); + return BaseT::getGEPCost(GEP, Operands); } unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy, Index: lib/Analysis/InlineCost.cpp =================================================================== --- lib/Analysis/InlineCost.cpp +++ lib/Analysis/InlineCost.cpp @@ -343,9 +343,7 @@ Indices.push_back(SimpleOp); else Indices.push_back(*I); - return TargetTransformInfo::TCC_Free == - TTI.getGEPCost(GEP.getSourceElementType(), GEP.getPointerOperand(), - Indices); + return TargetTransformInfo::TCC_Free == TTI.getGEPCost(&GEP, Indices); } bool CallAnalyzer::visitAlloca(AllocaInst &I) { Index: lib/Analysis/TargetTransformInfo.cpp =================================================================== --- lib/Analysis/TargetTransformInfo.cpp +++ lib/Analysis/TargetTransformInfo.cpp @@ -71,9 +71,9 @@ return TTIImpl->getInliningThresholdMultiplier(); } -int TargetTransformInfo::getGEPCost(Type *PointeeType, const Value *Ptr, +int TargetTransformInfo::getGEPCost(const GetElementPtrInst *GEP, ArrayRef Operands) const { - return TTIImpl->getGEPCost(PointeeType, Ptr, Operands); + return TTIImpl->getGEPCost(GEP, Operands); } int TargetTransformInfo::getIntrinsicCost( Index: lib/Transforms/Scalar/NaryReassociate.cpp =================================================================== --- lib/Transforms/Scalar/NaryReassociate.cpp +++ lib/Transforms/Scalar/NaryReassociate.cpp @@ -263,8 +263,7 @@ SmallVector Indices; for (auto I = GEP->idx_begin(); I != GEP->idx_end(); ++I) Indices.push_back(*I); - return TTI->getGEPCost(GEP->getSourceElementType(), GEP->getPointerOperand(), - Indices) == TargetTransformInfo::TCC_Free; + return TTI->getGEPCost(GEP, Indices) == TargetTransformInfo::TCC_Free; } Instruction *NaryReassociatePass::tryReassociateGEP(GetElementPtrInst *GEP) { Index: lib/Transforms/Scalar/StraightLineStrengthReduce.cpp =================================================================== --- lib/Transforms/Scalar/StraightLineStrengthReduce.cpp +++ lib/Transforms/Scalar/StraightLineStrengthReduce.cpp @@ -239,8 +239,7 @@ SmallVector Indices; for (auto I = GEP->idx_begin(); I != GEP->idx_end(); ++I) Indices.push_back(*I); - return TTI->getGEPCost(GEP->getSourceElementType(), GEP->getPointerOperand(), - Indices) == TargetTransformInfo::TCC_Free; + return TTI->getGEPCost(GEP, Indices) == TargetTransformInfo::TCC_Free; } // Returns whether (Base + Index * Stride) can be folded to an addressing mode.