[llvm] Perform mergefunc after constmerge (PR #92498)
YAMAMOTO Takashi via llvm-commits
llvm-commits at lists.llvm.org
Thu May 16 22:44:14 PDT 2024
https://github.com/yamt created https://github.com/llvm/llvm-project/pull/92498
Constmerge can fold switch jump tables, possibly making functions identical again. It can help mergefunc.
On the otherhand, the opposite seems unlikely.
Fixes https://github.com/llvm/llvm-project/issues/92201
>From ebc89c7f173c05c5c3a6e0f88b6854b984ad4a46 Mon Sep 17 00:00:00 2001
From: YAMAMOTO Takashi <yamamoto at midokura.com>
Date: Fri, 17 May 2024 14:31:17 +0900
Subject: [PATCH] Perform mergefunc after constmerge
Constmerge can fold switch jump tables, possibly making functions
identical again. It can help mergefunc.
On the otherhand, the opposite seems unlikely.
Fixes https://github.com/llvm/llvm-project/issues/92201
---
llvm/lib/Passes/PassBuilderPipelines.cpp | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 1892e16a06528..bc7be57284ad8 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1525,10 +1525,6 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
if (EnableIROutliner)
MPM.addPass(IROutlinerPass());
- // Merge functions if requested.
- if (PTO.MergeFunctions)
- MPM.addPass(MergeFunctionsPass());
-
// Now we need to do some global optimization transforms.
// FIXME: It would seem like these should come first in the optimization
// pipeline and maybe be the bottom of the canonicalization pipeline? Weird
@@ -1536,6 +1532,11 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
MPM.addPass(GlobalDCEPass());
MPM.addPass(ConstantMergePass());
+ // Merge functions if requested. It has a better chance to merge functions
+ // after ConstantMerge folded jump tables.
+ if (PTO.MergeFunctions)
+ MPM.addPass(MergeFunctionsPass());
+
if (PTO.CallGraphProfile && !LTOPreLink)
MPM.addPass(CGProfilePass(LTOPhase == ThinOrFullLTOPhase::FullLTOPostLink ||
LTOPhase == ThinOrFullLTOPhase::ThinLTOPostLink));
More information about the llvm-commits
mailing list