From 6f34e317e956da45a8015fe89e4b2ce4d7814fc3 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 19 Jan 2009 21:20:34 +0000 Subject: [PATCH] Fix PR3353, infinitely jump threading an infinite loop make from switches. llvm-svn: 62529 --- llvm/lib/Transforms/Scalar/JumpThreading.cpp | 5 +++++ .../JumpThreading/2009-01-19-InfSwitchLoop.ll | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 llvm/test/Transforms/JumpThreading/2009-01-19-InfSwitchLoop.ll diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 94d33aa78794..f96fc208ae19 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -419,6 +419,11 @@ bool JumpThreading::ProcessBranchOnDuplicateCond(BasicBlock *PredBB, /// switches out of repeated 'if' conditions. bool JumpThreading::ProcessSwitchOnDuplicateCond(BasicBlock *PredBB, BasicBlock *DestBB) { + // Can't thread edge to self. + if (PredBB == DestBB) + return false; + + SwitchInst *PredSI = cast(PredBB->getTerminator()); SwitchInst *DestSI = cast(DestBB->getTerminator()); diff --git a/llvm/test/Transforms/JumpThreading/2009-01-19-InfSwitchLoop.ll b/llvm/test/Transforms/JumpThreading/2009-01-19-InfSwitchLoop.ll new file mode 100644 index 000000000000..ab8b087f8a4a --- /dev/null +++ b/llvm/test/Transforms/JumpThreading/2009-01-19-InfSwitchLoop.ll @@ -0,0 +1,21 @@ +; RUN: llvm-as < %s | opt -jump-threading | llvm-dis +; PR3353 + +define i32 @test(i8 %X) { +entry: + %Y = add i8 %X, 1 + %Z = add i8 %Y, 1 + br label %bb33.i + +bb33.i: ; preds = %bb33.i, %bb32.i + switch i8 %Y, label %bb32.i [ + i8 39, label %bb35.split.i + i8 13, label %bb33.i + ] + +bb35.split.i: + ret i32 5 +bb32.i: + ret i32 1 +} + -- GitLab