Index: lib/Transforms/Scalar/JumpThreading.cpp =================================================================== --- lib/Transforms/Scalar/JumpThreading.cpp +++ lib/Transforms/Scalar/JumpThreading.cpp @@ -946,10 +946,9 @@ /// ProcessBlock - If there are any predecessors whose control can be threaded /// through to a successor, transform them now. bool JumpThreadingPass::ProcessBlock(BasicBlock *BB) { - // If the block is trivially dead, just return and let the caller nuke it. + // If the block is dead, just return and let the caller nuke it. // This simplifies other transformations. - if (DDT->pendingDeletedBB(BB) || - (pred_empty(BB) && BB != &BB->getParent()->getEntryBlock())) + if (DDT->pendingDeletedBB(BB) || !DDT->flush().isReachableFromEntry(BB)) return false; // If this block has a single predecessor, and if that pred has a single Index: test/Transforms/JumpThreading/PR33357-lvi-recursion.ll =================================================================== --- /dev/null +++ test/Transforms/JumpThreading/PR33357-lvi-recursion.ll @@ -0,0 +1,44 @@ +; RUN: opt -S -jump-threading -verify -o - %s | FileCheck %s + +; Don't enter infinite recursion in LazyValueInfo.cpp + +@a = external global i16, align 1 + +define void @f(i32 %p1) { +bb0: + %0 = icmp eq i32 %p1, 0 + br i1 undef, label %bb6, label %bb1 + +bb1: ; preds = %bb0 + br label %bb2 + +bb2: ; preds = %bb4, %bb1 + %1 = phi i1 [ %0, %bb1 ], [ %2, %bb4 ] + %2 = and i1 %1, undef + br i1 %2, label %bb3, label %bb4 + +bb3: ; preds = %bb2 + store i16 undef, i16* @a, align 1 + br label %bb4 + +bb4: ; preds = %bb3, %bb2 + br i1 %0, label %bb2, label %bb5 + +bb5: ; preds = %bb4 + unreachable + +bb6: ; preds = %bb0 + ret void +} + +; The +; br i1 undef, label %bb6, label %bb1 +; is replaced by +; br label %bb6 +; and the rest of the function is unreachable from entry and jump-threading +; shouldn't even ask LazyValueInfo about things in the dead blocks. + +; CHECK: define void @f(i32 %p1) { +; CHECK-NEXT: bb6: +; CHECK-NEXT: %0 = icmp eq i32 %p1, 0 +; CHECK-NEXT: ret void \ No newline at end of file