[llvm] [BranchFolding] Add an option to tail merge only bbs without successors (PR #101969)

Vladimir Radosavljevic via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 5 05:55:47 PDT 2024


https://github.com/vladimirradosavljevic created https://github.com/llvm/llvm-project/pull/101969

This patch adds -tail-merge-only-bbs-without-succ option to BranchFolding pass. The only difference between this option and -enable-tail-merge is that this option can reduce code size in case function has multiple return points that can be merged.

>From 5f78332e416c099bd797de68696cb1ff30b0f733 Mon Sep 17 00:00:00 2001
From: Vladimir Radosavljevic <vr at matterlabs.dev>
Date: Mon, 5 Aug 2024 14:26:37 +0200
Subject: [PATCH] [BranchFolding] Add an option to tail merge only bbs without
 successors

This patch adds -tail-merge-only-bbs-without-succ option to
BranchFolding pass. The only difference between this option
and -enable-tail-merge is that this option can reduce code
size in case function has multiple return points that can be
merged.
---
 llvm/lib/CodeGen/BranchFolding.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp
index 1dc278586f117..41c947c988077 100644
--- a/llvm/lib/CodeGen/BranchFolding.cpp
+++ b/llvm/lib/CodeGen/BranchFolding.cpp
@@ -85,6 +85,11 @@ TailMergeSize("tail-merge-size",
               cl::desc("Min number of instructions to consider tail merging"),
               cl::init(3), cl::Hidden);
 
+static cl::opt<bool> TailMergeOnlyBBsWithoutSucc(
+    "tail-merge-only-bbs-without-succ",
+    cl::desc("Tail merge only basic blocks without successors"),
+    cl::init(false), cl::Hidden);
+
 namespace {
 
   /// BranchFolderPass - Wrap branch folder in a machine function pass.
@@ -1035,6 +1040,9 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) {
   if (MergePotentials.size() >= 2)
     MadeChange |= TryTailMergeBlocks(nullptr, nullptr, MinCommonTailLength);
 
+  if (TailMergeOnlyBBsWithoutSucc)
+    return MadeChange;
+
   // Look at blocks (IBB) with multiple predecessors (PBB).
   // We change each predecessor to a canonical form, by
   // (1) temporarily removing any unconditional branch from the predecessor



More information about the llvm-commits mailing list