diff options
author | Alina Sbirlea <asbirlea@google.com> | 2019-02-26 19:44:52 +0000 |
---|---|---|
committer | Alina Sbirlea <asbirlea@google.com> | 2019-02-26 19:44:52 +0000 |
commit | 9026404125bcb7b7a3f8e21c5536a1b60e9e07b6 (patch) | |
tree | f8fc03213683f0193c9c95b12789d0f3aef47d93 | |
parent | 9b6135bf2a7aa2b9a79818671a5f12a98a41349f (diff) | |
download | bcm5719-llvm-9026404125bcb7b7a3f8e21c5536a1b60e9e07b6.tar.gz bcm5719-llvm-9026404125bcb7b7a3f8e21c5536a1b60e9e07b6.zip |
[MemorySSA & SimpleLoopUnswitch] Update MemorySSA in ReplaceUsesOfWith.
SimpleLoopUnswitch must update MemorySSA when removing instructions.
Resolves PR39197.
llvm-svn: 354919
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopUnswitch.cpp | 14 | ||||
-rw-r--r-- | llvm/test/Analysis/MemorySSA/pr39197.ll | 153 |
2 files changed, 162 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp index 3bff0538be5..51d113eac89 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/llvm/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<Instruction*> &Worklist, - Loop *L, LPPassManager *LPM) { + std::vector<Instruction *> &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<Instruction*> &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<Instruction*> &Worklist, Loop *L) { // Resolve any single entry PHI nodes in Succ. while (PHINode *PN = dyn_cast<PHINode>(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/llvm/test/Analysis/MemorySSA/pr39197.ll b/llvm/test/Analysis/MemorySSA/pr39197.ll new file mode 100644 index 00000000000..e384c060ce9 --- /dev/null +++ b/llvm/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 + +; <label>:4: ; preds = %0 + %5 = load i16, i16* getelementptr inbounds ([5 x i16], [5 x i16]* @g_1042, i64 0, i64 0), align 2, !tbaa !1 + %6 = zext i16 %5 to i64 + %7 = load i64, i64* @1, align 8, !tbaa !5 + %8 = and i64 %7, %6 + store i64 %8, i64* @1, align 8, !tbaa !5 + call void @llvm.lifetime.end.p0i8(i64 4, i8* undef) #2 + unreachable + +; <label>:9: ; preds = %0 + store i32* @0, i32** %1, align 8, !tbaa !7 + br label %10 + +; <label>:10: ; preds = %23, %9 + %11 = load i64, i64* @1, align 8, !tbaa !5 + %12 = icmp eq i64 %11, 65535 + br i1 %12, label %13, label %14 + +; <label>:13: ; preds = %10 + store i32* null, i32** %1, align 8, !tbaa !7 + br label %14 + +; <label>:14: ; preds = %13, %10 + %15 = load i32*, i32** %1, align 8, !tbaa !7 + %16 = load i32, i32* %15, align 4, !tbaa !9 + %17 = trunc i32 %16 to i16 + %18 = call signext i16 @safe_sub_func_int16_t_s_s(i16 signext %17) + %19 = sext i16 %18 to i32 + %20 = icmp ne i32 %19, 0 + br i1 %20, label %23, label %21 + +; <label>:21: ; preds = %14 + %22 = load volatile i8, i8* null, align 1, !tbaa !11 + br label %23 + +; <label>:23: ; preds = %21, %14 + br label %10 +} + +; Function Attrs: nounwind +declare dso_local signext i32 @func_2() #0 + +; Function Attrs: nounwind +define dso_local void @safe_sub_func_uint8_t_u_u() #0 { + ret void +} + +; Function Attrs: nounwind +define dso_local void @safe_add_func_int64_t_s_s() #0 { + ret void +} + +; Function Attrs: nounwind +define dso_local void @safe_rshift_func_int16_t_s_u() #0 { + ret void +} + +; Function Attrs: nounwind +define dso_local void @safe_div_func_uint8_t_u_u() #0 { + ret void +} + +; Function Attrs: nounwind +define dso_local void @safe_mul_func_uint16_t_u_u() #0 { + ret void +} + +; Function Attrs: nounwind +define dso_local void @safe_mul_func_int16_t_s_s() #0 { + ret void +} + +; Function Attrs: nounwind +define dso_local void @safe_div_func_int32_t_s_s() #0 { + ret void +} + +; Function Attrs: nounwind +define dso_local signext i16 @safe_sub_func_int16_t_s_s(i16 signext) #0 { + %2 = alloca i16, align 2 + store i16 %0, i16* %2, align 2, !tbaa !1 + %3 = load i16, i16* %2, align 2, !tbaa !1 + %4 = sext i16 %3 to i32 + %5 = sub nsw i32 %4, 0 + %6 = trunc i32 %5 to i16 + ret i16 %6 +} + +; Function Attrs: nounwind +define dso_local void @safe_add_func_uint16_t_u_u() #0 { + ret void +} + +; Function Attrs: nounwind +define dso_local void @safe_div_func_int8_t_s_s() #0 { + ret void +} + +; Function Attrs: nounwind +define dso_local void @safe_add_func_int16_t_s_s() #0 { + ret void +} + +; Function Attrs: nounwind +define dso_local void @safe_add_func_uint8_t_u_u() #0 { + ret void +} + +attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="z13" "target-features"="+transactional-execution,+vector" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { argmemonly nounwind } +attributes #2 = { nounwind } + +!llvm.ident = !{!0} + +!0 = !{!"clang version 8.0.0 (http://llvm.org/git/clang.git 7cda4756fc9713d98fd3513b8df172700f267bad) (http://llvm.org/git/llvm.git 199c0d32e96b646bd8cf6beeaf0f99f8a434b56a)"} +!1 = !{!2, !2, i64 0} +!2 = !{!"short", !3, i64 0} +!3 = !{!"omnipotent char", !4, i64 0} +!4 = !{!"Simple C/C++ TBAA"} +!5 = !{!6, !6, i64 0} +!6 = !{!"long", !3, i64 0} +!7 = !{!8, !8, i64 0} +!8 = !{!"any pointer", !3, i64 0} +!9 = !{!10, !10, i64 0} +!10 = !{!"int", !3, i64 0} +!11 = !{!3, !3, i64 0} |