From 7743badafa68ea15f5762fd9c20321fca564f1aa Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sat, 27 Aug 2022 22:06:11 +0100 Subject: [PATCH] [VPlan] Verify that header only contains header phi recipes. Add verification that VPHeaderPHIRecipes are only in header VPBBs. Also adds missing checks for VPPointerInductionRecipe to VPHeaderPHIRecipe::classof. Split off from D119661. Reviewed By: Ayal Differential Revision: https://reviews.llvm.org/D131989 --- llvm/lib/Transforms/Vectorize/VPlan.h | 2 ++ llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp | 39 +++++++++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index 75a544a..eab1223 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -1139,6 +1139,7 @@ public: B->getVPDefID() == VPRecipeBase::VPFirstOrderRecurrencePHISC || B->getVPDefID() == VPRecipeBase::VPReductionPHISC || B->getVPDefID() == VPRecipeBase::VPWidenIntOrFpInductionSC || + B->getVPDefID() == VPRecipeBase::VPWidenPointerInductionSC || B->getVPDefID() == VPRecipeBase::VPWidenPHISC; } static inline bool classof(const VPValue *V) { @@ -1147,6 +1148,7 @@ public: V->getVPValueID() == VPValue::VPVFirstOrderRecurrencePHISC || V->getVPValueID() == VPValue::VPVReductionPHISC || V->getVPValueID() == VPValue::VPVWidenIntOrFpInductionSC || + V->getVPValueID() == VPValue::VPVWidenPointerInductionSC || V->getVPValueID() == VPValue::VPVWidenPHISC; } diff --git a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp index 91ab693..34c8149 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp @@ -133,17 +133,38 @@ void VPlanVerifier::verifyHierarchicalCFG( verifyRegionRec(TopRegion); } -static bool -verifyVPBasicBlock(const VPBasicBlock *VPBB, - DenseMap &BlockNumbering) { - // Verify that phi-like recipes are at the beginning of the block, with no - // other recipes in between. +// Verify that phi-like recipes are at the beginning of \p VPBB, with no +// other recipes in between. Also check that only header blocks contain +// VPHeaderPHIRecipes. +static bool verifyPhiRecipes(const VPBasicBlock *VPBB) { auto RecipeI = VPBB->begin(); auto End = VPBB->end(); unsigned NumActiveLaneMaskPhiRecipes = 0; + const VPRegionBlock *ParentR = VPBB->getParent(); + bool IsHeaderVPBB = ParentR && !ParentR->isReplicator() && + ParentR->getEntryBasicBlock() == VPBB; while (RecipeI != End && RecipeI->isPhi()) { if (isa(RecipeI)) NumActiveLaneMaskPhiRecipes++; + + if (IsHeaderVPBB && !isa(*RecipeI)) { + errs() << "Found non-header PHI recipe in header VPBB"; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) + errs() << ": "; + RecipeI->dump(); +#endif + return false; + } + + if (!IsHeaderVPBB && isa(*RecipeI)) { + errs() << "Found header PHI recipe in non-header VPBB"; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) + errs() << ": "; + RecipeI->dump(); +#endif + return false; + } + RecipeI++; } @@ -166,6 +187,14 @@ verifyVPBasicBlock(const VPBasicBlock *VPBB, } RecipeI++; } + return true; +} + +static bool +verifyVPBasicBlock(const VPBasicBlock *VPBB, + DenseMap &BlockNumbering) { + if (!verifyPhiRecipes(VPBB)) + return false; // Verify that defs in VPBB dominate all their uses. The current // implementation is still incomplete. -- 2.7.4