diff --git a/llvm/include/llvm/IR/BasicBlock.h b/llvm/include/llvm/IR/BasicBlock.h --- a/llvm/include/llvm/IR/BasicBlock.h +++ b/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; diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp --- a/llvm/lib/IR/BasicBlock.cpp +++ b/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 diff --git a/llvm/test/Transforms/LoopRotate/phi-empty.ll b/llvm/test/Transforms/LoopRotate/phi-empty.ll new file mode 100644 --- /dev/null +++ b/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 +}