[llvm] [VPlan] Add initial CFG simplification, removing BranchOnCond true. (PR #106748)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 6 06:51:02 PDT 2024
================
@@ -1124,6 +1124,49 @@ void VPlanTransforms::truncateToMinimalBitwidths(
"some entries in MinBWs haven't been processed");
}
+/// Remove BranchOnCond recipes with constant conditions together with removing
+/// dead edges to their successors. Remove blocks that become dead (no remaining
+/// predecessors())
+static void simplifyCFG(VPlan &Plan) {
+ using namespace llvm::VPlanPatternMatch;
+ SmallVector<VPBasicBlock *> WorkList;
+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+ vp_depth_first_deep(Plan.getEntry()))) {
+ VPRecipeBase *Term = VPBB->getTerminator();
+ if (!Term || !match(Term, m_BranchOnCond(m_True())))
+ continue;
+ WorkList.push_back(VPBB);
+ }
+
+ SetVector<VPBasicBlock *> PossiblyDeadBlocks;
+ for (VPBasicBlock *VPBB : WorkList) {
+ VPRecipeBase *Term = VPBB->getTerminator();
+ VPBasicBlock *DeadSucc = cast<VPBasicBlock>(VPBB->getSuccessors()[1]);
+ VPBlockUtils::disconnectBlocks(VPBB, DeadSucc);
+ PossiblyDeadBlocks.insert(DeadSucc);
+ Term->eraseFromParent();
+ }
+ for (VPBasicBlock *VPBB : PossiblyDeadBlocks) {
+ if (VPBB->getNumPredecessors() != 0)
+ continue;
+ // The block doesn't have any predecessors, remove it.
+ //
+ // To do so, first remove all recipes in the block. At the moment, recipes
+ // with users outside the block must be live-outs. Those are removed.
+ SmallVector<PHINode *> DeadLiveOuts;
----------------
fhahn wrote:
Whole live-out handling has been removed as based on https://github.com/llvm/llvm-project/pull/110577
https://github.com/llvm/llvm-project/pull/106748
More information about the llvm-commits
mailing list