[llvm] b13f280 - [IR] Remove typed pointer handling from getGEPReturnType() (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 18 03:29:05 PDT 2023
Author: Nikita Popov
Date: 2023-07-18T12:28:53+02:00
New Revision: b13f280538cfd6a97bbbed24408e2524de7cc093
URL: https://github.com/llvm/llvm-project/commit/b13f280538cfd6a97bbbed24408e2524de7cc093
DIFF: https://github.com/llvm/llvm-project/commit/b13f280538cfd6a97bbbed24408e2524de7cc093.diff
LOG: [IR] Remove typed pointer handling from getGEPReturnType() (NFC)
Added:
Modified:
llvm/include/llvm/IR/Instructions.h
llvm/lib/IR/ConstantFold.cpp
llvm/lib/IR/IRBuilder.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index a71d7d0529f146..8d60384e1a32fc 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -1077,26 +1077,19 @@ class GetElementPtrInst : public Instruction {
/// Returns the pointer type returned by the GEP
/// instruction, which may be a vector of pointers.
- static Type *getGEPReturnType(Type *ElTy, Value *Ptr,
- ArrayRef<Value *> IdxList) {
- PointerType *OrigPtrTy = cast<PointerType>(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<Value *> IdxList) {
// Vector GEP
- if (auto *PtrVTy = dyn_cast<VectorType>(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<VectorType>(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<Value *> IdxList, unsigned Values,
const Twine &NameStr,
Instruction *InsertBefore)
- : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
+ : Instruction(getGEPReturnType(Ptr, IdxList), GetElementPtr,
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
Values, InsertBefore),
SourceElementType(PointeeType),
@@ -1166,7 +1159,7 @@ GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
ArrayRef<Value *> IdxList, unsigned Values,
const Twine &NameStr,
BasicBlock *InsertAtEnd)
- : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
+ : Instruction(getGEPReturnType(Ptr, IdxList), GetElementPtr,
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
Values, InsertAtEnd),
SourceElementType(PointeeType),
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 20e2882837d13d..4c3325063c09d0 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<PoisonValue>(C))
return PoisonValue::get(GEPTy);
diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp
index 5262bc6b647f9e..094819dc39b586 100644
--- a/llvm/lib/IR/IRBuilder.cpp
+++ b/llvm/lib/IR/IRBuilder.cpp
@@ -1260,8 +1260,7 @@ Value *IRBuilderBase::CreatePreserveArrayAccessIndex(
SmallVector<Value *, 4> 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(
More information about the llvm-commits
mailing list