[llvm] [CodeGen] Fix partial phi input removal in TailDuplicator. (PR #158265)
Afanasyev Ivan via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 12 17:37:55 PDT 2025
https://github.com/ivafanas updated https://github.com/llvm/llvm-project/pull/158265
>From 79dd1ed8b72ebafcf59de375d7a7519c72b5544c Mon Sep 17 00:00:00 2001
From: Ivan Afanasyev <ivafanas at gmail.com>
Date: Fri, 12 Sep 2025 17:24:49 +0700
Subject: [PATCH] [TailDup] Fix partial phi input removal in TailDuplicator.
---
llvm/lib/CodeGen/TailDuplicator.cpp | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/TailDuplicator.cpp b/llvm/lib/CodeGen/TailDuplicator.cpp
index 5d720fbbf1c61..9b1420a94142d 100644
--- a/llvm/lib/CodeGen/TailDuplicator.cpp
+++ b/llvm/lib/CodeGen/TailDuplicator.cpp
@@ -375,9 +375,14 @@ void TailDuplicator::processPHI(
if (!Remove)
return;
- // Remove PredBB from the PHI node.
- MI->removeOperand(SrcOpIdx + 1);
- MI->removeOperand(SrcOpIdx);
+ // MI might have multiple entries for PredBB. Need to remove them all.
+ for (unsigned N = MI->getNumOperands(); N > 2; N -= 2) {
+ if (MI->getOperand(N - 1).getMBB() == PredBB) {
+ MI->removeOperand(N - 1);
+ MI->removeOperand(N - 2);
+ }
+ }
+
if (MI->getNumOperands() == 1 && !TailBB->hasAddressTaken())
MI->eraseFromParent();
else if (MI->getNumOperands() == 1)
More information about the llvm-commits
mailing list