[llvm] ccb40b0 - [VPlan] Add insertOnEdge to VPBlockUtils (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 9 13:20:01 PST 2024
Author: Florian Hahn
Date: 2024-11-09T21:19:39Z
New Revision: ccb40b0b7a51a0619acc8a6b479b86ff28a19e5b
URL: https://github.com/llvm/llvm-project/commit/ccb40b0b7a51a0619acc8a6b479b86ff28a19e5b
DIFF: https://github.com/llvm/llvm-project/commit/ccb40b0b7a51a0619acc8a6b479b86ff28a19e5b.diff
LOG: [VPlan] Add insertOnEdge to VPBlockUtils (NFC).
Add a new helper to insert a new VPBlockBase on an edge between 2
blocks. Suggested in https://github.com/llvm/llvm-project/pull/114292
and also useful for some existing code.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 0770ff032aa6a0..abfe97b4ab55b6 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -4177,6 +4177,24 @@ class VPBlockUtils {
return cast<BlockTy>(&Block);
});
}
+
+ /// Inserts \p BlockPtr on the edge between \p From and \p To. That is, update
+ /// \p From's successor to \p To to point to \p BlockPtr and \p To's
+ /// predecessor from \p From to \p BlockPtr. \p From and \p To are added to \p
+ /// BlockPtr's predecessors and successors respectively. There must be a
+ /// single edge between \p From and \p To.
+ static void insertOnEdge(VPBlockBase *From, VPBlockBase *To,
+ VPBlockBase *BlockPtr) {
+ auto &Successors = From->getSuccessors();
+ auto &Predecessors = To->getPredecessors();
+ assert(count(Successors, To) == 1 && count(Predecessors, From) == 1 &&
+ "must have single between From and To");
+ unsigned SuccIdx = std::distance(Successors.begin(), find(Successors, To));
+ unsigned PredIx =
+ std::distance(Predecessors.begin(), find(Predecessors, From));
+ VPBlockUtils::connectBlocks(From, BlockPtr, -1, SuccIdx);
+ VPBlockUtils::connectBlocks(BlockPtr, To, PredIx, -1);
+ }
};
class VPInterleavedAccessInfo {
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 70163aacb19d9d..b9ab8a8fe60107 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -360,8 +360,7 @@ static void addReplicateRegions(VPlan &Plan) {
// Record predicated instructions for above packing optimizations.
VPBlockBase *Region = createReplicateRegion(RepR, Plan);
Region->setParent(CurrentBlock->getParent());
- VPBlockUtils::connectBlocks(CurrentBlock, Region, -1, 0);
- VPBlockUtils::connectBlocks(Region, SplitBlock, 0, -1);
+ VPBlockUtils::insertOnEdge(CurrentBlock, SplitBlock, Region);
}
}
More information about the llvm-commits
mailing list