From 6f285d21053552e5aff9aba74f0425505d6ab61a Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 10 Apr 2010 18:26:57 +0000 Subject: [PATCH] fix PR6743, a case where we'd delete an instruction before using it in some cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100937 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/JumpThreading.cpp | 4 +++- test/Transforms/JumpThreading/crash.ll | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp index a6489ecc2dc..df05b712dcb 100644 --- a/lib/Transforms/Scalar/JumpThreading.cpp +++ b/lib/Transforms/Scalar/JumpThreading.cpp @@ -670,8 +670,10 @@ bool JumpThreading::ProcessBranchOnDuplicateCond(BasicBlock *PredBB, Value *OldCond = DestBI->getCondition(); DestBI->setCondition(ConstantInt::get(Type::getInt1Ty(BB->getContext()), BranchDir)); - ConstantFoldTerminator(BB); + // Delete dead instructions before we fold the branch. Folding the branch + // can eliminate edges from the CFG which can end up deleting OldCond. RecursivelyDeleteTriviallyDeadInstructions(OldCond); + ConstantFoldTerminator(BB); return true; } diff --git a/test/Transforms/JumpThreading/crash.ll b/test/Transforms/JumpThreading/crash.ll index c65fd1014be..21620bef9cc 100644 --- a/test/Transforms/JumpThreading/crash.ll +++ b/test/Transforms/JumpThreading/crash.ll @@ -324,3 +324,20 @@ A: ; preds = %entry call void undef(i64 ptrtoint (i8* blockaddress(@test11, %A) to i64)) nounwind unreachable } + +; PR6743 +define void @test12() nounwind ssp { +entry: + br label %lbl_51 + +lbl_51: ; preds = %if.then, %entry + %tmp3 = phi i1 [ false, %if.then ], [ undef, %entry ] ; [#uses=2] + br i1 %tmp3, label %if.end12, label %if.then + +if.then: ; preds = %lbl_51 + br i1 %tmp3, label %lbl_51, label %if.end12 + +if.end12: ; preds = %if.then, %lbl_51 + ret void +} + -- 2.34.1