[llvm] aadf35c - [VPlan] Verify number preds and operands matches for VPIRPhis. (NFC)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon May 5 07:32:19 PDT 2025
Author: Florian Hahn
Date: 2025-05-05T15:32:02+01:00
New Revision: aadf35cb41db9bc4594d9a70cfdc6d43d795a097
URL: https://github.com/llvm/llvm-project/commit/aadf35cb41db9bc4594d9a70cfdc6d43d795a097
DIFF: https://github.com/llvm/llvm-project/commit/aadf35cb41db9bc4594d9a70cfdc6d43d795a097.diff
LOG: [VPlan] Verify number preds and operands matches for VPIRPhis. (NFC)
Extend the verifier to ensure the number of predecessors and operands
match for VPIRPhis.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
index 3f10b1756d7a1..b1528c401b459 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
@@ -97,6 +97,18 @@ bool VPlanVerifier::verifyPhiRecipes(const VPBasicBlock *VPBB) {
return false;
}
+ // Check if the recipe operands match the number of predecessors.
+ // TODO Extend to other phi-like recipes.
+ if (auto *PhiIRI = dyn_cast<VPIRPhi>(&*RecipeI)) {
+ if (PhiIRI->getNumOperands() != VPBB->getNumPredecessors()) {
+ errs() << "Phi-like recipe with
diff erent number of operands and "
+ "predecessors.\n";
+ // TODO: Print broken recipe. At the moment printing an ill-formed
+ // phi-like recipe may crash.
+ return false;
+ }
+ }
+
RecipeI++;
}
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
index 182c39cadecfa..95088bed68e98 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
@@ -223,4 +223,44 @@ TEST_F(VPVerifierTest, BlockOutsideRegionWithParent) {
#endif
}
+class VPIRVerifierTest : public VPlanTestIRBase {};
+
+TEST_F(VPIRVerifierTest, testVerifyIRPhi) {
+ const char *ModuleString =
+ "define void @f(ptr %A, i64 %N) {\n"
+ "entry:\n"
+ " br label %loop\n"
+ "loop:\n"
+ " %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n"
+ " %arr.idx = getelementptr inbounds i32, ptr %A, i64 %iv\n"
+ " %l1 = load i32, ptr %arr.idx, align 4\n"
+ " %res = add i32 %l1, 10\n"
+ " store i32 %res, ptr %arr.idx, align 4\n"
+ " %iv.next = add i64 %iv, 1\n"
+ " %exitcond = icmp ne i64 %iv.next, %N\n"
+ " br i1 %exitcond, label %loop, label %for.end\n"
+ "for.end:\n"
+ " %p = phi i32 [ %l1, %loop ]\n"
+ " ret void\n"
+ "}\n";
+
+ Module &M = parseModule(ModuleString);
+
+ Function *F = M.getFunction("f");
+ BasicBlock *LoopHeader = F->getEntryBlock().getSingleSuccessor();
+ auto Plan = buildVPlan(LoopHeader);
+
+ Plan->getExitBlocks()[0]->front().addOperand(
+ Plan->getOrAddLiveIn(ConstantInt::get(Type::getInt32Ty(*Ctx), 0)));
+
+#if GTEST_HAS_STREAM_REDIRECTION
+ ::testing::internal::CaptureStderr();
+#endif
+ EXPECT_FALSE(verifyVPlanIsValid(*Plan));
+#if GTEST_HAS_STREAM_REDIRECTION
+ EXPECT_STREQ(
+ "Phi-like recipe with
diff erent number of operands and predecessors.\n",
+ ::testing::internal::GetCapturedStderr().c_str());
+#endif
+}
} // namespace
More information about the llvm-commits
mailing list