[PATCH] D23411: Fix PR 28933

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 11 10:44:42 PDT 2016


dberlin created this revision.
dberlin added a reviewer: sebpop.
dberlin added subscribers: george.burgess.iv, llvm-commits.

This fixes PR 28933 by making sure GVNHoist does not try to recreate memory
accesses when it has not actually moved them.

https://reviews.llvm.org/D23411

Files:
  lib/Transforms/Scalar/GVNHoist.cpp

Index: lib/Transforms/Scalar/GVNHoist.cpp
===================================================================
--- lib/Transforms/Scalar/GVNHoist.cpp
+++ lib/Transforms/Scalar/GVNHoist.cpp
@@ -739,11 +739,12 @@
           // of the second based on the first.
           if (!Repl || firstInBB(I, Repl))
             Repl = I;
-
+      bool MoveAccess = true;
       if (Repl) {
         // Repl is already in HoistPt: it remains in place.
         assert(allOperandsAvailable(Repl, HoistPt) &&
                "instruction depends on operands that are not available");
+        MoveAccess = false;
       } else {
         // When we do not find Repl in HoistPt, select the first in the list
         // and move it to HoistPt.
@@ -772,16 +773,20 @@
       }
 
       MemoryAccess *NewMemAcc = nullptr;
-      if (MemoryAccess *MA = MSSA->getMemoryAccess(Repl)) {
-        if (MemoryUseOrDef *OldMemAcc = dyn_cast<MemoryUseOrDef>(MA)) {
-          // The definition of this ld/st will not change: ld/st hoisting is
-          // legal when the ld/st is not moved past its current definition.
-          MemoryAccess *Def = OldMemAcc->getDefiningAccess();
-          NewMemAcc = MSSA->createMemoryAccessInBB(Repl, Def, HoistPt,
-                                                   MemorySSA::End);
-          OldMemAcc->replaceAllUsesWith(NewMemAcc);
-          MSSA->removeMemoryAccess(OldMemAcc);
+      if (MoveAccess) {
+        if (MemoryAccess *MA = MSSA->getMemoryAccess(Repl)) {
+          if (MemoryUseOrDef *OldMemAcc = dyn_cast<MemoryUseOrDef>(MA)) {
+            // The definition of this ld/st will not change: ld/st hoisting is
+            // legal when the ld/st is not moved past its current definition.
+            MemoryAccess *Def = OldMemAcc->getDefiningAccess();
+            NewMemAcc = MSSA->createMemoryAccessInBB(Repl, Def, HoistPt,
+                                                     MemorySSA::End);
+            OldMemAcc->replaceAllUsesWith(NewMemAcc);
+            MSSA->removeMemoryAccess(OldMemAcc);
+          }
         }
+      } else {
+        NewMemAcc = MSSA->getMemoryAccess(Repl);
       }
 
       if (isa<LoadInst>(Repl))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23411.67707.patch
Type: text/x-patch
Size: 2166 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160811/05d5e513/attachment.bin>


More information about the llvm-commits mailing list