[llvm] [SeparateConstOffsetFromGEP] Support multiple indices in reorderGEP (PR #92339)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu May 16 01:57:25 PDT 2024
================
@@ -997,14 +992,12 @@ bool SeparateConstOffsetFromGEP::reorderGEP(GetElementPtrInst *GEP,
bool PtrGEPInBounds = PtrGEP->isInBounds();
bool IsChainInBounds = GEPInBounds && PtrGEPInBounds;
if (IsChainInBounds) {
- auto GEPIdx = GEP->indices().begin();
- auto KnownGEPIdx = computeKnownBits(GEPIdx->get(), *DL);
- IsChainInBounds &= KnownGEPIdx.isNonNegative();
- if (IsChainInBounds) {
- auto PtrGEPIdx = PtrGEP->indices().begin();
- auto KnownPtrGEPIdx = computeKnownBits(PtrGEPIdx->get(), *DL);
- IsChainInBounds &= KnownPtrGEPIdx.isNonNegative();
- }
+ auto IsKnownNonNegative = [&](Value *V) {
+ return isKnownNonNegative(V, *DL);
+ };
+ IsChainInBounds &= all_of(GEP->indices(), IsKnownNonNegative);
+ if (IsChainInBounds)
+ IsChainInBounds &= all_of(PtrGEP->indices(), IsKnownNonNegative);
----------------
jayfoad wrote:
Does this work? I'm never sure how flexible `concat` is.
```suggestion
IsChainInBounds &= all_of(concat(GEP->indices(), PtrGEP->indices()), IsKnownNonNegative);
```
https://github.com/llvm/llvm-project/pull/92339
More information about the llvm-commits
mailing list