Skip to content

Commit 56d4784

Browse files
committed
!fxup improve verifier message, add verification test.
1 parent 370eaf1 commit 56d4784

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,22 @@ bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {
219219

220220
for (const VPUser *U : V->users()) {
221221
auto *UI = cast<VPRecipeBase>(U);
222-
const VPBlockBase *UserVPBB = UI->getParent();
223222
if (auto *Phi = dyn_cast<VPPhiAccessors>(UI)) {
224223
for (unsigned Idx = 0; Idx != Phi->getNumIncoming(); ++Idx) {
225224
VPValue *IncVPV = Phi->getIncomingValue(Idx);
226225
const VPBasicBlock *IncVPBB = Phi->getIncomingBlock(Idx);
227226
if (IncVPV != V)
228227
continue;
229228
if (IncVPBB != VPBB && !VPDT.dominates(VPBB, IncVPBB)) {
230-
errs() << "Use before def!\n";
229+
errs() << "Incoming def at index " << Idx
230+
<< " does not dominate incoming block!\n";
231+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
232+
VPSlotTracker Tracker(VPBB->getPlan());
233+
IncVPV->getDefiningRecipe()->print(errs(), " ", Tracker);
234+
errs() << "\n does not dominate " << IncVPBB->getName()
235+
<< " for\n";
236+
UI->print(errs(), " ", Tracker);
237+
#endif
231238
return false;
232239
}
233240
}

llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,43 @@ TEST_F(VPVerifierTest, VPBlendUseBeforeDefDifferentBB) {
143143
delete Phi;
144144
}
145145

146+
TEST_F(VPVerifierTest, VPPhiIncomingValueDoesntDominateIncomingBlock) {
147+
VPlan &Plan = getPlan();
148+
IntegerType *Int32 = IntegerType::get(C, 32);
149+
VPValue *Zero = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 0));
150+
151+
VPBasicBlock *VPBB1 = Plan.getEntry();
152+
VPBasicBlock *VPBB2 = Plan.createVPBasicBlock("");
153+
VPBasicBlock *VPBB3 = Plan.createVPBasicBlock("");
154+
155+
VPInstruction *DefI = new VPInstruction(Instruction::Add, {Zero});
156+
VPPhi *Phi = new VPPhi({DefI}, {});
157+
VPBB2->appendRecipe(Phi);
158+
VPBB2->appendRecipe(DefI);
159+
auto *CanIV = new VPCanonicalIVPHIRecipe(Zero, {});
160+
VPBB3->appendRecipe(CanIV);
161+
162+
VPRegionBlock *R1 = Plan.createVPRegionBlock(VPBB3, VPBB3, "R1");
163+
VPBlockUtils::connectBlocks(VPBB1, VPBB2);
164+
VPBlockUtils::connectBlocks(VPBB2, R1);
165+
#if GTEST_HAS_STREAM_REDIRECTION
166+
::testing::internal::CaptureStderr();
167+
#endif
168+
EXPECT_FALSE(verifyVPlanIsValid(Plan));
169+
#if GTEST_HAS_STREAM_REDIRECTION
170+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
171+
EXPECT_STREQ("Incoming def at index 0 does not dominate incoming block!\n"
172+
" EMIT vp<%2> = add ir<0>\n"
173+
" does not dominate preheader for\n"
174+
" EMIT vp<%1> = phi [ vp<%2>, preheader ]",
175+
::testing::internal::GetCapturedStderr().c_str());
176+
#else
177+
EXPECT_STREQ("Use before def!\n",
178+
::testing::internal::GetCapturedStderr().c_str());
179+
#endif
180+
#endif
181+
}
182+
146183
TEST_F(VPVerifierTest, DuplicateSuccessorsOutsideRegion) {
147184
VPlan &Plan = getPlan();
148185
VPValue *Zero = Plan.getOrAddLiveIn(ConstantInt::get(Type::getInt32Ty(C), 0));

0 commit comments

Comments
 (0)