aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantFold.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-11-03 14:33:01 +0100
committerNikita Popov <npopov@redhat.com>2023-11-03 14:33:01 +0100
commit8efaf7a518fa3cf719cdeff3917b9fedf8f2cf19 (patch)
treebe69e23bf29a4c6fbc48a2d5c4dd762d93a6d030 /llvm/lib/IR/ConstantFold.cpp
parente299a4287018769b9dfdd1eea8609bb59423ae90 (diff)
downloadllvm-8efaf7a518fa3cf719cdeff3917b9fedf8f2cf19.zip
llvm-8efaf7a518fa3cf719cdeff3917b9fedf8f2cf19.tar.gz
llvm-8efaf7a518fa3cf719cdeff3917b9fedf8f2cf19.tar.bz2
[ConstantFold] Remove redundant zero index gep fold (NFCI)
We already handle the more general case of zero index GEPs above, so we don't need to also handle GEPs with null based and zero indices. (Strictly speaking, this code could handle the special case of an inrange gep with null base and zero indices, but that has no practical relevance.)
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp33
1 files changed, 0 insertions, 33 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index f877fb6..0358f99 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -1617,39 +1617,6 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
cast<VectorType>(GEPTy)->getElementCount(), C)
: C;
- if (C->isNullValue()) {
- bool isNull = true;
- for (Value *Idx : Idxs)
- if (!isa<UndefValue>(Idx) && !cast<Constant>(Idx)->isNullValue()) {
- isNull = false;
- break;
- }
- if (isNull) {
- PointerType *PtrTy = cast<PointerType>(C->getType()->getScalarType());
- Type *Ty = GetElementPtrInst::getIndexedType(PointeeTy, Idxs);
-
- assert(Ty && "Invalid indices for GEP!");
- Type *OrigGEPTy = PointerType::get(Ty, PtrTy->getAddressSpace());
- Type *GEPTy = PointerType::get(Ty, PtrTy->getAddressSpace());
- if (VectorType *VT = dyn_cast<VectorType>(C->getType()))
- GEPTy = VectorType::get(OrigGEPTy, VT->getElementCount());
-
- // The GEP returns a vector of pointers when one of more of
- // its arguments is a vector.
- for (Value *Idx : Idxs) {
- if (auto *VT = dyn_cast<VectorType>(Idx->getType())) {
- assert((!isa<VectorType>(GEPTy) || isa<ScalableVectorType>(GEPTy) ==
- isa<ScalableVectorType>(VT)) &&
- "Mismatched GEPTy vector types");
- GEPTy = VectorType::get(OrigGEPTy, VT->getElementCount());
- break;
- }
- }
-
- return Constant::getNullValue(GEPTy);
- }
- }
-
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
if (auto *GEP = dyn_cast<GEPOperator>(CE))
if (Constant *C = foldGEPOfGEP(GEP, PointeeTy, InBounds, Idxs))