Skip to content

Commit 9923d29

Browse files
committed
[VPlan] Merge main VPlan verifer with HCFG verifier.
Unify VPlan verifiers in verifyVPlanIsValid. This adds verification for various properties on blocks to the verifier used for VPlans generated by the inner loop vectorizer. It also adds def-use checks for the verifier used in the VPlan native path. This drops the separate flag to enable HCFG verification. Instead, all VPlans are verified once they have been created, if assertions are enabled. This also removes VPWidenPHIRecipe from VPHeaderPHIRecipe; it is used to model any phi node in the native path.
1 parent 9facaad commit 9923d29

File tree

10 files changed

+274
-170
lines changed

10 files changed

+274
-170
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "VPlanAnalysis.h"
6161
#include "VPlanHCFGBuilder.h"
6262
#include "VPlanTransforms.h"
63+
#include "VPlanVerifier.h"
6364
#include "llvm/ADT/APInt.h"
6465
#include "llvm/ADT/ArrayRef.h"
6566
#include "llvm/ADT/DenseMap.h"
@@ -8490,7 +8491,7 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
84908491
VPlanTransforms::truncateToMinimalBitwidths(
84918492
*Plan, CM.getMinimalBitwidths(), PSE.getSE()->getContext());
84928493
VPlanTransforms::optimize(*Plan, *PSE.getSE());
8493-
assert(VPlanVerifier::verifyPlanIsValid(*Plan) && "VPlan is invalid");
8494+
assert(verifyVPlanIsValid(*Plan) && "VPlan is invalid");
84948495
VPlans.push_back(std::move(Plan));
84958496
}
84968497
VF = SubRange.End;
@@ -8825,6 +8826,7 @@ VPlanPtr LoopVectorizationPlanner::buildVPlan(VFRange &Range) {
88258826
bool HasNUW = true;
88268827
addCanonicalIVRecipes(*Plan, Legal->getWidestInductionType(), HasNUW,
88278828
DebugLoc());
8829+
assert(verifyVPlanIsValid(*Plan) && "VPlan is invalid");
88288830
return Plan;
88298831
}
88308832

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,8 @@ static bool hasConditionalTerminator(const VPBasicBlock *VPBB) {
559559
VPI->getOpcode() == VPInstruction::BranchOnCount));
560560
(void)IsCondBranch;
561561

562-
if (VPBB->getNumSuccessors() >= 2 || VPBB->isExiting()) {
562+
if (VPBB->getNumSuccessors() >= 2 ||
563+
(VPBB->isExiting() && !VPBB->getParent()->isReplicator())) {
563564
assert(IsCondBranch && "block with multiple successors not terminated by "
564565
"conditional branch recipe");
565566

@@ -585,7 +586,7 @@ const VPRecipeBase *VPBasicBlock::getTerminator() const {
585586
}
586587

587588
bool VPBasicBlock::isExiting() const {
588-
return getParent()->getExitingBasicBlock() == this;
589+
return getParent() && getParent()->getExitingBasicBlock() == this;
589590
}
590591

591592
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
@@ -1333,7 +1334,7 @@ void VPInterleavedAccessInfo::visitBlock(VPBlockBase *Block, Old2NewTy &Old2New,
13331334
InterleavedAccessInfo &IAI) {
13341335
if (VPBasicBlock *VPBB = dyn_cast<VPBasicBlock>(Block)) {
13351336
for (VPRecipeBase &VPI : *VPBB) {
1336-
if (isa<VPHeaderPHIRecipe>(&VPI))
1337+
if (isa<VPWidenPHIRecipe>(&VPI))
13371338
continue;
13381339
assert(isa<VPInstruction>(&VPI) && "Can only handle VPInstructions");
13391340
auto *VPInst = cast<VPInstruction>(&VPI);

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,17 +1736,17 @@ class VPWidenPointerInductionRecipe : public VPHeaderPHIRecipe {
17361736
#endif
17371737
};
17381738

1739-
/// A recipe for handling header phis that are widened in the vector loop.
1739+
/// A recipe for handling phis that are widened in the vector loop.
17401740
/// In the VPlan native path, all incoming VPValues & VPBasicBlock pairs are
17411741
/// managed in the recipe directly.
1742-
class VPWidenPHIRecipe : public VPHeaderPHIRecipe {
1742+
class VPWidenPHIRecipe : public VPSingleDefRecipe {
17431743
/// List of incoming blocks. Only used in the VPlan native path.
17441744
SmallVector<VPBasicBlock *, 2> IncomingBlocks;
17451745

17461746
public:
17471747
/// Create a new VPWidenPHIRecipe for \p Phi with start value \p Start.
17481748
VPWidenPHIRecipe(PHINode *Phi, VPValue *Start = nullptr)
1749-
: VPHeaderPHIRecipe(VPDef::VPWidenPHISC, Phi) {
1749+
: VPSingleDefRecipe(VPDef::VPWidenPHISC, ArrayRef<VPValue *>(), Phi) {
17501750
if (Start)
17511751
addOperand(Start);
17521752
}

llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,6 @@ void VPlanHCFGBuilder::buildHierarchicalCFG() {
437437
buildPlainCFG();
438438
LLVM_DEBUG(Plan.setName("HCFGBuilder: Plain CFG\n"); dbgs() << Plan);
439439

440-
VPRegionBlock *TopRegion = Plan.getVectorLoopRegion();
441-
Verifier.verifyHierarchicalCFG(TopRegion);
442-
443440
// Compute plain CFG dom tree for VPLInfo.
444441
VPDomTree.recalculate(Plan);
445442
LLVM_DEBUG(dbgs() << "Dominator Tree after building the plain CFG.\n";

llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#define LLVM_TRANSFORMS_VECTORIZE_VPLAN_VPLANHCFGBUILDER_H
2626

2727
#include "VPlanDominatorTree.h"
28-
#include "VPlanVerifier.h"
2928

3029
namespace llvm {
3130

@@ -49,9 +48,6 @@ class VPlanHCFGBuilder {
4948
// The VPlan that will contain the H-CFG we are building.
5049
VPlan &Plan;
5150

52-
// VPlan verifier utility.
53-
VPlanVerifier Verifier;
54-
5551
// Dominator analysis for VPlan plain CFG to be used in the
5652
// construction of the H-CFG. This analysis is no longer valid once regions
5753
// are introduced.

llvm/lib/Transforms/Vectorize/VPlanValue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,13 @@ class VPDef {
362362
VPWidenSelectSC,
363363
// START: Phi-like recipes. Need to be kept together.
364364
VPBlendSC,
365+
VPWidenPHISC,
365366
VPPredInstPHISC,
366367
// START: SubclassID for recipes that inherit VPHeaderPHIRecipe.
367368
// VPHeaderPHIRecipe need to be kept together.
368369
VPCanonicalIVPHISC,
369370
VPActiveLaneMaskPHISC,
370371
VPFirstOrderRecurrencePHISC,
371-
VPWidenPHISC,
372372
VPWidenIntOrFpInductionSC,
373373
VPWidenPointerInductionSC,
374374
VPReductionPHISC,

0 commit comments

Comments
 (0)