Skip to content

[VPlan] Assert operand correctness at construction. (NFC) - #200686

Merged
fhahn merged 3 commits into
llvm:mainfrom
fhahn:vplan-assert-operands-at-construction
Jun 1, 2026
Merged

[VPlan] Assert operand correctness at construction. (NFC)#200686
fhahn merged 3 commits into
llvm:mainfrom
fhahn:vplan-assert-operands-at-construction

Conversation

@fhahn

@fhahn fhahn commented May 31, 2026

Copy link
Copy Markdown
Contributor

Update VPWidenPHIRecipe, VPBlendRecipe and VPReductionRecipe to assert type correctness at construction.

@llvmorg-github-actions

llvmorg-github-actions Bot commented May 31, 2026

Copy link
Copy Markdown

@llvm/pr-subscribers-vectorizers

@llvm/pr-subscribers-llvm-transforms

Author: Florian Hahn (fhahn)

Changes

Update VPWidenPHIRecipe, VPBlendRecipe and VPReductionRecipe to assert type correctness at construction.


Full diff: https://github.com/llvm/llvm-project/pull/200686.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/VPlan.h (+28-1)
  • (modified) llvm/unittests/Transforms/Vectorize/VPlanTest.cpp (+1-1)
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);

@github-actions

github-actions Bot commented May 31, 2026

Copy link
Copy Markdown

🪟 Windows x64 Test Results

  • 135294 tests passed
  • 3343 tests skipped

✅ The build succeeded and all tests passed.

@github-actions

github-actions Bot commented May 31, 2026

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 196061 tests passed
  • 5293 tests skipped

✅ The build succeeded and all tests passed.

Comment thread llvm/lib/Transforms/Vectorize/VPlan.h
RdxKind(RdxKind), Style(Style) {
assert(all_of(Operands,
[this](VPValue *VPV) {
return VPV->getScalarType() == getScalarType() ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because the EVL can be an operand in a FP reduction right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it gets added as operand for VPReductionEVLRecipe

fhahn added 2 commits June 1, 2026 14:14
Update VPWidenPHIRecipe, VPBlendRecipe and VPReductionRecipe to assert
type correctness at construction.
@fhahn
fhahn force-pushed the vplan-assert-operands-at-construction branch from 1fbb863 to e2cc94f Compare June 1, 2026 13:39
@fhahn
fhahn enabled auto-merge (squash) June 1, 2026 17:10
@fhahn
fhahn merged commit 294b72f into llvm:main Jun 1, 2026
9 of 10 checks passed
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
@fhahn
fhahn deleted the vplan-assert-operands-at-construction branch June 1, 2026 19:26
fhahn added a commit that referenced this pull request Jun 11, 2026
With #200692
and #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: #201209
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants