Skip to content

Commit 8efaf7a

Browse files
committed
[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.)
1 parent e299a42 commit 8efaf7a

File tree

1 file changed

+0
-33
lines changed

1 file changed

+0
-33
lines changed

llvm/lib/IR/ConstantFold.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,39 +1617,6 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
16171617
cast<VectorType>(GEPTy)->getElementCount(), C)
16181618
: C;
16191619

1620-
if (C->isNullValue()) {
1621-
bool isNull = true;
1622-
for (Value *Idx : Idxs)
1623-
if (!isa<UndefValue>(Idx) && !cast<Constant>(Idx)->isNullValue()) {
1624-
isNull = false;
1625-
break;
1626-
}
1627-
if (isNull) {
1628-
PointerType *PtrTy = cast<PointerType>(C->getType()->getScalarType());
1629-
Type *Ty = GetElementPtrInst::getIndexedType(PointeeTy, Idxs);
1630-
1631-
assert(Ty && "Invalid indices for GEP!");
1632-
Type *OrigGEPTy = PointerType::get(Ty, PtrTy->getAddressSpace());
1633-
Type *GEPTy = PointerType::get(Ty, PtrTy->getAddressSpace());
1634-
if (VectorType *VT = dyn_cast<VectorType>(C->getType()))
1635-
GEPTy = VectorType::get(OrigGEPTy, VT->getElementCount());
1636-
1637-
// The GEP returns a vector of pointers when one of more of
1638-
// its arguments is a vector.
1639-
for (Value *Idx : Idxs) {
1640-
if (auto *VT = dyn_cast<VectorType>(Idx->getType())) {
1641-
assert((!isa<VectorType>(GEPTy) || isa<ScalableVectorType>(GEPTy) ==
1642-
isa<ScalableVectorType>(VT)) &&
1643-
"Mismatched GEPTy vector types");
1644-
GEPTy = VectorType::get(OrigGEPTy, VT->getElementCount());
1645-
break;
1646-
}
1647-
}
1648-
1649-
return Constant::getNullValue(GEPTy);
1650-
}
1651-
}
1652-
16531620
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
16541621
if (auto *GEP = dyn_cast<GEPOperator>(CE))
16551622
if (Constant *C = foldGEPOfGEP(GEP, PointeeTy, InBounds, Idxs))

0 commit comments

Comments
 (0)