[llvm] [VPlan] Hook IR blocks into VPlan during skeleton creation (NFC) (PR #114292)

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 4 13:26:24 PST 2024


================
@@ -2426,6 +2426,26 @@ InnerLoopVectorizer::getOrCreateVectorTripCount(BasicBlock *InsertBlock) {
   return VectorTripCount;
 }
 
+static void connectScalarPreheaderInVPlan(VPlan &Plan) {
+  VPBlockBase *VectorPH = Plan.getVectorPreheader();
+  VPBlockBase *ScalarPH = Plan.getScalarPreheader();
+  VPBlockBase *PredVPB = VectorPH->getSinglePredecessor();
+  VPBlockUtils::disconnectBlocks(Plan.getEntry(), VectorPH);
+  VPBlockUtils::connectBlocks(PredVPB, ScalarPH);
----------------
ayalz wrote:

A simple 
```suggestion
  VPBlockUtils::connectBlocks(Plan.getEntry(), Plan.getScalarPreHeader());
```
alone does not suffice, because the scalar preheader should be the first successor, followed by the existing vector preheader.

Worth noting that we're disconnecting and reconnecting in order to set the right successor order.

Perhaps worth adding to `connectBlocks()` an option to indicate successor index (if not last)? And/or predecessor index(?) This would allow swapping entries or sorting vectors in place instead of insert sorting. This may be more general and efficient than `connectScalarPreheaderInVPlan()`?

https://github.com/llvm/llvm-project/pull/114292


More information about the llvm-commits mailing list