Skip to content

Commit 08c5944

Browse files
authored
[VPlan] Fix header phi VPInstruction verification. NFC (#151472)
Noticed this when checking the invariant that all phis in the header block must be header phis. I think there's a missing set of parentheses here, since otherwise it only cast<VPInstruction> when RecipeI isn't a VPInstruction.
1 parent e2bd92e commit 08c5944

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ bool VPlanVerifier::verifyPhiRecipes(const VPBasicBlock *VPBB) {
7979
if (isa<VPActiveLaneMaskPHIRecipe>(RecipeI))
8080
NumActiveLaneMaskPhiRecipes++;
8181

82-
if (IsHeaderVPBB && !isa<VPHeaderPHIRecipe, VPWidenPHIRecipe>(*RecipeI) &&
83-
!isa<VPInstruction>(*RecipeI) &&
84-
cast<VPInstruction>(RecipeI)->getOpcode() == Instruction::PHI) {
82+
if (IsHeaderVPBB &&
83+
!isa<VPHeaderPHIRecipe, VPWidenPHIRecipe, VPPhi>(*RecipeI)) {
8584
errs() << "Found non-header PHI recipe in header VPBB";
8685
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
8786
errs() << ": ";

llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,37 @@ TEST_F(VPVerifierTest, BlockOutsideRegionWithParent) {
287287
#endif
288288
}
289289

290+
TEST_F(VPVerifierTest, NonHeaderPHIInHeader) {
291+
VPlan &Plan = getPlan();
292+
VPValue *Zero = Plan.getOrAddLiveIn(ConstantInt::get(Type::getInt32Ty(C), 0));
293+
auto *CanIV = new VPCanonicalIVPHIRecipe(Zero, {});
294+
auto *BranchOnCond = new VPInstruction(VPInstruction::BranchOnCond, {CanIV});
295+
296+
VPBasicBlock *VPBB1 = Plan.getEntry();
297+
VPBasicBlock *VPBB2 = Plan.createVPBasicBlock("header");
298+
299+
VPBB2->appendRecipe(CanIV);
300+
301+
PHINode *PHINode = PHINode::Create(Type::getInt32Ty(C), 2);
302+
auto *IRPhi = new VPIRPhi(*PHINode);
303+
VPBB2->appendRecipe(IRPhi);
304+
VPBB2->appendRecipe(BranchOnCond);
305+
306+
VPRegionBlock *R1 = Plan.createVPRegionBlock(VPBB2, VPBB2, "R1");
307+
VPBlockUtils::connectBlocks(VPBB1, R1);
308+
VPBlockUtils::connectBlocks(R1, Plan.getScalarHeader());
309+
310+
#if GTEST_HAS_STREAM_REDIRECTION
311+
::testing::internal::CaptureStderr();
312+
#endif
313+
EXPECT_FALSE(verifyVPlanIsValid(Plan));
314+
#if GTEST_HAS_STREAM_REDIRECTION
315+
EXPECT_STREQ(
316+
"Found non-header PHI recipe in header VPBB: IR <badref> = phi i32 \n",
317+
::testing::internal::GetCapturedStderr().c_str());
318+
#endif
319+
}
320+
290321
class VPIRVerifierTest : public VPlanTestIRBase {};
291322

292323
TEST_F(VPIRVerifierTest, testVerifyIRPhi) {

0 commit comments

Comments
 (0)