[PATCH] D14797: [BranchFolding] Merge MMOs during tail merge

Junmo Park via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 19 22:16:38 PST 2015


flyingforyou retitled this revision from " [BranchFolding] Add volatile checking when clearing memory references" to "[BranchFolding] Merge MMOs during tail merge".
flyingforyou updated the summary for this revision.
flyingforyou updated this revision to Diff 40743.
flyingforyou added a comment.

I addressed Chad, Geoff comments.

Thanks Chad. Your comment really helpful for me.

Junmo.


http://reviews.llvm.org/D14797

Files:
  lib/CodeGen/BranchFolding.cpp

Index: lib/CodeGen/BranchFolding.cpp
===================================================================
--- lib/CodeGen/BranchFolding.cpp
+++ lib/CodeGen/BranchFolding.cpp
@@ -744,24 +744,34 @@
   return true;
 }
 
-static bool hasIdenticalMMOs(const MachineInstr *MI1, const MachineInstr *MI2) {
+// Add MI1's MMOs to MI2's.
+static void mergeMMOs(MachineInstr *MI1, MachineInstr *MI2) {
   auto I1 = MI1->memoperands_begin(), E1 = MI1->memoperands_end();
   auto I2 = MI2->memoperands_begin(), E2 = MI2->memoperands_end();
-  if ((E1 - I1) != (E2 - I2))
-    return false;
-  for (; I1 != E1; ++I1, ++I2) {
-    if (**I1 != **I2)
-      return false;
+  if ((E1 - I1) == 0)
+    return;
+
+  for (; I1 != E1; ++I1) {
+    bool IsDupMMO = false;
+    for (; I2 != E2; ++I2) {
+      if (**I1 == **I2) {
+        IsDupMMO = true;
+        break;
+      }
+    }
+    if (IsDupMMO == false) {
+      MachineFunction *MF = MI1->getParent()->getParent();
+      MI2->addMemOperand(*MF, *I1);
+      I2 = MI2->memoperands_begin();
+      E2 = MI2->memoperands_end();
+    }
   }
-  return true;
 }
 
 static void
-removeMMOsFromMemoryOperations(MachineBasicBlock::iterator MBBIStartPos,
+mergeMMOsFromMemoryOperations(MachineBasicBlock::iterator MBBIStartPos,
                                MachineBasicBlock &MBBCommon) {
-  // Remove MMOs from memory operations in the common block
-  // when they do not match the ones from the block being tail-merged.
-  // This ensures later passes conservatively compute dependencies.
+  // Merge MMOs from memory operations in the common block
   MachineBasicBlock *MBB = MBBIStartPos->getParent();
   // Note CommonTailLen does not necessarily matches the size of
   // the common BB nor all its instructions because of debug
@@ -792,8 +802,7 @@
     assert(MBBICommon->isIdenticalTo(&*MBBI) && "Expected matching MIIs!");
 
     if (MBBICommon->mayLoad() || MBBICommon->mayStore())
-      if (!hasIdenticalMMOs(&*MBBI, &*MBBICommon))
-        MBBICommon->clearMemRefs();
+      mergeMMOs(&*MBBI, &*MBBICommon);
 
     ++MBBI;
     ++MBBICommon;
@@ -913,8 +922,8 @@
         continue;
       DEBUG(dbgs() << "BB#" << SameTails[i].getBlock()->getNumber()
                    << (i == e-1 ? "" : ", "));
-      // Remove MMOs from memory operations as needed.
-      removeMMOsFromMemoryOperations(SameTails[i].getTailStartPos(), *MBB);
+      // Merge MMOs from memory operations as needed.
+      mergeMMOsFromMemoryOperations(SameTails[i].getTailStartPos(), *MBB);
       // Hack the end off BB i, making it jump to BB commonTailIndex instead.
       ReplaceTailWithBranchTo(SameTails[i].getTailStartPos(), MBB);
       // BB i is no longer a predecessor of SuccBB; remove it from the worklist.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14797.40743.patch
Type: text/x-patch
Size: 2736 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151120/453c7cee/attachment.bin>


More information about the llvm-commits mailing list