From: Alina Sbirlea Date: Tue, 26 Feb 2019 19:44:52 +0000 (+0000) Subject: [MemorySSA & SimpleLoopUnswitch] Update MemorySSA in ReplaceUsesOfWith. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02e42d437e0450c8c231861aa7523a8c5988e753;p=llvm [MemorySSA & SimpleLoopUnswitch] Update MemorySSA in ReplaceUsesOfWith. SimpleLoopUnswitch must update MemorySSA when removing instructions. Resolves PR39197. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354919 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index 3bff0538be5..51d113eac89 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -1404,8 +1404,8 @@ static void RemoveFromWorklist(Instruction *I, /// When we find that I really equals V, remove I from the /// program, replacing all uses with V and update the worklist. static void ReplaceUsesOfWith(Instruction *I, Value *V, - std::vector &Worklist, - Loop *L, LPPassManager *LPM) { + std::vector &Worklist, Loop *L, + LPPassManager *LPM, MemorySSAUpdater *MSSAU) { LLVM_DEBUG(dbgs() << "Replace with '" << *V << "': " << *I << "\n"); // Add uses to the worklist, which may be dead now. @@ -1419,8 +1419,11 @@ static void ReplaceUsesOfWith(Instruction *I, Value *V, LPM->deleteSimpleAnalysisValue(I, L); RemoveFromWorklist(I, Worklist); I->replaceAllUsesWith(V); - if (!I->mayHaveSideEffects()) + if (!I->mayHaveSideEffects()) { + if (MSSAU) + MSSAU->removeMemoryAccess(I); I->eraseFromParent(); + } ++NumSimplify; } @@ -1595,7 +1598,7 @@ void LoopUnswitch::SimplifyCode(std::vector &Worklist, Loop *L) { // 'false'. TODO: update the domtree properly so we can pass it here. if (Value *V = SimplifyInstruction(I, DL)) if (LI->replacementPreservesLCSSAForm(I, V)) { - ReplaceUsesOfWith(I, V, Worklist, L, LPM); + ReplaceUsesOfWith(I, V, Worklist, L, LPM, MSSAU.get()); continue; } @@ -1615,7 +1618,8 @@ void LoopUnswitch::SimplifyCode(std::vector &Worklist, Loop *L) { // Resolve any single entry PHI nodes in Succ. while (PHINode *PN = dyn_cast(Succ->begin())) - ReplaceUsesOfWith(PN, PN->getIncomingValue(0), Worklist, L, LPM); + ReplaceUsesOfWith(PN, PN->getIncomingValue(0), Worklist, L, LPM, + MSSAU.get()); // If Succ has any successors with PHI nodes, update them to have // entries coming from Pred instead of Succ. diff --git a/test/Analysis/MemorySSA/pr39197.ll b/test/Analysis/MemorySSA/pr39197.ll new file mode 100644 index 00000000000..e384c060ce9 --- /dev/null +++ b/test/Analysis/MemorySSA/pr39197.ll @@ -0,0 +1,153 @@ +; RUN: opt -mtriple=s390x-linux-gnu -mcpu=z13 -enable-mssa-loop-dependency -verify-memoryssa -sroa -globalopt -functionattrs -simplifycfg -licm -loop-unswitch %s -S | FileCheck %s +; REQUIRES: asserts + +target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64" +target triple = "s390x-ibm-linux" + +@0 = internal global i32 -9, align 4 +@1 = internal global i64 9, align 8 +@g_1042 = external dso_local global [5 x i16], align 2 + +; CHECK-LABEL: @main() +; Function Attrs: nounwind +define dso_local void @main() #0 { + call void @func_1() + unreachable +} + +; Function Attrs: argmemonly nounwind +declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1 + +; Function Attrs: nounwind +define dso_local void @func_1() #0 { + %1 = alloca i32*, align 8 + %2 = call signext i32 @func_2() + %3 = icmp ne i32 %2, 0 + br i1 %3, label %4, label %9 + +;