[llvm] [VPlan] Only exempt MaskedCond from cross-block dominance in verifier. (PR #226512)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 25 07:52:26 PDT 2026
https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/226512
Previously the verifier skipped all use-before-def checks for MaskedCond,
including uses in the same block before the definition. Restrict the
exemption to users in blocks not dominated by the MaskedCond's block, so
same-block use-before-def is still diagnosed.
>From 54920b7ed3167c05b0f454c21f85249e7c8278ad Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Fri, 25 Sep 2026 14:21:23 +0100
Subject: [PATCH 1/2] Add verifier test
---
.../Transforms/Vectorize/VPlanVerifierTest.cpp | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
index 7ce87be841c2d..86dc6da2aa514 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
@@ -66,6 +66,24 @@ TEST_F(VPVerifierTest, VPInstructionUseBeforeDefSameBB) {
#endif
}
+TEST_F(VPVerifierTest, MaskedCondUseBeforeDefSameBB) {
+ VPlan &Plan = getPlan();
+ auto *DefI = new VPInstruction(VPInstruction::MaskedCond, {Plan.getFalse()});
+ VPBasicBlock *Entry = Plan.getEntry();
+ Entry->appendRecipe(new VPInstruction(Instruction::Freeze, {DefI}));
+ Entry->appendRecipe(DefI);
+ VPBlockUtils::connectBlocks(Entry, Plan.getScalarHeader());
+
+#if GTEST_HAS_STREAM_REDIRECTION
+ ::testing::internal::CaptureStderr();
+#endif
+ EXPECT_FALSE(verifyVPlanIsValid(Plan));
+#if GTEST_HAS_STREAM_REDIRECTION
+ EXPECT_TRUE(StringRef(::testing::internal::GetCapturedStderr())
+ .starts_with("Use before def!\n"));
+#endif
+}
+
TEST_F(VPVerifierTest, VPInstructionUseBeforeDefDifferentBB) {
VPlan &Plan = getPlan();
VPIRValue *Zero = Plan.getConstantInt(32, 0);
>From 5cbad1d9abeacbee29774ac389246dadc425c3c8 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Fri, 25 Sep 2026 09:38:03 +0100
Subject: [PATCH 2/2] [VPlan] Only exempt MaskedCond from cross-block dominance
in verifier.
Previously the verifier skipped all use-before-def checks for MaskedCond,
including uses in the same block before the definition. Restrict the
exemption to users in blocks not dominated by the MaskedCond's block, so
same-block use-before-def is still diagnosed.
---
llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
index e36ad81cfae2a..6fbd53d529380 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
@@ -248,11 +248,6 @@ bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {
return false;
}
- // MaskedCond may be used from blocks it don't dominate; the block will be
- // linearized and it will dominate its users after linearization.
- if (match(&R, m_VPInstruction<VPInstruction::MaskedCond>()))
- continue;
-
for (const VPUser *U : V->users()) {
auto *UI = cast<VPRecipeBase>(U);
if (isa<VPIRPhi>(UI) &&
@@ -293,7 +288,11 @@ bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {
if (RecipeNumbering[UI] >= RecipeNumbering[&R])
continue;
} else {
- if (VPDT.dominates(VPBB, UI->getParent()))
+ // MaskedCond may be used from blocks it don't dominate; the block
+ // will be linearized and it will dominate its users after
+ // linearization.
+ if (match(&R, m_VPInstruction<VPInstruction::MaskedCond>()) ||
+ VPDT.dominates(VPBB, UI->getParent()))
continue;
}
More information about the llvm-commits
mailing list