[PATCH] D88782: [MemorySSA] Use provided memory location even if instruction is call

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 3 11:02:27 PDT 2020


nikic updated this revision to Diff 295992.
nikic retitled this revision from "[MemorySSA] Consistently handle lifetime.start clobbers" to "[MemorySSA] Use provided memory location even if instruction is call".
nikic edited the summary of this revision.
nikic added a comment.

Fix the underlying problem. Ran into this with lifetime intrinsics, but it's really something that affects all calls.


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

https://reviews.llvm.org/D88782

Files:
  llvm/lib/Analysis/MemorySSA.cpp
  llvm/unittests/Analysis/MemorySSATest.cpp


Index: llvm/unittests/Analysis/MemorySSATest.cpp
===================================================================
--- llvm/unittests/Analysis/MemorySSATest.cpp
+++ llvm/unittests/Analysis/MemorySSATest.cpp
@@ -1205,8 +1205,8 @@
   //   %bar = getelementptr i8, i8* %foo, i64 1
   //   store i8 0, i8* %foo
   //   store i8 0, i8* %bar
-  //   call void @llvm.lifetime.end.p0i8(i64 8, i32* %p)
-  //   call void @llvm.lifetime.start.p0i8(i64 8, i32* %p)
+  //   call void @llvm.lifetime.end.p0i8(i64 8, i32* %foo)
+  //   call void @llvm.lifetime.start.p0i8(i64 8, i32* %foo)
   //   store i8 0, i8* %foo
   //   store i8 0, i8* %bar
   //   ret void
@@ -1263,6 +1263,11 @@
   MemoryAccess *BarClobber =
       MSSA.getWalker()->getClobberingMemoryAccess(BarAccess);
   EXPECT_EQ(BarClobber, LifetimeStartAccess);
+
+  MemoryAccess *LifetimeStartClobber =
+      MSSA.getWalker()->getClobberingMemoryAccess(
+          LifetimeStartAccess, MemoryLocation(Foo));
+  EXPECT_EQ(LifetimeStartClobber, LifetimeStartAccess);
 }
 
 TEST_F(MemorySSATest, DefOptimizationsAreInvalidatedOnMoving) {
Index: llvm/lib/Analysis/MemorySSA.cpp
===================================================================
--- llvm/lib/Analysis/MemorySSA.cpp
+++ llvm/lib/Analysis/MemorySSA.cpp
@@ -261,10 +261,10 @@
 template <typename AliasAnalysisType>
 static ClobberAlias
 instructionClobbersQuery(const MemoryDef *MD, const MemoryLocation &UseLoc,
-                         const Instruction *UseInst, AliasAnalysisType &AA) {
+                         const Instruction *UseInst, bool IsCall,
+                         AliasAnalysisType &AA) {
   Instruction *DefInst = MD->getMemoryInst();
   assert(DefInst && "Defining instruction not actually an instruction");
-  const auto *UseCall = dyn_cast<CallBase>(UseInst);
   Optional<AliasResult> AR;
 
   if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(DefInst)) {
@@ -277,7 +277,7 @@
     // context.
     switch (II->getIntrinsicID()) {
     case Intrinsic::lifetime_start:
-      if (UseCall)
+      if (IsCall)
         return {false, NoAlias};
       AR = AA.alias(MemoryLocation(II->getArgOperand(1)), UseLoc);
       return {AR != NoAlias, AR};
@@ -296,8 +296,8 @@
     }
   }
 
-  if (UseCall) {
-    ModRefInfo I = AA.getModRefInfo(DefInst, UseCall);
+  if (IsCall) {
+    ModRefInfo I = AA.getModRefInfo(DefInst, cast<CallBase>(UseInst));
     AR = isMustSet(I) ? MustAlias : MayAlias;
     return {isModOrRefSet(I), AR};
   }
@@ -320,9 +320,9 @@
   // to exist while MemoryLocOrCall is pushed through places.
   if (UseMLOC.IsCall)
     return instructionClobbersQuery(MD, MemoryLocation(), MU->getMemoryInst(),
-                                    AA);
+                                    UseMLOC.IsCall, AA);
   return instructionClobbersQuery(MD, UseMLOC.getLoc(), MU->getMemoryInst(),
-                                  AA);
+                                  UseMLOC.IsCall, AA);
 }
 
 // Return true when MD may alias MU, return false otherwise.
@@ -587,7 +587,8 @@
           return {Current, true, MayAlias};
 
         ClobberAlias CA =
-            instructionClobbersQuery(MD, Desc.Loc, Query->Inst, AA);
+            instructionClobbersQuery(MD, Desc.Loc, Query->Inst, Query->IsCall,
+                                     AA);
         if (CA.IsClobber)
           return {MD, true, CA.AR};
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88782.295992.patch
Type: text/x-patch
Size: 3360 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201003/b577072d/attachment.bin>


More information about the llvm-commits mailing list