From: Nikita Popov Date: Tue, 18 Jul 2023 10:17:29 +0000 (+0200) Subject: [IR] Remove typed pointer handling from getGEPReturnType() (NFC) X-Git-Tag: upstream/17.0.6~1372 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b13f280538cfd6a97bbbed24408e2524de7cc093;p=platform%2Fupstream%2Fllvm.git [IR] Remove typed pointer handling from getGEPReturnType() (NFC) --- diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h index a71d7d0..8d60384 100644 --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -1077,26 +1077,19 @@ public: /// Returns the pointer type returned by the GEP /// instruction, which may be a vector of pointers. - static Type *getGEPReturnType(Type *ElTy, Value *Ptr, - ArrayRef IdxList) { - PointerType *OrigPtrTy = cast(Ptr->getType()->getScalarType()); - unsigned AddrSpace = OrigPtrTy->getAddressSpace(); - Type *ResultElemTy = checkGEPType(getIndexedType(ElTy, IdxList)); - Type *PtrTy = OrigPtrTy->isOpaque() - ? PointerType::get(OrigPtrTy->getContext(), AddrSpace) - : PointerType::get(ResultElemTy, AddrSpace); + static Type *getGEPReturnType(Value *Ptr, ArrayRef IdxList) { // Vector GEP - if (auto *PtrVTy = dyn_cast(Ptr->getType())) { - ElementCount EltCount = PtrVTy->getElementCount(); - return VectorType::get(PtrTy, EltCount); - } + Type *Ty = Ptr->getType(); + if (Ty->isVectorTy()) + return Ty; + for (Value *Index : IdxList) if (auto *IndexVTy = dyn_cast(Index->getType())) { ElementCount EltCount = IndexVTy->getElementCount(); - return VectorType::get(PtrTy, EltCount); + return VectorType::get(Ty, EltCount); } // Scalar GEP - return PtrTy; + return Ty; } unsigned getNumIndices() const { // Note: always non-negative @@ -1154,7 +1147,7 @@ GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr, ArrayRef IdxList, unsigned Values, const Twine &NameStr, Instruction *InsertBefore) - : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr, + : Instruction(getGEPReturnType(Ptr, IdxList), GetElementPtr, OperandTraits::op_end(this) - Values, Values, InsertBefore), SourceElementType(PointeeType), @@ -1166,7 +1159,7 @@ GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr, ArrayRef IdxList, unsigned Values, const Twine &NameStr, BasicBlock *InsertAtEnd) - : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr, + : Instruction(getGEPReturnType(Ptr, IdxList), GetElementPtr, OperandTraits::op_end(this) - Values, Values, InsertAtEnd), SourceElementType(PointeeType), diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 20e2882..4c33250 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -2000,7 +2000,7 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C, if (Idxs.empty()) return C; Type *GEPTy = GetElementPtrInst::getGEPReturnType( - PointeeTy, C, ArrayRef((Value *const *)Idxs.data(), Idxs.size())); + C, ArrayRef((Value *const *)Idxs.data(), Idxs.size())); if (isa(C)) return PoisonValue::get(GEPTy); diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp index 5262bc6..094819d 100644 --- a/llvm/lib/IR/IRBuilder.cpp +++ b/llvm/lib/IR/IRBuilder.cpp @@ -1260,8 +1260,7 @@ Value *IRBuilderBase::CreatePreserveArrayAccessIndex( SmallVector IdxList(Dimension, Zero); IdxList.push_back(LastIndexV); - Type *ResultType = - GetElementPtrInst::getGEPReturnType(ElTy, Base, IdxList); + Type *ResultType = GetElementPtrInst::getGEPReturnType(Base, IdxList); Module *M = BB->getParent()->getParent(); Function *FnPreserveArrayAccessIndex = Intrinsic::getDeclaration( @@ -1307,7 +1306,7 @@ Value *IRBuilderBase::CreatePreserveStructAccessIndex( Value *GEPIndex = getInt32(Index); Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0); Type *ResultType = - GetElementPtrInst::getGEPReturnType(ElTy, Base, {Zero, GEPIndex}); + GetElementPtrInst::getGEPReturnType(Base, {Zero, GEPIndex}); Module *M = BB->getParent()->getParent(); Function *FnPreserveStructAccessIndex = Intrinsic::getDeclaration(