[llvm] [VPlan] Free removeDeadRecipes from VPPhi simplification (PR #156438)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 2 03:46:19 PDT 2025
https://github.com/artagnon updated https://github.com/llvm/llvm-project/pull/156438
>From 6c7b401cf082c3a85a37b57d7281dea0e685dea9 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Tue, 2 Sep 2025 11:28:21 +0100
Subject: [PATCH 1/2] [VPlan] Free removeDeadRecipes from VPPhi simplification
VPPhi simplification is best done in simplifyRecipe.
---
.../Transforms/Vectorize/VPlanTransforms.cpp | 29 ++++++++-----------
llvm/lib/Transforms/Vectorize/VPlanValue.h | 4 +++
2 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 3a918ffdf5e91..b1a6940272691 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -555,24 +555,9 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
vp_post_order_deep(Plan.getEntry()))) {
// The recipes in the block are processed in reverse order, to catch chains
// of dead recipes.
- for (VPRecipeBase &R : make_early_inc_range(reverse(*VPBB))) {
- if (isDeadRecipe(R)) {
+ for (VPRecipeBase &R : make_early_inc_range(reverse(*VPBB)))
+ if (isDeadRecipe(R))
R.eraseFromParent();
- continue;
- }
-
- // Check if R is a dead VPPhi <-> update cycle and remove it.
- auto *PhiR = dyn_cast<VPPhi>(&R);
- if (!PhiR || PhiR->getNumOperands() != 2 || PhiR->getNumUsers() != 1)
- continue;
- VPValue *Incoming = PhiR->getOperand(1);
- if (*PhiR->user_begin() != Incoming->getDefiningRecipe() ||
- Incoming->getNumUsers() != 1)
- continue;
- PhiR->replaceAllUsesWith(PhiR->getOperand(0));
- PhiR->eraseFromParent();
- Incoming->getDefiningRecipe()->eraseFromParent();
- }
}
}
@@ -1215,6 +1200,16 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
if (auto *Phi = dyn_cast<VPPhi>(Def)) {
if (Phi->getNumOperands() == 1)
Phi->replaceAllUsesWith(Phi->getOperand(0));
+
+ if (Phi->getNumOperands() == 2) {
+ VPValue *Incoming = Phi->getOperand(1);
+ VPUser *U = Phi->getUniqueUser();
+ if (U && U == Incoming->getDefiningRecipe() && Incoming->hasOneUser()) {
+ Phi->replaceAllUsesWith(Phi->getOperand(0));
+ Phi->eraseFromParent();
+ Incoming->getDefiningRecipe()->eraseFromParent();
+ }
+ }
return;
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h
index 24f6d61512ef6..ed6abb67493f5 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanValue.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h
@@ -111,6 +111,10 @@ class LLVM_ABI_FOR_TEST VPValue {
#endif
unsigned getNumUsers() const { return Users.size(); }
+ bool hasOneUser() const { return Users.size() == 1; }
+ VPUser *getUniqueUser() const {
+ return Users.size() == 1 ? Users.front() : nullptr;
+ }
void addUser(VPUser &User) { Users.push_back(&User); }
/// Remove a single \p User from the list of users.
>From 23b0fcd152e131c9b22a10ab6ad976b87c84521d Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Tue, 2 Sep 2025 11:44:40 +0100
Subject: [PATCH 2/2] [VPlan] Small improvement (NFC)
---
llvm/lib/Transforms/Vectorize/VPlanValue.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h
index ed6abb67493f5..2072c5df31309 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanValue.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h
@@ -113,7 +113,7 @@ class LLVM_ABI_FOR_TEST VPValue {
unsigned getNumUsers() const { return Users.size(); }
bool hasOneUser() const { return Users.size() == 1; }
VPUser *getUniqueUser() const {
- return Users.size() == 1 ? Users.front() : nullptr;
+ return hasOneUser() ? Users.front() : nullptr;
}
void addUser(VPUser &User) { Users.push_back(&User); }
More information about the llvm-commits
mailing list