[llvm] [VPlan] Verify dominance for incoming values of phi-like recipes. (PR #124838)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 29 01:31:45 PST 2025
================
@@ -207,22 +212,65 @@ bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {
for (const VPUser *U : V->users()) {
auto *UI = cast<VPRecipeBase>(U);
- // TODO: check dominance of incoming values for phis properly.
- if (!UI ||
- isa<VPHeaderPHIRecipe, VPWidenPHIRecipe, VPPredInstPHIRecipe>(UI))
+ const VPBlockBase *UserVPBB = UI->getParent();
+
+ // Verify incoming values of VPIRInstructions wrapping phis. V most
+ // dominate the end of the incoming block. The operand index of the
+ // incoming value matches the predecessor block index of the
+ // corresponding incoming block.
+ if (isVPIRInstructionPhi(*UI)) {
+ for (const auto &[Idx, Op] : enumerate(UI->operands())) {
+ if (V != Op)
+ continue;
+ const VPBlockBase *Incoming = UserVPBB->getPredecessors()[Idx];
+ if (Incoming != VPBB && !VPDT.dominates(VPBB, Incoming)) {
+ errs() << "Use before def!\n";
+ return false;
+ }
+ }
continue;
+ }
+ // Verify incoming value of various phi-like recipes.
+ if (isa<VPWidenPHIRecipe, VPHeaderPHIRecipe, VPPredInstPHIRecipe>(UI)) {
+ const VPBlockBase *Incoming = nullptr;
+ // Get the incoming block based on the number of predecessors.
+ if (UserVPBB->getNumPredecessors() == 0) {
+ assert((isa<VPWidenPHIRecipe>(UI) || isa<VPHeaderPHIRecipe>(UI)) &&
+ "Unexpected recipe with 0 predecessors");
+ const VPRegionBlock *UserRegion = UserVPBB->getParent();
+ Incoming = V == UI->getOperand(0)
+ ? UserRegion->getSinglePredecessor()
+ : UserRegion->getExiting();
+ } else if (UserVPBB->getNumPredecessors() == 1) {
+ assert(isa<VPWidenPHIRecipe>(UI) &&
+ "Unexpected recipe with 1 predecessors");
+ Incoming = UserVPBB->getSinglePredecessor();
+ } else {
+ assert(UserVPBB->getNumPredecessors() == 2 &&
+ isa<VPPredInstPHIRecipe>(UI) &&
+ "Unexpected recipe with 2 or more predecessors");
+ Incoming = UserVPBB->getPredecessors()[1];
+ }
+ if (auto *R = dyn_cast<VPRegionBlock>(Incoming))
----------------
david-arm wrote:
Just out of curiosity, what's the scenario where the incoming block for a VPWidenPHIRecipe, VPHeaderPHIRecipe or VPPredInstPHIRecipe recipe would be the region? Is it the recipes we create in the middle block? If so, could this check potentially fail with uncountable early exits, i.e. the incoming block is effectively the middle.split block? I assume it's fine, but just wondering if there are missing tests for all the scenarios.
https://github.com/llvm/llvm-project/pull/124838
More information about the llvm-commits
mailing list