aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Constants.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-07-18 12:37:35 +0200
committerNikita Popov <npopov@redhat.com>2023-07-18 14:11:38 +0200
commiteadbc4b004b6f5bcd67f17b1d79c9955bd410fb8 (patch)
treea11f933c12f2678da0adbadeb61cfe8a29505e4d /llvm/lib/IR/Constants.cpp
parentc24f0f9bd6f4261d3ebdb34cbf4634026be0f2dc (diff)
downloadllvm-eadbc4b004b6f5bcd67f17b1d79c9955bd410fb8.zip
llvm-eadbc4b004b6f5bcd67f17b1d79c9955bd410fb8.tar.gz
llvm-eadbc4b004b6f5bcd67f17b1d79c9955bd410fb8.tar.bz2
[Constants] Use getGEPReturnType() (NFC)
This reimplements essentially the same logic.
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r--llvm/lib/IR/Constants.cpp25
1 files changed, 7 insertions, 18 deletions
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<Value *> Idxs, bool InBounds,
std::optional<unsigned> InRangeIndex,
Type *OnlyIfReducedTy) {
- PointerType *OrigPtrTy = cast<PointerType>(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<VectorType>(C->getType()))
+ if (VectorType *VecTy = dyn_cast<VectorType>(ReqTy))
EltCount = VecTy->getElementCount();
- else
- for (auto *Idx : Idxs)
- if (VectorType *VecTy = dyn_cast<VectorType>(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<Constant*> ArgVec;