[LV] Assert if trying to sink replicate region into another region (NFC)
authorFlorian Hahn <flo@fhahn.com>
Fri, 7 May 2021 20:05:58 +0000 (21:05 +0100)
committerFlorian Hahn <flo@fhahn.com>
Fri, 7 May 2021 20:25:35 +0000 (21:25 +0100)
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.

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

index 5b61734..9337224 100644 (file)
@@ -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<VPRegionBlock>(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<VPRegionBlock>(Target->getParent()->getParent())) {
-      if (TargetRegion->isReplicator()) {
-        assert(TargetRegion->getNumSuccessors() == 1 &&
-               "Expected SESE region!");
-        VPBasicBlock *NextBlock =
-            cast<VPBasicBlock>(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<VPBasicBlock>(TargetRegion->getSuccessors().front());
+      Sink->moveBefore(*NextBlock, NextBlock->getFirstNonPhi());
+      continue;
     }
 
-    auto *SinkRegion =
-        dyn_cast_or_null<VPRegionBlock>(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;
     }