[llvm] 8efaf7a - [ConstantFold] Remove redundant zero index gep fold (NFCI)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 3 06:35:42 PDT 2023
Author: Nikita Popov
Date: 2023-11-03T14:33:01+01:00
New Revision: 8efaf7a518fa3cf719cdeff3917b9fedf8f2cf19
URL: https://github.com/llvm/llvm-project/commit/8efaf7a518fa3cf719cdeff3917b9fedf8f2cf19
DIFF: https://github.com/llvm/llvm-project/commit/8efaf7a518fa3cf719cdeff3917b9fedf8f2cf19.diff
LOG: [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.)
Added:
Modified:
llvm/lib/IR/ConstantFold.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index f877fb614c65da8..0358f996f285165 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))
More information about the llvm-commits
mailing list