[llvm] da4baa2 - [MemorySSA] Update analysis when the terminator is a memory instruction.

Alina Sbirlea via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 20 16:38:47 PST 2019


Author: Alina Sbirlea
Date: 2019-11-20T16:36:52-08:00
New Revision: da4baa2a6c966154e19964fdced1119ed2f4d6ee

URL: https://github.com/llvm/llvm-project/commit/da4baa2a6c966154e19964fdced1119ed2f4d6ee
DIFF: https://github.com/llvm/llvm-project/commit/da4baa2a6c966154e19964fdced1119ed2f4d6ee.diff

LOG: [MemorySSA] Update analysis when the terminator is a memory instruction.

Update MemorySSA when moving the terminator instruction, as that may be a memory touching instruction.
Resolves PR44029.

Added: 
    llvm/test/Analysis/MemorySSA/pr44029.ll

Modified: 
    llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
    llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
index e55d8570ffa7..b27e65e0adb7 100644
--- a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
@@ -662,6 +662,9 @@ static bool mergeBlocksIntoPredecessors(Loop &L, DominatorTree &DT,
     // Merge Succ into Pred and delete it.
     MergeBlockIntoPredecessor(Succ, &DTU, &LI, MSSAU);
 
+    if (MSSAU && VerifyMemorySSA)
+      MSSAU->getMemorySSA()->verifyMemorySSA();
+
     Changed = true;
   }
 

diff  --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index d85cc40c372a..31eaf2607356 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -247,7 +247,7 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU,
   Instruction *STI = BB->getTerminator();
   Instruction *Start = &*BB->begin();
   // If there's nothing to move, mark the starting instruction as the last
-  // instruction in the block.
+  // instruction in the block. Terminator instruction is handled separately.
   if (Start == STI)
     Start = PTI;
 
@@ -274,6 +274,12 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU,
 
     // Move terminator instruction.
     PredBB->getInstList().splice(PredBB->end(), BB->getInstList());
+
+    // Terminator may be a memory accessing instruction too.
+    if (MSSAU)
+      if (MemoryUseOrDef *MUD = cast_or_null<MemoryUseOrDef>(
+              MSSAU->getMemorySSA()->getMemoryAccess(PredBB->getTerminator())))
+        MSSAU->moveToPlace(MUD, PredBB, MemorySSA::End);
   }
   // Add unreachable to now empty BB.
   new UnreachableInst(BB->getContext(), BB);

diff  --git a/llvm/test/Analysis/MemorySSA/pr44029.ll b/llvm/test/Analysis/MemorySSA/pr44029.ll
new file mode 100644
index 000000000000..e3aab4d0cef6
--- /dev/null
+++ b/llvm/test/Analysis/MemorySSA/pr44029.ll
@@ -0,0 +1,63 @@
+; RUN: opt -loop-simplifycfg -verify-memoryssa -S < %s | FileCheck %s
+; REQUIRES: asserts
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare i32 @eggs(...)
+
+declare void @spam()
+
+; CHECK-LABEL: @f()
+define void @f() personality i8* bitcast (i32 (...)* @eggs to i8*) {
+bb:
+  invoke void @spam()
+          to label %bb2 unwind label %bb4
+
+bb2:                                              ; preds = %bb
+  invoke void @spam()
+          to label %bb8 unwind label %bb5
+
+bb4:                                              ; preds = %bb
+  %tmp = landingpad { i8*, i32 }
+          cleanup
+  resume { i8*, i32 } undef
+
+bb5:                                              ; preds = %bb2
+  %tmp6 = landingpad { i8*, i32 }
+          cleanup
+  unreachable
+
+bb8:                                              ; preds = %bb13, %bb2
+  br label %bb10
+
+bb10:                                             ; preds = %bb8
+  invoke void @spam()
+          to label %bb11 unwind label %bb20
+
+bb11:                                             ; preds = %bb10
+  invoke void @spam()
+          to label %bb12 unwind label %bb22
+
+bb12:                                             ; preds = %bb11
+  invoke void @spam()
+          to label %bb13 unwind label %bb24
+
+bb13:                                             ; preds = %bb12
+  br label %bb8
+
+bb20:                                             ; preds = %bb10
+  %tmp21 = landingpad { i8*, i32 }
+          cleanup
+  unreachable
+
+bb22:                                             ; preds = %bb11
+  %tmp23 = landingpad { i8*, i32 }
+          cleanup
+  unreachable
+
+bb24:                                             ; preds = %bb12
+  %tmp25 = landingpad { i8*, i32 }
+          cleanup
+  unreachable
+}


        


More information about the llvm-commits mailing list