[llvm] [InstCombine] Make indexed compare fold GEP source type independent (PR #71663)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 26 18:09:02 PST 2023
================
@@ -447,11 +448,9 @@ static bool canRewriteGEPAsOffset(Type *ElemTy, Value *Start, Value *Base,
return false;
if (auto *GEP = dyn_cast<GEPOperator>(V)) {
- // We're limiting the GEP to having one index. This will preserve
- // the original pointer type. We could handle more cases in the
- // future.
- if (GEP->getNumIndices() != 1 || !GEP->isInBounds() ||
- GEP->getSourceElementType() != ElemTy)
+ // Only allow GEPs with at most one variable offset.
+ auto IsNonConst = [](Value *V) { return !isa<ConstantInt>(V); };
+ if (count_if(GEP->indices(), IsNonConst) > 1)
----------------
dtcxzyw wrote:
Why did you drop the `!GEP->isInBounds()` check?
https://github.com/llvm/llvm-project/blob/b84cb9c2e672a39cb94f080b67c121ff5ae74879/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp#L685-L694
> We've only looked through inbouds GEPs we know that we can't have overflow on either side.
https://github.com/llvm/llvm-project/pull/71663
More information about the llvm-commits
mailing list