[llvm] 2967815 - [VPlan] Don't emit VPBlendRecipes with only one incoming value. NFC (#171804)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 11 04:56:00 PST 2025
Author: Luke Lau
Date: 2025-12-11T12:55:56Z
New Revision: 296781524902c4eb06efc5bb054cac58b973d839
URL: https://github.com/llvm/llvm-project/commit/296781524902c4eb06efc5bb054cac58b973d839
DIFF: https://github.com/llvm/llvm-project/commit/296781524902c4eb06efc5bb054cac58b973d839.diff
LOG: [VPlan] Don't emit VPBlendRecipes with only one incoming value. NFC (#171804)
We can just directly use the incoming value. These single value blends
would get optimized later on in simplifyBlends, but by doing it early it
removes the notion of an "immediately normalized" blend, and simplifies
an upcoming patch.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp
llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 2ef7b5405668d..0f8f6abab7b0a 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -2517,7 +2517,7 @@ class LLVM_ABI_FOR_TEST VPBlendRecipe : public VPSingleDefRecipe {
/// all other incoming values are merged into it.
VPBlendRecipe(PHINode *Phi, ArrayRef<VPValue *> Operands, DebugLoc DL)
: VPSingleDefRecipe(VPDef::VPBlendSC, Operands, Phi, DL) {
- assert(Operands.size() > 0 && "Expected at least one operand!");
+ assert(Operands.size() >= 2 && "Expected at least two operands!");
}
VPBlendRecipe *clone() override {
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp b/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp
index 6517862e2d0f8..f7e7fc29bc203 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp
@@ -240,17 +240,16 @@ void VPPredicator::convertPhisToBlends(VPBasicBlock *VPBB) {
// be duplications since this is a simple recursive scan, but future
// optimizations will clean it up.
+ if (all_equal(PhiR->incoming_values())) {
+ PhiR->replaceAllUsesWith(PhiR->getIncomingValue(0));
+ PhiR->eraseFromParent();
+ continue;
+ }
+
SmallVector<VPValue *, 2> OperandsWithMask;
for (const auto &[InVPV, InVPBB] : PhiR->incoming_values_and_blocks()) {
OperandsWithMask.push_back(InVPV);
- VPValue *EdgeMask = getEdgeMask(InVPBB, VPBB);
- if (!EdgeMask) {
- assert(all_equal(PhiR->incoming_values()) &&
- "Distinct incoming values with one having a full mask");
- break;
- }
-
- OperandsWithMask.push_back(EdgeMask);
+ OperandsWithMask.push_back(getEdgeMask(InVPBB, VPBB));
}
PHINode *IRPhi = cast_or_null<PHINode>(PhiR->getUnderlyingValue());
auto *Blend =
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
index 97783a63c8fb9..91c71724205c9 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
@@ -103,7 +103,7 @@ TEST_F(VPVerifierTest, VPBlendUseBeforeDefDifferentBB) {
auto *CanIV = new VPCanonicalIVPHIRecipe(Zero, {});
VPInstruction *BranchOnCond =
new VPInstruction(VPInstruction::BranchOnCond, {CanIV});
- auto *Blend = new VPBlendRecipe(Phi, {DefI}, {});
+ auto *Blend = new VPBlendRecipe(Phi, {DefI, Plan.getTrue()}, {});
VPBasicBlock *VPBB1 = Plan.getEntry();
VPBasicBlock *VPBB2 = Plan.createVPBasicBlock("");
More information about the llvm-commits
mailing list