[llvm] [VPlan] Assert operand correctness at construction. (NFC) (PR #200686)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 1 06:39:39 PDT 2026
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/200686
>From 6c85db2ceadbf76888f741d7e516c38d9a041b6f Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Sat, 30 May 2026 19:49:48 +0100
Subject: [PATCH 1/2] [VPlan] Assert operand correctness at construction. (NFC)
Update VPWidenPHIRecipe, VPBlendRecipe and VPReductionRecipe to assert
type correctness at construction.
---
llvm/lib/Transforms/Vectorize/VPlan.h | 29 ++++++++++++++++++-
.../Transforms/Vectorize/VPlanTest.cpp | 2 +-
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index d07b9896514d7..ff2e0e7f50887 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -2710,7 +2710,13 @@ class LLVM_ABI_FOR_TEST VPWidenPHIRecipe : public VPSingleDefRecipe,
: VPSingleDefRecipe(VPRecipeBase::VPWidenPHISC, IncomingValues,
getScalarTypeOrInfer(IncomingValues[0]),
/*UV=*/nullptr, DL),
- Name(Name.str()) {}
+ Name(Name.str()) {
+ assert(all_of(IncomingValues,
+ [this](VPValue *VPV) {
+ return VPV->getScalarType() == getScalarType();
+ }) &&
+ "all incoming values must have the same type");
+ }
VPWidenPHIRecipe *clone() override {
return new VPWidenPHIRecipe(operands(), getDebugLoc(), Name);
@@ -2911,6 +2917,17 @@ class LLVM_ABI_FOR_TEST VPBlendRecipe : public VPRecipeWithIRFlags {
: VPRecipeWithIRFlags(VPRecipeBase::VPBlendSC, Operands,
Operands[0]->getScalarType(), Flags, DL) {
assert(Operands.size() >= 2 && "Expected at least two operands!");
+ assert(all_of(seq<unsigned>(0, getNumIncomingValues()),
+ [this](unsigned I) {
+ return getIncomingValue(I)->getScalarType() ==
+ getScalarType();
+ }) &&
+ "all incoming values must have the same type");
+ assert(all_of(seq<unsigned>(isNormalized(), getNumIncomingValues()),
+ [this](unsigned I) {
+ return getMask(I)->getScalarType()->isIntegerTy(1);
+ }) &&
+ "masks must be a bool");
setUnderlyingValue(Phi);
}
@@ -3180,7 +3197,17 @@ class LLVM_ABI_FOR_TEST VPReductionRecipe : public VPRecipeWithIRFlags {
: VPRecipeWithIRFlags(SC, Operands, Operands[0]->getScalarType(), FMFs,
DL),
RdxKind(RdxKind), Style(Style) {
+ assert(all_of(Operands,
+ [this](VPValue *VPV) {
+ return VPV->getScalarType() == getScalarType() ||
+ (isa<VPInstruction>(VPV) &&
+ cast<VPInstruction>(VPV)->getOpcode() ==
+ VPInstruction::ExplicitVectorLength);
+ }) &&
+ "all incoming values must have the same type");
if (CondOp) {
+ assert(CondOp->getScalarType()->isIntegerTy(1) &&
+ "CondOp must be a bool");
IsConditional = true;
addOperand(CondOp);
}
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
index ea1ab78ea5fc8..8dd9da7c5dcef 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
@@ -1212,7 +1212,7 @@ TEST_F(VPRecipeTest, CastVPBlendRecipeToVPUser) {
VPValue *I1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
VPValue *I2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
- VPValue *M2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 3));
+ VPValue *M2 = Plan.getOrAddLiveIn(ConstantInt::getTrue(C));
SmallVector<VPValue *, 4> Args;
Args.push_back(I1);
Args.push_back(I2);
>From e2cc94f3a99a526a624178a455e0f4e3af1524ba Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Mon, 1 Jun 2026 14:38:13 +0100
Subject: [PATCH 2/2] !fixup fix failing testts
---
llvm/unittests/Transforms/Vectorize/VPlanTest.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
index 8dd9da7c5dcef..f36f361bbf71d 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
@@ -1397,7 +1397,7 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
{
VPValue *ChainOp = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
VPValue *VecOp = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
- VPValue *CondOp = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 3));
+ VPValue *CondOp = Plan.getOrAddLiveIn(ConstantInt::getTrue(C));
VPReductionRecipe Recipe(RecurKind::Add, FastMathFlags(), ChainOp, VecOp,
CondOp, RdxUnordered{});
EXPECT_FALSE(Recipe.mayHaveSideEffects());
@@ -1409,7 +1409,7 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
{
VPValue *ChainOp = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
VPValue *VecOp = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
- VPValue *CondOp = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 3));
+ VPValue *CondOp = Plan.getOrAddLiveIn(ConstantInt::getTrue(C));
VPReductionRecipe Recipe(RecurKind::Add, FastMathFlags(), ChainOp, VecOp,
CondOp, RdxUnordered{});
VPValue *EVL = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 4));
@@ -1741,7 +1741,7 @@ TEST_F(VPRecipeTest, CastVPReductionRecipeToVPUser) {
IntegerType *Int32 = IntegerType::get(C, 32);
VPValue *ChainOp = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 1));
VPValue *VecOp = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 2));
- VPValue *CondOp = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 3));
+ VPValue *CondOp = getPlan().getOrAddLiveIn(ConstantInt::getTrue(C));
VPReductionRecipe Recipe(RecurKind::Add, FastMathFlags(), ChainOp, VecOp,
CondOp, RdxUnordered{});
checkVPRecipeCastImpl<VPReductionRecipe, VPUser>(&Recipe);
@@ -1754,7 +1754,7 @@ TEST_F(VPRecipeTest, CastVPReductionEVLRecipeToVPUser) {
IntegerType *Int32 = IntegerType::get(C, 32);
VPValue *ChainOp = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 1));
VPValue *VecOp = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 2));
- VPValue *CondOp = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 3));
+ VPValue *CondOp = getPlan().getOrAddLiveIn(ConstantInt::getTrue(C));
VPReductionRecipe Recipe(RecurKind::Add, FastMathFlags(), ChainOp, VecOp,
CondOp, RdxUnordered{});
VPValue *EVL = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 0));
More information about the llvm-commits
mailing list