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

luxufan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 18 23:26:55 PDT 2022


StephenFan created this revision.
StephenFan added reviewers: nikic, asbirlea.
Herald added a subscriber: george.burgess.iv.
Herald added a project: All.
StephenFan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

We set the Location size to beforeOrAfter if the Location value is not
guaranteed loop invariant. But in some cases, we need to reset the
location size if the location size is precise after phi tranlation of
location value. This will improve MemorySSA analysis results.


Repository:
  rG LLVM Github Monorepo

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
@@ -437,10 +437,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
@@ -1252,7 +1252,9 @@
       // 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(const_cast<Value *>(Location.Ptr)))
+      bool GuaranteedLoopInvariant =
+          IsGuaranteedLoopInvariant(const_cast<Value *>(Location.Ptr));
+      if (!GuaranteedLoopInvariant)
         CurrentPair.second =
             Location.getWithNewSize(LocationSize::beforeOrAfterPointer());
       PHITransAddr Translator(
@@ -1266,6 +1268,10 @@
         if (TransAddr != Location.Ptr) {
           CurrentPair.second = CurrentPair.second.getWithNewPtr(TransAddr);
 
+          if (!GuaranteedLoopInvariant && IsGuaranteedLoopInvariant(TransAddr))
+            CurrentPair.second =
+                CurrentPair.second.getWithNewSize(Location.Size);
+
           if (TransAddr &&
               !IsGuaranteedLoopInvariant(const_cast<Value *>(TransAddr)))
             CurrentPair.second = CurrentPair.second.getWithNewSize(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134161.461144.patch
Type: text/x-patch
Size: 2108 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220919/d69e95cf/attachment.bin>


More information about the llvm-commits mailing list