[llvm] 337d765 - [LV] Assert if trying to sink replicate region into another region (NFC)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri May 7 13:27:33 PDT 2021


Author: Florian Hahn
Date: 2021-05-07T21:25:35+01:00
New Revision: 337d7652823f59f4613552cebdf81292bf8f393d

URL: https://github.com/llvm/llvm-project/commit/337d7652823f59f4613552cebdf81292bf8f393d
DIFF: https://github.com/llvm/llvm-project/commit/337d7652823f59f4613552cebdf81292bf8f393d.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Removed: 
    


################################################################################
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<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;
     }


        


More information about the llvm-commits mailing list