[PATCH] D111302: [VPlan] Add initial VPlan verification.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 27 04:17:59 PDT 2021
fhahn updated this revision to Diff 382601.
fhahn added a comment.
In D111302#3085781 <https://reviews.llvm.org/D111302#3085781>, @Ayal wrote:
> Looks good to me, thanks!
> Perhaps also worth checking that all header-phi recipes reside in the header?
That sounds like a good idea. I'll put up a follow-up patch, to keep the patches smaller in case they highlight any issues.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D111302/new/
https://reviews.llvm.org/D111302
Files:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
llvm/lib/Transforms/Vectorize/VPlanVerifier.h
Index: llvm/lib/Transforms/Vectorize/VPlanVerifier.h
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlanVerifier.h
+++ llvm/lib/Transforms/Vectorize/VPlanVerifier.h
@@ -26,6 +26,7 @@
namespace llvm {
class VPRegionBlock;
+class VPlan;
/// Struct with utility functions that can be used to check the consistency and
/// invariants of a VPlan, including the components of its H-CFG.
@@ -35,6 +36,12 @@
/// 1. Region/Block verification: Check the Region/Block verification
/// invariants for every region in the H-CFG.
void verifyHierarchicalCFG(const VPRegionBlock *TopRegion) const;
+
+ /// Verify invariants for general VPlans. Currently it checks the following:
+ /// 1. all phi-like recipes must be at the beginning of a block, with no other
+ /// recipes in between. Note that currently there is still an exception for
+ /// VPBlendRecipes.
+ static bool verifyPlanIsValid(const VPlan &Plan);
};
} // namespace llvm
Index: llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
+++ llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
@@ -128,3 +128,31 @@
assert(!TopRegion->getParent() && "VPlan Top Region should have no parent.");
verifyRegionRec(TopRegion);
}
+
+bool VPlanVerifier::verifyPlanIsValid(const VPlan &Plan) {
+ auto Iter = depth_first(
+ VPBlockRecursiveTraversalWrapper<const VPBlockBase *>(Plan.getEntry()));
+ for (const VPBasicBlock *VPBB :
+ VPBlockUtils::blocksOnly<const VPBasicBlock>(Iter)) {
+ // Verify that phi-like recipes are at the beginning of the block, with no
+ // other recipes in between.
+ auto RecipeI = VPBB->begin();
+ auto End = VPBB->end();
+ while (RecipeI != End && RecipeI->isPhi())
+ RecipeI++;
+
+ while (RecipeI != End) {
+ // FIXME: At the moment, creating a mask might insert non-phi recipes
+ // before VPBlendRecipes.
+ if (RecipeI->isPhi() && !isa<VPBlendRecipe>(&*RecipeI)) {
+ errs() << "Found phi-like recipe after non-phi recipe:";
+ RecipeI->dump();
+ errs() << "after\n";
+ std::prev(RecipeI)->dump();
+ return false;
+ }
+ RecipeI++;
+ }
+ }
+ return true;
+}
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -9523,6 +9523,7 @@
RSO.flush();
Plan->setName(PlanName);
+ assert(VPlanVerifier::verifyPlanIsValid(*Plan) && "VPlan is invalid");
return Plan;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111302.382601.patch
Type: text/x-patch
Size: 2712 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211027/f8da7786/attachment.bin>
More information about the llvm-commits
mailing list