From: Nick Desaulniers Date: Wed, 5 Jun 2019 01:28:55 +0000 (+0000) Subject: [TargetTransformInfo] assert on nullptr X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=198088e9e115f189644f5457b6a0d309f07f0837;p=llvm [TargetTransformInfo] assert on nullptr Summary: This was flagged in https://www.viva64.com/en/b/0629/ under "Snippet No. 38". Add an assertion, since it's unlikely that this parameter is nullptr. Reviewers: RKSimon, fhahn Reviewed By: RKSimon Subscribers: fhahn, llvm-commits, RKSimon, srhines Tags: #llvm Differential Revision: https://reviews.llvm.org/D62229 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362567 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/TargetTransformInfoImpl.h b/include/llvm/Analysis/TargetTransformInfoImpl.h index af250aa638e..bb290ec898e 100644 --- a/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -681,14 +681,12 @@ public: int getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef Operands) { - const GlobalValue *BaseGV = nullptr; - if (Ptr != nullptr) { - // TODO: will remove this when pointers have an opaque type. - assert(Ptr->getType()->getScalarType()->getPointerElementType() == - PointeeType && - "explicit pointee type doesn't match operand's pointee type"); - BaseGV = dyn_cast(Ptr->stripPointerCasts()); - } + assert(PointeeType && Ptr && "can't get GEPCost of nullptr"); + // TODO: will remove this when pointers have an opaque type. + assert(Ptr->getType()->getScalarType()->getPointerElementType() == + PointeeType && + "explicit pointee type doesn't match operand's pointee type"); + auto *BaseGV = dyn_cast(Ptr->stripPointerCasts()); bool HasBaseReg = (BaseGV == nullptr); auto PtrSizeBits = DL.getPointerTypeSizeInBits(Ptr->getType()); @@ -731,13 +729,10 @@ public: } } - // Assumes the address space is 0 when Ptr is nullptr. - unsigned AS = - (Ptr == nullptr ? 0 : Ptr->getType()->getPointerAddressSpace()); - if (static_cast(this)->isLegalAddressingMode( TargetType, const_cast(BaseGV), - BaseOffset.sextOrTrunc(64).getSExtValue(), HasBaseReg, Scale, AS)) + BaseOffset.sextOrTrunc(64).getSExtValue(), HasBaseReg, Scale, + Ptr->getType()->getPointerAddressSpace())) return TTI::TCC_Free; return TTI::TCC_Basic; }