Skip to content

Commit 46b293c

Browse files
committed
[Attributor] Simplify offset calculation for a constant GEP
Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D132931
1 parent 607f14d commit 46b293c

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,26 +1280,15 @@ struct AAPointerInfoFloating : public AAPointerInfoImpl {
12801280
UsrOI = PtrOI;
12811281

12821282
// TODO: Use range information.
1283+
APInt GEPOffset(DL.getIndexTypeSizeInBits(GEP->getType()), 0);
12831284
if (PtrOI.Offset == OffsetAndSize::Unknown ||
1284-
!GEP->hasAllConstantIndices()) {
1285+
!GEP->accumulateConstantOffset(DL, GEPOffset)) {
12851286
UsrOI.Offset = OffsetAndSize::Unknown;
12861287
Follow = true;
12871288
return true;
12881289
}
12891290

1290-
SmallVector<Value *, 8> Indices;
1291-
for (Use &Idx : GEP->indices()) {
1292-
if (auto *CIdx = dyn_cast<ConstantInt>(Idx)) {
1293-
Indices.push_back(CIdx);
1294-
continue;
1295-
}
1296-
1297-
LLVM_DEBUG(dbgs() << "[AAPointerInfo] Non constant GEP index " << *GEP
1298-
<< " : " << *Idx << "\n");
1299-
return false;
1300-
}
1301-
UsrOI.Offset = PtrOI.Offset + DL.getIndexedOffsetInType(
1302-
GEP->getSourceElementType(), Indices);
1291+
UsrOI.Offset = PtrOI.Offset + GEPOffset.getZExtValue();
13031292
Follow = true;
13041293
return true;
13051294
}

0 commit comments

Comments
 (0)