From ae40dfc1e3ce5f64be3234ed7958792f15800181 Mon Sep 17 00:00:00 2001 From: Alina Sbirlea Date: Tue, 1 Oct 2019 18:34:39 +0000 Subject: [PATCH] [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. llvm-svn: 373380 --- llvm/lib/Analysis/MemorySSAUpdater.cpp | 9 ++++- llvm/test/Analysis/MemorySSA/pr43438.ll | 54 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp index b62cf08eb4c8..315037bcc041 100644 --- a/llvm/lib/Analysis/MemorySSAUpdater.cpp +++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp @@ -303,7 +303,12 @@ void MemorySSAUpdater::insertDef(MemoryDef *MD, bool RenameUses) { // 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(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::updatePhisWhenInsertingUniqueBackedgeBlock( // 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, diff --git a/llvm/test/Analysis/MemorySSA/pr43438.ll b/llvm/test/Analysis/MemorySSA/pr43438.ll index 2dddcd3153c5..69bbcedde862 100644 --- a/llvm/test/Analysis/MemorySSA/pr43438.ll +++ b/llvm/test/Analysis/MemorySSA/pr43438.ll @@ -44,3 +44,57 @@ if.end569: ; preds = %if.else568, %if.the 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)