From b60c7b1f61eabbe971d08568adb790a7cfc6a403 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 7 Dec 2016 19:55:59 +0000 Subject: [PATCH] [GVNHoist] Invalidate MemDep when an instruction is moved. See also r279907. Fixes https://llvm.org/bugs/show_bug.cgi?id=30991 . Differential Revision: https://reviews.llvm.org/D27493 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288968 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/GVNHoist.cpp | 1 + test/Transforms/GVNHoist/hoist.ll | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/Transforms/Scalar/GVNHoist.cpp b/lib/Transforms/Scalar/GVNHoist.cpp index 230558b4aa9..90c26e13db7 100644 --- a/lib/Transforms/Scalar/GVNHoist.cpp +++ b/lib/Transforms/Scalar/GVNHoist.cpp @@ -802,6 +802,7 @@ private: // Move the instruction at the end of HoistPt. Instruction *Last = HoistPt->getTerminator(); + MD->removeInstruction(Repl); Repl->moveBefore(Last); DFSNumber[Repl] = DFSNumber[Last]++; diff --git a/test/Transforms/GVNHoist/hoist.ll b/test/Transforms/GVNHoist/hoist.ll index 8e189418d72..d4b4afdd5ad 100644 --- a/test/Transforms/GVNHoist/hoist.ll +++ b/test/Transforms/GVNHoist/hoist.ll @@ -711,3 +711,36 @@ return: ; preds = %if.end, %if.then ; CHECK: %[[load:.*]] = load i32, i32* %y, align 1 ; CHECK: %[[phi:.*]] = phi i32 [ %[[load]], %{{.*}} ], [ %[[load]], %{{.*}} ] ; CHECK: i32 %[[phi]] + + +declare i8 @pr30991_f() nounwind readonly +declare void @pr30991_f1(i8) +define i8 @pr30991(i8* %sp, i8* %word, i1 %b1, i1 %b2) { +entry: + br i1 %b1, label %a, label %b + +a: + %r0 = load i8, i8* %word, align 1 + %incdec.ptr = getelementptr i8, i8* %sp, i32 1 + %rr0 = call i8 @pr30991_f() nounwind readonly + call void @pr30991_f1(i8 %r0) + ret i8 %rr0 + +b: + br i1 %b2, label %c, label %x + +c: + %r1 = load i8, i8* %word, align 1 + %incdec.ptr115 = getelementptr i8, i8* %sp, i32 1 + %rr1 = call i8 @pr30991_f() nounwind readonly + call void @pr30991_f1(i8 %r1) + ret i8 %rr1 + +x: + %r2 = load i8, i8* %word, align 1 + ret i8 %r2 +} + +; CHECK-LABEL: define i8 @pr30991 +; CHECK: %r0 = load i8, i8* %word, align 1 +; CHECK-NEXT: br i1 %b1, label %a, label %b -- 2.11.0