From: Nikita Popov Date: Tue, 18 Jul 2023 10:37:35 +0000 (+0200) Subject: [Constants] Use getGEPReturnType() (NFC) X-Git-Tag: upstream/17.0.6~1356 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eadbc4b004b6f5bcd67f17b1d79c9955bd410fb8;p=platform%2Fupstream%2Fllvm.git [Constants] Use getGEPReturnType() (NFC) This reimplements essentially the same logic. --- diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 9c8d044..c69c7c0 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -2380,7 +2380,6 @@ Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C, ArrayRef Idxs, bool InBounds, std::optional InRangeIndex, Type *OnlyIfReducedTy) { - PointerType *OrigPtrTy = cast(C->getType()->getScalarType()); assert(Ty && "Must specify element type"); assert(isSupportedGetElementPtr(Ty) && "Element type is unsupported!"); @@ -2388,27 +2387,17 @@ Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C, ConstantFoldGetElementPtr(Ty, C, InBounds, InRangeIndex, Idxs)) return FC; // Fold a few common cases. + assert(GetElementPtrInst::getIndexedType(Ty, Idxs) && + "GEP indices invalid!");; + // Get the result type of the getelementptr! - Type *DestTy = GetElementPtrInst::getIndexedType(Ty, Idxs); - assert(DestTy && "GEP indices invalid!"); - unsigned AS = OrigPtrTy->getAddressSpace(); - Type *ReqTy = OrigPtrTy->isOpaque() - ? PointerType::get(OrigPtrTy->getContext(), AS) - : DestTy->getPointerTo(AS); + Type *ReqTy = GetElementPtrInst::getGEPReturnType(C, Idxs); + if (OnlyIfReducedTy == ReqTy) + return nullptr; auto EltCount = ElementCount::getFixed(0); - if (VectorType *VecTy = dyn_cast(C->getType())) + if (VectorType *VecTy = dyn_cast(ReqTy)) EltCount = VecTy->getElementCount(); - else - for (auto *Idx : Idxs) - if (VectorType *VecTy = dyn_cast(Idx->getType())) - EltCount = VecTy->getElementCount(); - - if (EltCount.isNonZero()) - ReqTy = VectorType::get(ReqTy, EltCount); - - if (OnlyIfReducedTy == ReqTy) - return nullptr; // Look up the constant in the table first to ensure uniqueness std::vector ArgVec;