[PATCH] D129717: [VPlan] Initial def-use verification.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 13 19:04:48 PDT 2022
fhahn created this revision.
fhahn added reviewers: Ayal, gilr, rengolin.
Herald added subscribers: tschuett, psnobl, rogfer01, bollu, hiraditya.
Herald added a project: All.
fhahn requested review of this revision.
Herald added a subscriber: vkmr.
Herald added a project: LLVM.
This patch introduces some initial def-use verification. This catches
cases like the one fixed by D129436 <https://reviews.llvm.org/D129436>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129717
Files:
llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
Index: llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
+++ llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
@@ -133,7 +133,9 @@
verifyRegionRec(TopRegion);
}
-static bool verifyVPBasicBlock(const VPBasicBlock *VPBB) {
+static bool
+verifyVPBasicBlock(const VPBasicBlock *VPBB,
+ DenseMap<const VPBlockBase *, unsigned> &BlockNumbering) {
// Verify that phi-like recipes are at the beginning of the block, with no
// other recipes in between.
auto RecipeI = VPBB->begin();
@@ -165,15 +167,73 @@
RecipeI++;
}
+ // Verify that defs in VPBB dominate all their uses. The current
+ // implementation is still incomplete.
+ DenseMap<const VPRecipeBase *, unsigned> RecipeNumbering;
+ unsigned Cnt = 0;
+ for (const VPRecipeBase &R : *VPBB)
+ RecipeNumbering[&R] = Cnt++;
+
+ for (const VPRecipeBase &R : *VPBB) {
+ for (const VPValue *V : R.definedValues()) {
+ for (const VPUser *U : V->users()) {
+ auto *UI = dyn_cast<VPRecipeBase>(U);
+ if (!UI || isa<VPHeaderPHIRecipe>(UI))
+ continue;
+
+ // If the user is in the same block, check it comes after R in the
+ // block.
+ if (UI->getParent() == VPBB) {
+ if (RecipeNumbering[UI] < RecipeNumbering[&R]) {
+ errs() << "Use before def!\n";
+ return false;
+ }
+ continue;
+ }
+
+ // Skip blocks outside any region for now
+ auto *ParentR = VPBB->getParent();
+ if (!ParentR)
+ continue;
+
+ // For replicators, verify that VPPRedInstPHIRecipe defs are only used
+ // in subsequent blocks.
+ if (ParentR->isReplicator()) {
+ if (isa<VPPredInstPHIRecipe>(&R)) {
+ if (BlockNumbering[UI->getParent()] < BlockNumbering[ParentR]) {
+ errs() << "Use before def!\n";
+ return false;
+ }
+ continue;
+ }
+
+ // All non-VPPredInstPHIRecipe recipes in the block must be used in
+ // the replicate region only.
+ if (UI->getParent()->getParent() != ParentR) {
+ errs() << "Use before def!\n";
+ return false;
+ }
+ }
+ }
+ }
+ }
return true;
}
bool VPlanVerifier::verifyPlanIsValid(const VPlan &Plan) {
+ DenseMap<const VPBlockBase *, unsigned> BlockNumbering;
+ unsigned Cnt = 0;
+ auto Iter1 = depth_first(
+ VPBlockRecursiveTraversalWrapper<const VPBlockBase *>(Plan.getEntry()));
+
+ for (const VPBlockBase *VPB : Iter1)
+ BlockNumbering[VPB] = Cnt++;
+
auto Iter = depth_first(
VPBlockRecursiveTraversalWrapper<const VPBlockBase *>(Plan.getEntry()));
for (const VPBasicBlock *VPBB :
VPBlockUtils::blocksOnly<const VPBasicBlock>(Iter)) {
- if (!verifyVPBasicBlock(VPBB))
+ if (!verifyVPBasicBlock(VPBB, BlockNumbering))
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129717.444488.patch
Type: text/x-patch
Size: 3013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220714/6ac7428d/attachment.bin>
More information about the llvm-commits
mailing list