Skip to content

Commit 1c8845a

Browse files
committed
[Pipelines] 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 #92201
1 parent 35f7b60 commit 1c8845a

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,17 +1527,18 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
15271527
if (EnableIROutliner)
15281528
MPM.addPass(IROutlinerPass());
15291529

1530-
// Merge functions if requested.
1531-
if (PTO.MergeFunctions)
1532-
MPM.addPass(MergeFunctionsPass());
1533-
15341530
// Now we need to do some global optimization transforms.
15351531
// FIXME: It would seem like these should come first in the optimization
15361532
// pipeline and maybe be the bottom of the canonicalization pipeline? Weird
15371533
// ordering here.
15381534
MPM.addPass(GlobalDCEPass());
15391535
MPM.addPass(ConstantMergePass());
15401536

1537+
// Merge functions if requested. It has a better chance to merge functions
1538+
// after ConstantMerge folded jump tables.
1539+
if (PTO.MergeFunctions)
1540+
MPM.addPass(MergeFunctionsPass());
1541+
15411542
if (PTO.CallGraphProfile && !LTOPreLink)
15421543
MPM.addPass(CGProfilePass(LTOPhase == ThinOrFullLTOPhase::FullLTOPostLink ||
15431544
LTOPhase == ThinOrFullLTOPhase::ThinLTOPostLink));

llvm/test/Other/new-pm-defaults.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@
281281
; CHECK-HOT-COLD-SPLIT-NEXT: Running pass: HotColdSplittingPass
282282
; CHECK-IR-OUTLINER-NEXT: Running pass: IROutlinerPass
283283
; CHECK-IR-OUTLINER-NEXT: Running analysis: IRSimilarityAnalysis
284-
; CHECK-MERGE-FUNCS-NEXT: Running pass: MergeFunctionsPass
285284
; CHECK-O-NEXT: Running pass: GlobalDCEPass
286285
; CHECK-O-NEXT: Running pass: ConstantMergePass
286+
; CHECK-MERGE-FUNCS-NEXT: Running pass: MergeFunctionsPass
287287
; CHECK-DEFAULT-NEXT: Running pass: CGProfilePass
288288
; CHECK-DEFAULT-NEXT: Running pass: RelLookupTableConverterPass
289289
; CHECK-LTO-NOT: Running pass: RelLookupTableConverterPass

0 commit comments

Comments
 (0)