[VPlan] Assert operand correctness at construction. (NFC) - #200686
Merged
Conversation
|
@llvm/pr-subscribers-vectorizers @llvm/pr-subscribers-llvm-transforms Author: Florian Hahn (fhahn) ChangesUpdate VPWidenPHIRecipe, VPBlendRecipe and VPReductionRecipe to assert type correctness at construction. Full diff: https://github.com/llvm/llvm-project/pull/200686.diff 2 Files Affected:
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);
|
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
lukel97
approved these changes
Jun 1, 2026
| RdxKind(RdxKind), Style(Style) { | ||
| assert(all_of(Operands, | ||
| [this](VPValue *VPV) { | ||
| return VPV->getScalarType() == getScalarType() || |
Contributor
There was a problem hiding this comment.
This is because the EVL can be an operand in a FP reduction right?
Contributor
Author
There was a problem hiding this comment.
Yep, it gets added as operand for VPReductionEVLRecipe
Update VPWidenPHIRecipe, VPBlendRecipe and VPReductionRecipe to assert type correctness at construction.
fhahn
force-pushed
the
vplan-assert-operands-at-construction
branch
from
June 1, 2026 13:39
1fbb863 to
e2cc94f
Compare
fhahn
enabled auto-merge (squash)
June 1, 2026 17:10
llvm-upstreamsync Bot
pushed a commit
to qualcomm/cpullvm-toolchain
that referenced
this pull request
Jun 1, 2026
…(#200686) Update VPWidenPHIRecipe, VPBlendRecipe and VPReductionRecipe to assert type correctness at construction. PR: llvm/llvm-project#200686
llvm-sync Bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
Jun 1, 2026
…(#200686) Update VPWidenPHIRecipe, VPBlendRecipe and VPReductionRecipe to assert type correctness at construction. PR: llvm/llvm-project#200686
llvm-upstreamsync Bot
pushed a commit
to qualcomm/cpullvm-toolchain
that referenced
this pull request
Jun 11, 2026
…(#201209) With llvm/llvm-project#200692 and llvm/llvm-project#200686, types are no checked at construction, and each operation that changes operands (setOperand, addOperand etc) verifies that the replacement happens with suitable types. This should remove the need for running type checking as part of the verifier. PR: llvm/llvm-project#201209
llvm-sync Bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
Jun 11, 2026
…(#201209) With llvm/llvm-project#200692 and llvm/llvm-project#200686, types are no checked at construction, and each operation that changes operands (setOperand, addOperand etc) verifies that the replacement happens with suitable types. This should remove the need for running type checking as part of the verifier. PR: llvm/llvm-project#201209
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Update VPWidenPHIRecipe, VPBlendRecipe and VPReductionRecipe to assert type correctness at construction.