diff options
author | Nikita Popov <npopov@redhat.com> | 2024-06-12 09:50:14 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2024-06-13 17:03:35 +0200 |
commit | cc2dc0916ad6a00ebc9373a58854d77cf73af122 (patch) | |
tree | e918c11b7c7875b5e35123e302c0f94b02fe970e /llvm/lib/IR/ConstantFold.cpp | |
parent | 3d35b94e3a9abcf5f703267c7653fd6ef39870b6 (diff) | |
download | llvm-cc2dc0916ad6a00ebc9373a58854d77cf73af122.zip llvm-cc2dc0916ad6a00ebc9373a58854d77cf73af122.tar.gz llvm-cc2dc0916ad6a00ebc9373a58854d77cf73af122.tar.bz2 |
Reapply [ConstantFold] Drop gep of gep fold entirely (#95126)
Reapplying without changes. The flang+openmp buildbot failure
should be addressed by https://github.com/llvm/llvm-project/pull/94541.
-----
This is a followup to https://github.com/llvm/llvm-project/pull/93823
and drops the DataLayout-unaware GEP of GEP fold entirely. All cases are
now left to the DataLayout-aware constant folder, which will fold
everything to a single i8 GEP.
We didn't have any test coverage for this fold in LLVM, but some Clang
tests change.
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 33 |
1 files changed, 0 insertions, 33 deletions
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; } |