diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 33 | ||||
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 3 |
3 files changed, 3 insertions, 38 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 8b2aa6b..0089586 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -5068,9 +5068,8 @@ static Value *simplifyGEPInst(Type *SrcTy, Value *Ptr, return nullptr; if (!ConstantExpr::isSupportedGetElementPtr(SrcTy)) - // TODO(gep_nowrap): Pass on the whole GEPNoWrapFlags. - return ConstantFoldGetElementPtr(SrcTy, cast<Constant>(Ptr), - NW.isInBounds(), std::nullopt, Indices); + return ConstantFoldGetElementPtr(SrcTy, cast<Constant>(Ptr), std::nullopt, + Indices); auto *CE = ConstantExpr::getGetElementPtr(SrcTy, cast<Constant>(Ptr), Indices, NW); diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 77a8336..34bcf36 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -1404,35 +1404,7 @@ Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, return nullptr; } -// Combine Indices - If the source pointer to this getelementptr instruction -// is a getelementptr instruction, combine the indices of the two -// getelementptr instructions into a single instruction. -static Constant *foldGEPOfGEP(GEPOperator *GEP, Type *PointeeTy, bool InBounds, - ArrayRef<Value *> Idxs) { - if (PointeeTy != GEP->getResultElementType()) - return nullptr; - - // Leave inrange handling to DL-aware constant folding. - if (GEP->getInRange()) - return nullptr; - - // Only handle simple case with leading zero index. We cannot perform an - // actual addition as we don't know the correct index type size to use. - Constant *Idx0 = cast<Constant>(Idxs[0]); - if (!Idx0->isNullValue()) - return nullptr; - - SmallVector<Value*, 16> NewIndices; - NewIndices.reserve(Idxs.size() + GEP->getNumIndices()); - NewIndices.append(GEP->idx_begin(), GEP->idx_end()); - NewIndices.append(Idxs.begin() + 1, Idxs.end()); - return ConstantExpr::getGetElementPtr( - GEP->getSourceElementType(), cast<Constant>(GEP->getPointerOperand()), - NewIndices, InBounds && GEP->isInBounds()); -} - Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C, - bool InBounds, std::optional<ConstantRange> InRange, ArrayRef<Value *> Idxs) { if (Idxs.empty()) return C; @@ -1462,10 +1434,5 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C, cast<VectorType>(GEPTy)->getElementCount(), C) : C; - if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) - if (auto *GEP = dyn_cast<GEPOperator>(CE)) - if (Constant *C = foldGEPOfGEP(GEP, PointeeTy, InBounds, Idxs)) - return C; - return nullptr; } diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index a76be44..d079073 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -2438,8 +2438,7 @@ Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C, assert(Ty && "Must specify element type"); assert(isSupportedGetElementPtr(Ty) && "Element type is unsupported!"); - if (Constant *FC = - ConstantFoldGetElementPtr(Ty, C, NW.isInBounds(), InRange, Idxs)) + if (Constant *FC = ConstantFoldGetElementPtr(Ty, C, InRange, Idxs)) return FC; // Fold a few common cases. assert(GetElementPtrInst::getIndexedType(Ty, Idxs) && "GEP indices invalid!"); |