Index: lib/Transforms/Scalar/JumpThreading.cpp =================================================================== --- lib/Transforms/Scalar/JumpThreading.cpp +++ lib/Transforms/Scalar/JumpThreading.cpp @@ -160,10 +160,12 @@ FindLoopHeaders(F); - bool Changed, EverChanged = false; + unsigned UpdatedBBCount; + SmallPtrSet UpdatedBB; do { - Changed = false; + UpdatedBBCount = UpdatedBB.size(); for (Function::iterator I = F.begin(), E = F.end(); I != E;) { + bool Changed = false; BasicBlock *BB = I; // Thread all of the branches we can over this block. while (ProcessBlock(BB)) @@ -180,7 +182,7 @@ LoopHeaders.erase(BB); LVI->eraseBlock(BB); DeleteDeadBlock(BB); - Changed = true; + UpdatedBB.insert(BB); continue; } @@ -214,12 +216,13 @@ if (ErasedFromLoopHeaders) LoopHeaders.insert(BB); } + if (Changed) + UpdatedBB.insert(BB); } - EverChanged |= Changed; - } while (Changed); + } while (UpdatedBBCount < UpdatedBB.size()); LoopHeaders.clear(); - return EverChanged; + return UpdatedBBCount > 0; } /// getJumpThreadDuplicationCost - Return the cost of duplicating this block to Index: test/Transforms/JumpThreading/pr15851_hang.ll =================================================================== --- test/Transforms/JumpThreading/pr15851_hang.ll +++ test/Transforms/JumpThreading/pr15851_hang.ll @@ -0,0 +1,27 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @f() { +entry: + call void @f() + unreachable + +for.cond1: ; preds = %for.cond1, %for.inc + %i.0 = phi i32 [ %inc, %for.inc ], [ 0, %for.cond1 ] + %cmp = icmp slt i32 %i.0, 2 + br i1 %cmp, label %for.body, label %for.cond1 + +for.body: ; preds = %for.cond1 + %div = sdiv i32 %i.0, 2 + %i.0.off = add i32 %i.0, 1 + %0 = icmp ugt i32 %i.0.off, 2 + br i1 %0, label %land.rhs, label %for.inc + +land.rhs: ; preds = %for.body + store i32 0, i32* undef, align 4 + br label %for.inc + +for.inc: ; preds = %for.body + %inc = add nsw i32 %div, 1 + br label %for.cond1 +}