<div dir="ltr">Fails with asan, Sam is going to revert.</div><br><div class="gmail_quote"><div dir="ltr">On Sat, Jan 28, 2017 at 3:34 AM Daniel Berlin via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: dannyb<br class="gmail_msg">
Date: Fri Jan 27 20:22:52 2017<br class="gmail_msg">
New Revision: 293361<br class="gmail_msg">
<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=293361&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=293361&view=rev</a><br class="gmail_msg">
Log:<br class="gmail_msg">
MemorySSA: Fix block numbering invalidation and replacement bugs discovered by updater<br class="gmail_msg">
<br class="gmail_msg">
Modified:<br class="gmail_msg">
    llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp<br class="gmail_msg">
    llvm/trunk/lib/Transforms/Utils/MemorySSAUpdater.cpp<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp?rev=293361&r1=293360&r2=293361&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp?rev=293361&r1=293360&r2=293361&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp (original)<br class="gmail_msg">
+++ llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp Fri Jan 27 20:22:52 2017<br class="gmail_msg">
@@ -1597,6 +1597,7 @@ void MemorySSA::insertIntoListsForBlock(<br class="gmail_msg">
       Defs->push_back(*NewAccess);<br class="gmail_msg">
     }<br class="gmail_msg">
   }<br class="gmail_msg">
+  BlockNumberingValid.erase(BB);<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
 void MemorySSA::insertIntoListsBefore(MemoryAccess *What, const BasicBlock *BB,<br class="gmail_msg">
@@ -1624,6 +1625,7 @@ void MemorySSA::insertIntoListsBefore(Me<br class="gmail_msg">
         Defs->insert(InsertPt->getDefsIterator(), *What);<br class="gmail_msg">
     }<br class="gmail_msg">
   }<br class="gmail_msg">
+  BlockNumberingValid.erase(BB);<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
 // Move What before Where in the IR.  The end result is taht What will belong to<br class="gmail_msg">
@@ -1638,13 +1640,19 @@ void MemorySSA::moveTo(MemoryUseOrDef *W<br class="gmail_msg">
   insertIntoListsBefore(What, BB, Where);<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
+void MemorySSA::moveTo(MemoryUseOrDef *What, BasicBlock *BB,<br class="gmail_msg">
+                       InsertionPlace Point) {<br class="gmail_msg">
+  removeFromLists(What, false);<br class="gmail_msg">
+  What->setBlock(BB);<br class="gmail_msg">
+  insertIntoListsForBlock(What, BB, Point);<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
 MemoryPhi *MemorySSA::createMemoryPhi(BasicBlock *BB) {<br class="gmail_msg">
   assert(!getMemoryAccess(BB) && "MemoryPhi already exists for this BB");<br class="gmail_msg">
   MemoryPhi *Phi = new MemoryPhi(BB->getContext(), BB, NextID++);<br class="gmail_msg">
+  // Phi's always are placed at the front of the block.<br class="gmail_msg">
   insertIntoListsForBlock(Phi, BB, Beginning);<br class="gmail_msg">
   ValueToMemoryAccess[BB] = Phi;<br class="gmail_msg">
-  // Phi's always are placed at the front of the block.<br class="gmail_msg">
-  BlockNumberingValid.erase(BB);<br class="gmail_msg">
   return Phi;<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
@@ -1665,7 +1673,6 @@ MemoryAccess *MemorySSA::createMemoryAcc<br class="gmail_msg">
                                                 InsertionPlace Point) {<br class="gmail_msg">
   MemoryUseOrDef *NewAccess = createDefinedAccess(I, Definition);<br class="gmail_msg">
   insertIntoListsForBlock(NewAccess, BB, Point);<br class="gmail_msg">
-  BlockNumberingValid.erase(BB);<br class="gmail_msg">
   return NewAccess;<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
@@ -1675,7 +1682,6 @@ MemoryUseOrDef *MemorySSA::createMemoryA<br class="gmail_msg">
   assert(I->getParent() == InsertPt->getBlock() &&<br class="gmail_msg">
          "New and old access must be in the same block");<br class="gmail_msg">
   MemoryUseOrDef *NewAccess = createDefinedAccess(I, Definition);<br class="gmail_msg">
-  BlockNumberingValid.erase(InsertPt->getBlock());<br class="gmail_msg">
   insertIntoListsBefore(NewAccess, InsertPt->getBlock(),<br class="gmail_msg">
                         InsertPt->getIterator());<br class="gmail_msg">
   return NewAccess;<br class="gmail_msg">
@@ -1687,7 +1693,6 @@ MemoryUseOrDef *MemorySSA::createMemoryA<br class="gmail_msg">
   assert(I->getParent() == InsertPt->getBlock() &&<br class="gmail_msg">
          "New and old access must be in the same block");<br class="gmail_msg">
   MemoryUseOrDef *NewAccess = createDefinedAccess(I, Definition);<br class="gmail_msg">
-  BlockNumberingValid.erase(InsertPt->getBlock());<br class="gmail_msg">
   insertIntoListsBefore(NewAccess, InsertPt->getBlock(),<br class="gmail_msg">
                         ++(InsertPt->getIterator()));<br class="gmail_msg">
   return NewAccess;<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/lib/Transforms/Utils/MemorySSAUpdater.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/MemorySSAUpdater.cpp?rev=293361&r1=293360&r2=293361&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/MemorySSAUpdater.cpp?rev=293361&r1=293360&r2=293361&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/lib/Transforms/Utils/MemorySSAUpdater.cpp (original)<br class="gmail_msg">
+++ llvm/trunk/lib/Transforms/Utils/MemorySSAUpdater.cpp Fri Jan 27 20:22:52 2017<br class="gmail_msg">
@@ -243,13 +243,17 @@ void MemorySSAUpdater::insertDef(MemoryD<br class="gmail_msg">
   // of that thing with us, since we are in the way of whatever was there<br class="gmail_msg">
   // before.<br class="gmail_msg">
   // We now define that def's memorydefs and memoryphis<br class="gmail_msg">
-  for (auto UI = DefBefore->use_begin(), UE = DefBefore->use_end(); UI != UE;) {<br class="gmail_msg">
-    Use &U = *UI++;<br class="gmail_msg">
-    // Leave the uses alone<br class="gmail_msg">
-    if (isa<MemoryUse>(U.getUser()))<br class="gmail_msg">
-      continue;<br class="gmail_msg">
-    U.set(MD);<br class="gmail_msg">
+  if (DefBeforeSameBlock) {<br class="gmail_msg">
+    for (auto UI = DefBefore->use_begin(), UE = DefBefore->use_end();<br class="gmail_msg">
+         UI != UE;) {<br class="gmail_msg">
+      Use &U = *UI++;<br class="gmail_msg">
+      // Leave the uses alone<br class="gmail_msg">
+      if (isa<MemoryUse>(U.getUser()))<br class="gmail_msg">
+        continue;<br class="gmail_msg">
+      U.set(MD);<br class="gmail_msg">
+    }<br class="gmail_msg">
   }<br class="gmail_msg">
+<br class="gmail_msg">
   // and that def is now our defining access.<br class="gmail_msg">
   // We change them in this order otherwise we will appear in the use list<br class="gmail_msg">
   // above and reset ourselves.<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
llvm-commits mailing list<br class="gmail_msg">
<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="gmail_msg">
</blockquote></div>