From 337d7652823f59f4613552cebdf81292bf8f393d Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Fri, 7 May 2021 21:05:58 +0100 Subject: [PATCH] [LV] Assert if trying to sink replicate region into another region (NFC) Currently sinking a replicate region into another replicate region is not supported. Add an assert, to make the problem more obvious, should it occur. Discussed post-commit for ccebf7a1096a. --- .../Transforms/Vectorize/LoopVectorize.cpp | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 5b61734a1812..933722480343 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -9116,25 +9116,30 @@ VPlanPtr LoopVectorizationPlanner::buildVPlanWithVPRecipes( VPRecipeBase *Sink = RecipeBuilder.getRecipe(Entry.first); VPRecipeBase *Target = RecipeBuilder.getRecipe(Entry.second); + auto GetReplicateRegion = [](VPRecipeBase *R) -> VPRegionBlock * { + auto *Region = + dyn_cast_or_null(R->getParent()->getParent()); + if (Region && Region->isReplicator()) + return Region; + return nullptr; + }; + // If the target is in a replication region, make sure to move Sink to the // block after it, not into the replication region itself. - if (auto *TargetRegion = - dyn_cast_or_null(Target->getParent()->getParent())) { - if (TargetRegion->isReplicator()) { - assert(TargetRegion->getNumSuccessors() == 1 && - "Expected SESE region!"); - VPBasicBlock *NextBlock = - cast(TargetRegion->getSuccessors().front()); - Sink->moveBefore(*NextBlock, NextBlock->getFirstNonPhi()); - continue; - } + if (auto *TargetRegion = GetReplicateRegion(Target)) { + assert(TargetRegion->getNumSuccessors() == 1 && "Expected SESE region!"); + assert(!GetReplicateRegion(Sink) && + "cannot sink a region into another region yet"); + VPBasicBlock *NextBlock = + cast(TargetRegion->getSuccessors().front()); + Sink->moveBefore(*NextBlock, NextBlock->getFirstNonPhi()); + continue; } - auto *SinkRegion = - dyn_cast_or_null(Sink->getParent()->getParent()); + auto *SinkRegion = GetReplicateRegion(Sink); // Unless the sink source is in a replicate region, sink the recipe // directly. - if (!SinkRegion || !SinkRegion->isReplicator()) { + if (!SinkRegion) { Sink->moveAfter(Target); continue; }