Skip to content

Commit ba2dacd

Browse files
committed
[VPlan] Print use and definition in verifier on violation.
Improves the error message when a use comes before the def by including the use and def, when print utilities are available.
1 parent 137aa57 commit ba2dacd

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "VPlan.h"
1717
#include "VPlanCFG.h"
1818
#include "VPlanDominatorTree.h"
19+
#include "VPlanHelpers.h"
1920
#include "llvm/ADT/SmallPtrSet.h"
2021
#include "llvm/ADT/TypeSwitch.h"
2122

@@ -230,17 +231,22 @@ bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {
230231
// If the user is in the same block, check it comes after R in the
231232
// block.
232233
if (UI->getParent() == VPBB) {
233-
if (RecipeNumbering[UI] < RecipeNumbering[&R]) {
234-
errs() << "Use before def!\n";
235-
return false;
236-
}
237-
continue;
234+
if (RecipeNumbering[UI] >= RecipeNumbering[&R])
235+
continue;
236+
} else {
237+
if (VPDT.dominates(VPBB, UI->getParent()))
238+
continue;
238239
}
239240

240-
if (!VPDT.dominates(VPBB, UI->getParent())) {
241-
errs() << "Use before def!\n";
242-
return false;
243-
}
241+
errs() << "Use before def!\n";
242+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
243+
VPSlotTracker Tracker(VPBB->getPlan());
244+
UI->print(errs(), " ", Tracker);
245+
errs() << "\n before\n";
246+
R.print(errs(), " ", Tracker);
247+
errs() << "\n";
248+
#endif
249+
return false;
244250
}
245251
}
246252
if (const auto *EVL = dyn_cast<VPInstruction>(&R)) {

llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,17 @@ TEST_F(VPVerifierTest, VPInstructionUseBeforeDefSameBB) {
4141
#endif
4242
EXPECT_FALSE(verifyVPlanIsValid(Plan));
4343
#if GTEST_HAS_STREAM_REDIRECTION
44+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
45+
EXPECT_STREQ("Use before def!\n"
46+
" EMIT vp<%1> = sub vp<%2>\n"
47+
" before\n"
48+
" EMIT vp<%2> = add ir<0>\n",
49+
::testing::internal::GetCapturedStderr().c_str());
50+
#else
4451
EXPECT_STREQ("Use before def!\n",
4552
::testing::internal::GetCapturedStderr().c_str());
4653
#endif
54+
#endif
4755
}
4856

4957
TEST_F(VPVerifierTest, VPInstructionUseBeforeDefDifferentBB) {
@@ -72,9 +80,17 @@ TEST_F(VPVerifierTest, VPInstructionUseBeforeDefDifferentBB) {
7280
#endif
7381
EXPECT_FALSE(verifyVPlanIsValid(Plan));
7482
#if GTEST_HAS_STREAM_REDIRECTION
83+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
84+
EXPECT_STREQ("Use before def!\n"
85+
" EMIT vp<%1> = sub vp<%3>\n"
86+
" before\n"
87+
" EMIT vp<%3> = add ir<0>\n",
88+
::testing::internal::GetCapturedStderr().c_str());
89+
#else
7590
EXPECT_STREQ("Use before def!\n",
7691
::testing::internal::GetCapturedStderr().c_str());
7792
#endif
93+
#endif
7894
}
7995

8096
TEST_F(VPVerifierTest, VPBlendUseBeforeDefDifferentBB) {
@@ -112,8 +128,16 @@ TEST_F(VPVerifierTest, VPBlendUseBeforeDefDifferentBB) {
112128
#endif
113129
EXPECT_FALSE(verifyVPlanIsValid(Plan));
114130
#if GTEST_HAS_STREAM_REDIRECTION
131+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
132+
EXPECT_STREQ("Use before def!\n"
133+
" BLEND ir<<badref>> = vp<%2>\n"
134+
" before\n"
135+
" EMIT vp<%2> = add ir<0>\n",
136+
::testing::internal::GetCapturedStderr().c_str());
137+
#else
115138
EXPECT_STREQ("Use before def!\n",
116139
::testing::internal::GetCapturedStderr().c_str());
140+
#endif
117141
#endif
118142

119143
delete Phi;

0 commit comments

Comments
 (0)