Skip to content

Commit b6b3d20

Browse files
committed
[VPlan] Use VPDominatorTree in VPlanVerifier .
Use VPDominatorTree to generalize def-use verification. Depends on D140513. Reviewed By: Ayal Differential Revision: https://reviews.llvm.org/D140514
1 parent 93aa412 commit b6b3d20

File tree

2 files changed

+18
-41
lines changed

2 files changed

+18
-41
lines changed

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "VPlanVerifier.h"
1616
#include "VPlan.h"
1717
#include "VPlanCFG.h"
18+
#include "VPlanDominatorTree.h"
1819
#include "llvm/ADT/DepthFirstIterator.h"
1920
#include "llvm/Support/CommandLine.h"
2021

@@ -189,9 +190,8 @@ static bool verifyPhiRecipes(const VPBasicBlock *VPBB) {
189190
return true;
190191
}
191192

192-
static bool
193-
verifyVPBasicBlock(const VPBasicBlock *VPBB,
194-
DenseMap<const VPBlockBase *, unsigned> &BlockNumbering) {
193+
static bool verifyVPBasicBlock(const VPBasicBlock *VPBB,
194+
VPDominatorTree &VPDT) {
195195
if (!verifyPhiRecipes(VPBB))
196196
return false;
197197

@@ -206,7 +206,8 @@ verifyVPBasicBlock(const VPBasicBlock *VPBB,
206206
for (const VPValue *V : R.definedValues()) {
207207
for (const VPUser *U : V->users()) {
208208
auto *UI = dyn_cast<VPRecipeBase>(U);
209-
if (!UI || isa<VPHeaderPHIRecipe>(UI))
209+
// TODO: check dominance of incoming values for phis properly.
210+
if (!UI || isa<VPHeaderPHIRecipe>(UI) || isa<VPPredInstPHIRecipe>(UI))
210211
continue;
211212

212213
// If the user is in the same block, check it comes after R in the
@@ -219,27 +220,7 @@ verifyVPBasicBlock(const VPBasicBlock *VPBB,
219220
continue;
220221
}
221222

222-
// Skip blocks outside any region for now and blocks outside
223-
// replicate-regions.
224-
auto *ParentR = VPBB->getParent();
225-
if (!ParentR || !ParentR->isReplicator())
226-
continue;
227-
228-
// For replicators, verify that VPPRedInstPHIRecipe defs are only used
229-
// in subsequent blocks.
230-
if (isa<VPPredInstPHIRecipe>(&R)) {
231-
auto I = BlockNumbering.find(UI->getParent());
232-
unsigned BlockNumber = I == BlockNumbering.end() ? std::numeric_limits<unsigned>::max() : I->second;
233-
if (BlockNumber < BlockNumbering[ParentR]) {
234-
errs() << "Use before def!\n";
235-
return false;
236-
}
237-
continue;
238-
}
239-
240-
// All non-VPPredInstPHIRecipe recipes in the block must be used in
241-
// the replicate region only.
242-
if (UI->getParent()->getParent() != ParentR) {
223+
if (!VPDT.dominates(VPBB, UI->getParent())) {
243224
errs() << "Use before def!\n";
244225
return false;
245226
}
@@ -250,15 +231,13 @@ verifyVPBasicBlock(const VPBasicBlock *VPBB,
250231
}
251232

252233
bool VPlanVerifier::verifyPlanIsValid(const VPlan &Plan) {
253-
DenseMap<const VPBlockBase *, unsigned> BlockNumbering;
254-
unsigned Cnt = 0;
234+
VPDominatorTree VPDT;
235+
VPDT.recalculate(const_cast<VPlan &>(Plan));
236+
255237
auto Iter = vp_depth_first_deep(Plan.getEntry());
256-
for (const VPBlockBase *VPB : Iter) {
257-
BlockNumbering[VPB] = Cnt++;
258-
auto *VPBB = dyn_cast<VPBasicBlock>(VPB);
259-
if (!VPBB)
260-
continue;
261-
if (!verifyVPBasicBlock(VPBB, BlockNumbering))
238+
for (const VPBasicBlock *VPBB :
239+
VPBlockUtils::blocksOnly<const VPBasicBlock>(Iter)) {
240+
if (!verifyVPBasicBlock(VPBB, VPDT))
262241
return false;
263242
}
264243

llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,13 @@ TEST(VPVerifierTest, VPInstructionUseBeforeDefDifferentBB) {
5757
VPlan Plan;
5858
Plan.setEntry(VPBB1);
5959

60-
// TODO: UseI uses DefI but DefI does not dominate UseI. Currently missed by
61-
// the verifier.
6260
#if GTEST_HAS_STREAM_REDIRECTION
6361
::testing::internal::CaptureStderr();
6462
#endif
65-
EXPECT_TRUE(VPlanVerifier::verifyPlanIsValid(Plan));
63+
EXPECT_FALSE(VPlanVerifier::verifyPlanIsValid(Plan));
6664
#if GTEST_HAS_STREAM_REDIRECTION
67-
EXPECT_STREQ("", ::testing::internal::GetCapturedStderr().c_str());
65+
EXPECT_STREQ("Use before def!\n",
66+
::testing::internal::GetCapturedStderr().c_str());
6867
#endif
6968
}
7069

@@ -99,14 +98,13 @@ TEST(VPVerifierTest, VPBlendUseBeforeDefDifferentBB) {
9998
VPlan Plan;
10099
Plan.setEntry(VPBB1);
101100

102-
// TODO: Blend uses Def but Def does not dominate Blend. Currently missed by
103-
// the verifier.
104101
#if GTEST_HAS_STREAM_REDIRECTION
105102
::testing::internal::CaptureStderr();
106103
#endif
107-
EXPECT_TRUE(VPlanVerifier::verifyPlanIsValid(Plan));
104+
EXPECT_FALSE(VPlanVerifier::verifyPlanIsValid(Plan));
108105
#if GTEST_HAS_STREAM_REDIRECTION
109-
EXPECT_STREQ("", ::testing::internal::GetCapturedStderr().c_str());
106+
EXPECT_STREQ("Use before def!\n",
107+
::testing::internal::GetCapturedStderr().c_str());
110108
#endif
111109

112110
delete Phi;

0 commit comments

Comments
 (0)