<div dir="ltr">This needs a bunch of unit tests.<div>:)</div><div>Also, you need to invalidate BlockNumberingValid for the from and to blocks.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 14, 2016 at 11:17 PM, bryant <span dir="ltr"><<a href="mailto:3.14472+reviews.llvm.org@gmail.com" target="_blank">3.14472+reviews.llvm.org@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">bryant created this revision.<br>
bryant added reviewers: dberlin, george.burgess.iv, hfinkel.<br>
bryant added a subscriber: llvm-commits.<br>
bryant set the repository for this revision to rL LLVM.<br>
<br>
This defines an API endpoint that allows clients to move upwards a MemoryUse/Def<br>
*M to just before a MemoryDef *Dest, where Dest and M may reside in separate<br>
BasicBlocks. The following conditions must hold:<br>
<br>
- Dest must dominate M,<br>
- All MemoryAccesses between the Dest and M, as well as Dest itself, must be no-alias with M,<br>
- Dest is MemoryDef (this restriction could probably be lifted).<br>
<br>
These conditions allow the splice to be carried out with simple<br>
replaceAllUsesWith and setDefiningAccess operations. In particular, the first<br>
and second conditions are sufficient conditions for preservation of semantics.<br>
<br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D26661" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D26661</a><br>
<br>
Files:<br>
  include/llvm/Transforms/Utils/<wbr>MemorySSA.h<br>
  lib/Transforms/Utils/<wbr>MemorySSA.cpp<br>
<br>
<br>
Index: lib/Transforms/Utils/<wbr>MemorySSA.cpp<br>
==============================<wbr>==============================<wbr>=======<br>
--- lib/Transforms/Utils/<wbr>MemorySSA.cpp<br>
+++ lib/Transforms/Utils/<wbr>MemorySSA.cpp<br>
@@ -1614,6 +1614,25 @@<br>
   return NewAccess;<br>
 }<br>
<br>
+void MemorySSA::<wbr>spliceMemoryAccessAbove(<wbr>MemoryDef *Where,<br>
+                                        MemoryUseOrDef *What) {<br>
+  assert(What != getLiveOnEntryDef() &&<br>
+         Where != getLiveOnEntryDef() && "Can't splice (above) LOE.");<br>
+  assert(dominates(Where, What) && "Only upwards splices are permitted.");<br>
+<br>
+  if (Where == What)<br>
+    return;<br>
+  if (isa<MemoryDef>(What)) {<br>
+    // TODO: possibly use removeMemoryAccess' more efficient RAUW<br>
+    What->replaceAllUsesWith(What-<wbr>>getDefiningAccess());<br>
+    What->setDefiningAccess(Where-<wbr>>getDefiningAccess());<br>
+    Where->setDefiningAccess(What)<wbr>;<br>
+  }<br>
+  AccessList *Src = getWritableBlockAccesses(What-<wbr>>getBlock());<br>
+  AccessList *Dest = getWritableBlockAccesses(<wbr>Where->getBlock());<br>
+  Dest->splice(AccessList::<wbr>iterator(Where), *Src, What);<br>
+}<br>
+<br>
 /// \brief Helper function to create new memory accesses<br>
 MemoryUseOrDef *MemorySSA::createNewAccess(<wbr>Instruction *I) {<br>
   // The assume intrinsic has a control dependency which we model by claiming<br>
Index: include/llvm/Transforms/Utils/<wbr>MemorySSA.h<br>
==============================<wbr>==============================<wbr>=======<br>
--- include/llvm/Transforms/Utils/<wbr>MemorySSA.h<br>
+++ include/llvm/Transforms/Utils/<wbr>MemorySSA.h<br>
@@ -570,6 +570,15 @@<br>
                                           MemoryAccess *Definition,<br>
                                           MemoryAccess *InsertPt);<br>
<br>
+  // \brief Splice \p What to just before \p Where.<br>
+  //<br>
+  // In order to be efficient, the following conditions must be met:<br>
+  //   - \p Where  dominates \p What,<br>
+  //   - All memory accesses in [\p Where, \p What) are no-alias with \p What.<br>
+  //<br>
+  // TODO: relax the MemoryDef requirement on Where.<br>
+  void spliceMemoryAccessAbove(<wbr>MemoryDef *Where, MemoryUseOrDef *What);<br>
+<br>
   /// \brief Remove a MemoryAccess from MemorySSA, including updating all<br>
   /// definitions and uses.<br>
   /// This should be called when a memory instruction that has a MemoryAccess<br>
<br>
<br>
</blockquote></div><br></div>