[PATCH] D134161: [MemorySSA] Reset location size if IsGuaranteedLoopInvariant after phi tranlation

luxufan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 21 23:51:30 PDT 2022


StephenFan updated this revision to Diff 462087.
StephenFan added a comment.

Thanks nikic for digging into to reduce the logic.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134161/new/

https://reviews.llvm.org/D134161

Files:
  llvm/include/llvm/Analysis/MemorySSA.h
  llvm/test/Analysis/MemorySSA/phi-translation.ll


Index: llvm/test/Analysis/MemorySSA/phi-translation.ll
===================================================================
--- llvm/test/Analysis/MemorySSA/phi-translation.ll
+++ llvm/test/Analysis/MemorySSA/phi-translation.ll
@@ -439,10 +439,10 @@
 ; CHECK-LABEL: merge:
 ; CHECK:       ; 3 = MemoryPhi({lhs,1},{rhs,2})
 ; CHECK-NEXT   %storemerge2 = phi i32 [ 2, %lhs ], [ 3, %rhs ]
-; TODO: Here the defining access could be liveOnEntry. Since all incoming
-; values of phi node can be phi translated.
-; CHECK:       ; MemoryUse(3)
-; CHECK-NEXT:    %lv = load i16, i16* %arrayidx, align 2
+; LIMIT:       ; MemoryUse(3)
+; LIMIT-NEXT:  %lv = load i16, i16* %arrayidx, align 2
+; NOLIMIT:     ; MemoryUse(liveOnEntry)
+; NOLIMIT-NEXT: %lv = load i16, i16* %arrayidx, align 2
 
 entry:
   br i1 %cmp, label %lhs, label %rhs
Index: llvm/include/llvm/Analysis/MemorySSA.h
===================================================================
--- llvm/include/llvm/Analysis/MemorySSA.h
+++ llvm/include/llvm/Analysis/MemorySSA.h
@@ -1245,31 +1245,24 @@
     CurrentPair.first = *DefIterator;
     CurrentPair.second = Location;
     if (WalkingPhi && Location.Ptr) {
-      // Mark size as unknown, if the location is not guaranteed to be
-      // loop-invariant for any possible loop in the function. Setting the size
-      // to unknown guarantees that any memory accesses that access locations
-      // after the pointer are considered as clobbers, which is important to
-      // catch loop carried dependences.
-      if (!IsGuaranteedLoopInvariant(Location.Ptr))
-        CurrentPair.second =
-            Location.getWithNewSize(LocationSize::beforeOrAfterPointer());
       PHITransAddr Translator(
           const_cast<Value *>(Location.Ptr),
           OriginalAccess->getBlock()->getModule()->getDataLayout(), nullptr);
 
       if (!Translator.PHITranslateValue(OriginalAccess->getBlock(),
-                                        DefIterator.getPhiArgBlock(), DT,
-                                        true)) {
-        Value *TransAddr = Translator.getAddr();
-        if (TransAddr != Location.Ptr) {
-          CurrentPair.second = CurrentPair.second.getWithNewPtr(TransAddr);
-
-          if (TransAddr &&
-              !IsGuaranteedLoopInvariant(TransAddr))
-            CurrentPair.second = CurrentPair.second.getWithNewSize(
-                LocationSize::beforeOrAfterPointer());
-        }
-      }
+                                        DefIterator.getPhiArgBlock(), DT, true))
+        if (Translator.getAddr() != CurrentPair.second.Ptr)
+          CurrentPair.second =
+              CurrentPair.second.getWithNewPtr(Translator.getAddr());
+
+      // Mark size as unknown, if the location is not guaranteed to be
+      // loop-invariant for any possible loop in the function. Setting the size
+      // to unknown guarantees that any memory accesses that access locations
+      // after the pointer are considered as clobbers, which is important to
+      // catch loop carried dependences.
+      if (!IsGuaranteedLoopInvariant(CurrentPair.second.Ptr))
+        CurrentPair.second = CurrentPair.second.getWithNewSize(
+            LocationSize::beforeOrAfterPointer());
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134161.462087.patch
Type: text/x-patch
Size: 3221 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220922/17d3f7f8/attachment.bin>


More information about the llvm-commits mailing list