[llvm] 6c745e0 - [Attributor][FIX] Ensure order for multiple references into map

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 8 16:13:33 PST 2022


Author: Johannes Doerfert
Date: 2022-01-08T16:59:21-06:00
New Revision: 6c745e04fac8241e1be6ef90a654228d4eb3ff2b

URL: https://github.com/llvm/llvm-project/commit/6c745e04fac8241e1be6ef90a654228d4eb3ff2b
DIFF: https://github.com/llvm/llvm-project/commit/6c745e04fac8241e1be6ef90a654228d4eb3ff2b.diff

LOG: [Attributor][FIX] Ensure order for multiple references into map

If we have multiple references into a map we need to ensure the ones
created late do not invalidate the ones created early. To do that we
need to make sure all but the first are not modifying the map, hence
for them the keys have to be present already.

Fixes #52875.

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 8bfa940449fb2..de7244ab27bde 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -1170,12 +1170,12 @@ struct AAPointerInfoFloating : public AAPointerInfoImpl {
       User *Usr = U.getUser();
       LLVM_DEBUG(dbgs() << "[AAPointerInfo] Analyze " << *CurPtr << " in "
                         << *Usr << "\n");
-
-      OffsetInfo &PtrOI = OffsetInfoMap[CurPtr];
+      assert(OffsetInfoMap.count(CurPtr) &&
+             "The current pointer offset should have been seeded!");
 
       if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Usr)) {
         if (CE->isCast())
-          return HandlePassthroughUser(Usr, PtrOI, Follow);
+          return HandlePassthroughUser(Usr, OffsetInfoMap[CurPtr], Follow);
         if (CE->isCompare())
           return true;
         if (!CE->isGEPWithNoNotionalOverIndexing()) {
@@ -1185,7 +1185,10 @@ struct AAPointerInfoFloating : public AAPointerInfoImpl {
         }
       }
       if (auto *GEP = dyn_cast<GEPOperator>(Usr)) {
+        // Note the order here, the Usr access might change the map, CurPtr is
+        // already in it though.
         OffsetInfo &UsrOI = OffsetInfoMap[Usr];
+        OffsetInfo &PtrOI = OffsetInfoMap[CurPtr];
         UsrOI = PtrOI;
 
         // TODO: Use range information.
@@ -1214,14 +1217,17 @@ struct AAPointerInfoFloating : public AAPointerInfoImpl {
         return true;
       }
       if (isa<CastInst>(Usr) || isa<SelectInst>(Usr))
-        return HandlePassthroughUser(Usr, PtrOI, Follow);
+        return HandlePassthroughUser(Usr, OffsetInfoMap[CurPtr], Follow);
 
       // For PHIs we need to take care of the recurrence explicitly as the value
       // might change while we iterate through a loop. For now, we give up if
       // the PHI is not invariant.
       if (isa<PHINode>(Usr)) {
-        // Check if the PHI is invariant (so far).
+        // Note the order here, the Usr access might change the map, CurPtr is
+        // already in it though.
         OffsetInfo &UsrOI = OffsetInfoMap[Usr];
+        OffsetInfo &PtrOI = OffsetInfoMap[CurPtr];
+        // Check if the PHI is invariant (so far).
         if (UsrOI == PtrOI)
           return true;
 
@@ -1261,8 +1267,8 @@ struct AAPointerInfoFloating : public AAPointerInfoImpl {
 
       if (auto *LoadI = dyn_cast<LoadInst>(Usr))
         return handleAccess(A, *LoadI, *CurPtr, /* Content */ nullptr,
-                            AccessKind::AK_READ, PtrOI.Offset, Changed,
-                            LoadI->getType());
+                            AccessKind::AK_READ, OffsetInfoMap[CurPtr].Offset,
+                            Changed, LoadI->getType());
       if (auto *StoreI = dyn_cast<StoreInst>(Usr)) {
         if (StoreI->getValueOperand() == CurPtr) {
           LLVM_DEBUG(dbgs() << "[AAPointerInfo] Escaping use in store "
@@ -1273,7 +1279,7 @@ struct AAPointerInfoFloating : public AAPointerInfoImpl {
         Optional<Value *> Content = A.getAssumedSimplified(
             *StoreI->getValueOperand(), *this, UsedAssumedInformation);
         return handleAccess(A, *StoreI, *CurPtr, Content, AccessKind::AK_WRITE,
-                            PtrOI.Offset, Changed,
+                            OffsetInfoMap[CurPtr].Offset, Changed,
                             StoreI->getValueOperand()->getType());
       }
       if (auto *CB = dyn_cast<CallBase>(Usr)) {
@@ -1286,7 +1292,8 @@ struct AAPointerInfoFloating : public AAPointerInfoImpl {
           const auto &CSArgPI = A.getAAFor<AAPointerInfo>(
               *this, IRPosition::callsite_argument(*CB, ArgNo),
               DepClassTy::REQUIRED);
-          Changed = translateAndAddCalleeState(A, CSArgPI, PtrOI.Offset, *CB) |
+          Changed = translateAndAddCalleeState(
+                        A, CSArgPI, OffsetInfoMap[CurPtr].Offset, *CB) |
                     Changed;
           return true;
         }


        


More information about the llvm-commits mailing list