Skip to content

Commit 6185246

Browse files
committed
[OpenMP] Run an extra 'OpenMPOpt' pass in LTO-mode
The `OpenMPOpt` pass is pivotal to the performance of many OpenMP offloading programs. When we perform non-LTO builds with OpenMP we used to link the OpenMP deviceRTL individually for each TU. This lead to us getting an additional attributor run on the combined runtime and user code. When we used LTO we lost a run and suffered a large performance degradation. This patch simply adds in the extra `OpenMPOpt` pass that we miss into the LTO pipeline. This patch fixes the performance regression shown in applications that used OpenMP offloading in LTO mode. Previously, this wasn't legal to do as we could emit new runtime calls into the module. That was fixed by D142646. Depends on D142646 Fixes #60300 Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D142650
1 parent 0bdde9d commit 6185246

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,6 @@ std::unique_ptr<lto::LTO> createLTO(
513513
assert(CGOptLevelOrNone && "Invalid optimization level");
514514
Conf.CGOptLevel = *CGOptLevelOrNone;
515515
Conf.OptLevel = OptLevel[1] - '0';
516-
if (Conf.OptLevel > 0)
517-
Conf.UseDefaultPipeline = true;
518516
Conf.DefaultTriple = Triple.getTriple();
519517

520518
LTOError = false;

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,9 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
17121712
// Optimize globals again after we ran the inliner.
17131713
MPM.addPass(GlobalOptPass());
17141714

1715+
// Run the OpenMPOpt pass again after global optimizations.
1716+
MPM.addPass(OpenMPOptPass(ThinOrFullLTOPhase::FullLTOPostLink));
1717+
17151718
// Garbage collect dead functions.
17161719
MPM.addPass(GlobalDCEPass());
17171720

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
; CHECK-O23SZ-NEXT: Running pass: InlinerPass
7979
; CHECK-O23SZ-NEXT: Invalidating analysis: InlineAdvisorAnalysis
8080
; CHECK-O23SZ-NEXT: Running pass: GlobalOptPass
81+
; CHECK-O23SZ-NEXT: Running pass: OpenMPOptPass
8182
; CHECK-O23SZ-NEXT: Running pass: GlobalDCEPass
8283
; CHECK-O23SZ-NEXT: Running pass: ArgumentPromotionPass
8384
; CHECK-O23SZ-NEXT: Running pass: DeadArgumentEliminationPass

0 commit comments

Comments
 (0)