From c36b206a7b59e7549f67d4deac8674e0458f6bae Mon Sep 17 00:00:00 2001 From: Ivan Afanasyev Date: Mon, 15 Sep 2025 11:36:50 +0700 Subject: [PATCH] [CodeGen] TailDuplicator should remove PHI when single predecessor block remains --- llvm/lib/CodeGen/TailDuplicator.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/llvm/lib/CodeGen/TailDuplicator.cpp b/llvm/lib/CodeGen/TailDuplicator.cpp index 9b1420a94142d..f94ada4e68e9d 100644 --- a/llvm/lib/CodeGen/TailDuplicator.cpp +++ b/llvm/lib/CodeGen/TailDuplicator.cpp @@ -387,6 +387,16 @@ void TailDuplicator::processPHI( MI->eraseFromParent(); else if (MI->getNumOperands() == 1) MI->setDesc(TII->get(TargetOpcode::IMPLICIT_DEF)); + else if (TailBB->pred_size() == 2) { + // According to callers implementation, PredBB has not yet been removed from + // TailBB predecessors list. After removal TailBB will have the only one + // predecessor and all phi instructions should be replaced with copies. + assert(PredBB->isSuccessor(TailBB)); + BuildMI(*TailBB, MI->getIterator(), MI->getDebugLoc(), + TII->get(TargetOpcode::COPY), MI->getOperand(0).getReg()) + .add(MI->getOperand(1)); + MI->eraseFromParent(); + } } /// Duplicate a TailBB instruction to PredBB and update