[llvm] [InstCombine] Make indexed compare fold GEP source type independent (PR #71663)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 27 00:48: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)
----------------
nikic wrote:
Thanks for catching this! I've added some additional inbounds tests in https://github.com/llvm/llvm-project/commit/57a0a9aadf1ec4c111e303b7f0fe76505b3ad137 so we have coverage for this case and have restored the check.
https://github.com/llvm/llvm-project/pull/71663
More information about the llvm-commits
mailing list