Skip to content

Commit d3f9de6

Browse files
committed
Simplify check for at most one variable index
1 parent 79c3ce2 commit d3f9de6

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ static bool canRewriteGEPAsOffset(Value *Start, Value *Base,
419419
SetVector<Value *> &Explored) {
420420
SmallVector<Value *, 16> WorkList(1, Start);
421421
Explored.insert(Base);
422-
uint64_t IndexSize = DL.getIndexTypeSizeInBits(Start->getType());
423422

424423
// The following traversal gives us an order which can be used
425424
// when doing the final transformation. Since in the final
@@ -450,10 +449,8 @@ static bool canRewriteGEPAsOffset(Value *Start, Value *Base,
450449

451450
if (auto *GEP = dyn_cast<GEPOperator>(V)) {
452451
// Only allow GEPs with at most one variable offset.
453-
APInt Offset(IndexSize, 0);
454-
MapVector<Value *, APInt> VarOffsets;
455-
if (!GEP->collectOffset(DL, IndexSize, VarOffsets, Offset) ||
456-
VarOffsets.size() > 1)
452+
auto IsNonConst = [](Value *V) { return !isa<ConstantInt>(V); };
453+
if (count_if(GEP->indices(), IsNonConst) > 1)
457454
return false;
458455

459456
if (!Explored.contains(GEP->getOperand(0)))

0 commit comments

Comments
 (0)