[llvm] 46b293c - [Attributor] Simplify offset calculation for a constant GEP

Sameer Sahasrabuddhe via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 2 11:24:38 PDT 2022


Author: Sameer Sahasrabuddhe
Date: 2022-09-02T23:53:51+05:30
New Revision: 46b293cb3f8d29ed4626c987c38190b54d558cce

URL: https://github.com/llvm/llvm-project/commit/46b293cb3f8d29ed4626c987c38190b54d558cce
DIFF: https://github.com/llvm/llvm-project/commit/46b293cb3f8d29ed4626c987c38190b54d558cce.diff

LOG: [Attributor] Simplify offset calculation for a constant GEP

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D132931

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 26720829756a5..d94a651a770af 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<Value *, 8> Indices;
-        for (Use &Idx : GEP->indices()) {
-          if (auto *CIdx = dyn_cast<ConstantInt>(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;
       }


        


More information about the llvm-commits mailing list