[PATCH] D51563: [MemorySSA] Update MemoryPhi wiring for block splitting to consider if identical edges were merged.

Alina Sbirlea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 31 17:13:47 PDT 2018


asbirlea created this revision.
asbirlea added a reviewer: george.burgess.iv.
Herald added subscribers: Prazek, jlebar, sanjoy.

Block splitting is done with either identical edges being merged, or not.
Only critical edges can be split without merging identical edges based on an option.
Teach the memoryssa updater to take this into account: for the same edge between two blocks only move one entry from the Phi in Old to the new Phi in New.


Repository:
  rL LLVM

https://reviews.llvm.org/D51563

Files:
  include/llvm/Analysis/MemorySSAUpdater.h
  lib/Analysis/MemorySSAUpdater.cpp
  lib/Transforms/Utils/BreakCriticalEdges.cpp


Index: lib/Transforms/Utils/BreakCriticalEdges.cpp
===================================================================
--- lib/Transforms/Utils/BreakCriticalEdges.cpp
+++ lib/Transforms/Utils/BreakCriticalEdges.cpp
@@ -200,8 +200,10 @@
   auto *DT = Options.DT;
   auto *LI = Options.LI;
   auto *MSSAU = Options.MSSAU;
-  if (MSSAU)
-    MSSAU->wireOldPredecessorsToNewImmediatePredecessor(DestBB, NewBB, {TIBB});
+  if (MSSAU) {
+    MSSAU->wireOldPredecessorsToNewImmediatePredecessor(
+        DestBB, NewBB, {TIBB}, Options.MergeIdenticalEdges);
+  }
 
   if (!DT && !LI)
     return NewBB;
Index: lib/Analysis/MemorySSAUpdater.cpp
===================================================================
--- lib/Analysis/MemorySSAUpdater.cpp
+++ lib/Analysis/MemorySSAUpdater.cpp
@@ -1010,7 +1010,8 @@
 }
 
 void MemorySSAUpdater::wireOldPredecessorsToNewImmediatePredecessor(
-    BasicBlock *Old, BasicBlock *New, ArrayRef<BasicBlock *> Preds) {
+    BasicBlock *Old, BasicBlock *New, ArrayRef<BasicBlock *> Preds,
+    bool IdenticalEdgesWereMerged) {
   assert(!MSSA->getWritableBlockAccesses(New) &&
          "Access list should be null for a new block.");
   MemoryPhi *Phi = MSSA->getMemoryAccess(Old);
@@ -1028,6 +1029,8 @@
     Phi->unorderedDeleteIncomingIf([&](MemoryAccess *MA, BasicBlock *B) {
       if (PredsSet.count(B)) {
         NewPhi->addIncoming(MA, B);
+        if (!IdenticalEdgesWereMerged)
+          PredsSet.erase(B);
         return true;
       }
       return false;
Index: include/llvm/Analysis/MemorySSAUpdater.h
===================================================================
--- include/llvm/Analysis/MemorySSAUpdater.h
+++ include/llvm/Analysis/MemorySSAUpdater.h
@@ -172,9 +172,9 @@
   /// If New is the only predecessor, move Old's Phi, if present, to New.
   /// Otherwise, add a new Phi in New with appropriate incoming values, and
   /// update the incoming values in Old's Phi node too, if present.
-  void
-  wireOldPredecessorsToNewImmediatePredecessor(BasicBlock *Old, BasicBlock *New,
-                                               ArrayRef<BasicBlock *> Preds);
+  void wireOldPredecessorsToNewImmediatePredecessor(
+      BasicBlock *Old, BasicBlock *New, ArrayRef<BasicBlock *> Preds,
+      bool IdenticalEdgesWereMerged = true);
   // The below are utility functions. Other than creation of accesses to pass
   // to insertDef, and removeAccess to remove accesses, you should generally
   // not attempt to update memoryssa yourself. It is very non-trivial to get


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51563.163610.patch
Type: text/x-patch
Size: 2522 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180901/7271b2ef/attachment.bin>


More information about the llvm-commits mailing list