[llvm] r373380 - [MemorySSA] Update last_access_in_block check.

Alina Sbirlea via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 1 11:34:39 PDT 2019


Author: asbirlea
Date: Tue Oct  1 11:34:39 2019
New Revision: 373380

URL: http://llvm.org/viewvc/llvm-project?rev=373380&view=rev
Log:
[MemorySSA] Update last_access_in_block check.

The check for "was there an access in this block" should be: is the last
access in this block and is it not a newly inserted phi.
Resolves new test in PR43438.

Also fix a typo when simplifying trivial Phis to match the comment.

Modified:
    llvm/trunk/lib/Analysis/MemorySSAUpdater.cpp
    llvm/trunk/test/Analysis/MemorySSA/pr43438.ll

Modified: llvm/trunk/lib/Analysis/MemorySSAUpdater.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemorySSAUpdater.cpp?rev=373380&r1=373379&r2=373380&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemorySSAUpdater.cpp (original)
+++ llvm/trunk/lib/Analysis/MemorySSAUpdater.cpp Tue Oct  1 11:34:39 2019
@@ -303,7 +303,12 @@ void MemorySSAUpdater::insertDef(MemoryD
 
   // See if we had a local def, and if not, go hunting.
   MemoryAccess *DefBefore = getPreviousDef(MD);
-  bool DefBeforeSameBlock = DefBefore->getBlock() == MD->getBlock();
+  bool DefBeforeSameBlock = false;
+  if (DefBefore->getBlock() == MD->getBlock() &&
+      !(isa<MemoryPhi>(DefBefore) &&
+        std::find(InsertedPHIs.begin(), InsertedPHIs.end(), DefBefore) !=
+            InsertedPHIs.end()))
+    DefBeforeSameBlock = true;
 
   // There is a def before us, which means we can replace any store/phi uses
   // of that thing with us, since we are in the way of whatever was there
@@ -628,7 +633,7 @@ void MemorySSAUpdater::updatePhisWhenIns
 
   // If NewMPhi is a trivial phi, remove it. Its use in the header MPhi will be
   // replaced with the unique value.
-  tryRemoveTrivialPhi(MPhi);
+  tryRemoveTrivialPhi(NewMPhi);
 }
 
 void MemorySSAUpdater::updateForClonedLoop(const LoopBlocksRPO &LoopBlocks,

Modified: llvm/trunk/test/Analysis/MemorySSA/pr43438.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/MemorySSA/pr43438.ll?rev=373380&r1=373379&r2=373380&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/MemorySSA/pr43438.ll (original)
+++ llvm/trunk/test/Analysis/MemorySSA/pr43438.ll Tue Oct  1 11:34:39 2019
@@ -44,3 +44,57 @@ if.end569:
   ret void
 }
 
+
+; CHECK-LABEL: @f()
+; CHECK: 8 = MemoryPhi(
+; CHECK: 7 = MemoryPhi(
+; CHECK: 11 = MemoryPhi(
+; CHECK: 10 = MemoryPhi(
+; CHECK: 9 = MemoryPhi(
+define void @f() {
+entry:
+  %e = alloca i16, align 1
+  br label %lbl1
+
+lbl1:                                             ; preds = %if.else, %for.end5, %entry
+  store i16 undef, i16* %e, align 1
+  %0 = load i16, i16* %e, align 1
+  %call = call i16 @g(i16 %0)
+  br i1 undef, label %for.end, label %if.else
+
+for.end:                                          ; preds = %if.then
+  br i1 true, label %for.cond2, label %lbl2
+
+lbl2:                                             ; preds = %for.body4, %if.end
+  br label %for.cond2
+
+for.cond2:                                        ; preds = %lbl3
+  br i1 undef, label %for.body4, label %for.end5
+
+for.body4:                                        ; preds = %for.cond2
+  br label %lbl2
+
+for.end5:                                         ; preds = %for.cond2
+  switch i32 undef, label %unreachable [
+    i32 0, label %if.end12
+    i32 2, label %lbl1
+  ]
+
+if.else:                                          ; preds = %lbl1
+  switch i32 undef, label %unreachable [
+    i32 0, label %if.end12
+    i32 2, label %lbl1
+  ]
+
+if.end12:                                         ; preds = %cleanup.cont11s, %cleanup.cont
+  call void @llvm.lifetime.end.p0i8(i64 1, i8* undef)
+  ret void
+
+unreachable:                                      ; preds = %if.else, %for.end5
+  unreachable
+}
+
+declare i16 @g(i16)
+
+; Function Attrs: argmemonly nounwind willreturn
+declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)




More information about the llvm-commits mailing list