Index: llvm/include/llvm/IR/BasicBlock.h =================================================================== --- llvm/include/llvm/IR/BasicBlock.h +++ llvm/include/llvm/IR/BasicBlock.h @@ -387,9 +387,9 @@ /// Update PHI nodes in this BasicBlock before removal of predecessor \p Pred. /// Note that this function does not actually remove the predecessor. /// - /// If \p KeepOneInputPHIs is true then don't remove PHIs that are left with - /// zero or one incoming values, and don't simplify PHIs with all incoming - /// values the same. + /// If \p KeepOneInputPHIs is true, then don't remove PHIs that are left with + /// one incoming value and don't simplify PHIs with all incoming values the + /// same. void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs = false); bool canSplitPredecessors() const; Index: llvm/lib/IR/BasicBlock.cpp =================================================================== --- llvm/lib/IR/BasicBlock.cpp +++ llvm/lib/IR/BasicBlock.cpp @@ -330,7 +330,7 @@ unsigned NumPreds = cast(front()).getNumIncomingValues(); for (PHINode &Phi : make_early_inc_range(phis())) { - Phi.removeIncomingValue(Pred, !KeepOneInputPHIs); + Phi.removeIncomingValue(Pred); if (KeepOneInputPHIs) continue; // If we have a single predecessor, removeIncomingValue erased the PHI Index: llvm/test/Transforms/LoopRotate/phi-empty.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/LoopRotate/phi-empty.ll @@ -0,0 +1,34 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -S -lcssa -loop-rotate < %s | FileCheck %s + +define void @PR48296(i1 %cond) { +; CHECK-LABEL: @PR48296( +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[LOOP:%.*]] +; CHECK: loop: +; CHECK-NEXT: br i1 [[COND:%.*]], label [[INC:%.*]], label [[LOOP_BACKEDGE:%.*]] +; CHECK: loop.backedge: +; CHECK-NEXT: br label [[LOOP]] +; CHECK: dead: +; CHECK-NEXT: unreachable +; CHECK: inc: +; CHECK-NEXT: br label [[LOOP_BACKEDGE]] +; CHECK: return: +; CHECK-NEXT: ret void +; +entry: + br label %loop + +loop: + br i1 %cond, label %inc, label %loop + +dead: ; No predecessors! + br i1 %cond, label %inc, label %return + +inc: + br label %loop + +return: + %r = phi i32 [ undef, %dead ] + ret void +}