From 46b293cb3f8d29ed4626c987c38190b54d558cce Mon Sep 17 00:00:00 2001 From: Sameer Sahasrabuddhe Date: Fri, 2 Sep 2022 23:53:51 +0530 Subject: [PATCH] [Attributor] Simplify offset calculation for a constant GEP Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D132931 --- llvm/lib/Transforms/IPO/AttributorAttributes.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index 2672082..d94a651 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -1280,26 +1280,15 @@ struct AAPointerInfoFloating : public AAPointerInfoImpl { UsrOI = PtrOI; // TODO: Use range information. + APInt GEPOffset(DL.getIndexTypeSizeInBits(GEP->getType()), 0); if (PtrOI.Offset == OffsetAndSize::Unknown || - !GEP->hasAllConstantIndices()) { + !GEP->accumulateConstantOffset(DL, GEPOffset)) { UsrOI.Offset = OffsetAndSize::Unknown; Follow = true; return true; } - SmallVector Indices; - for (Use &Idx : GEP->indices()) { - if (auto *CIdx = dyn_cast(Idx)) { - Indices.push_back(CIdx); - continue; - } - - LLVM_DEBUG(dbgs() << "[AAPointerInfo] Non constant GEP index " << *GEP - << " : " << *Idx << "\n"); - return false; - } - UsrOI.Offset = PtrOI.Offset + DL.getIndexedOffsetInType( - GEP->getSourceElementType(), Indices); + UsrOI.Offset = PtrOI.Offset + GEPOffset.getZExtValue(); Follow = true; return true; } -- 2.7.4