[PATCH] D142650: [OpenMP] Run an extra 'OpenMPOpt' pass in LTO-mode

Joseph Huber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 26 09:31:49 PST 2023


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992, JonChesterfield, ronlieb, ye-luo, fhahn.
Herald added subscribers: StephenFan, guansong, hiraditya, inglorion, yaxunl.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added a reviewer: sstefan1.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

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 <https://reviews.llvm.org/D142646>.

Depends on D142646 <https://reviews.llvm.org/D142646>

Fixes https://github.com/llvm/llvm-project/issues/60300


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142650

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  llvm/lib/Passes/PassBuilderPipelines.cpp


Index: llvm/lib/Passes/PassBuilderPipelines.cpp
===================================================================
--- llvm/lib/Passes/PassBuilderPipelines.cpp
+++ llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1715,6 +1715,9 @@
   // Garbage collect dead functions.
   MPM.addPass(GlobalDCEPass());
 
+  // Run the OpenMPOpt pass again after global optimizations.
+  MPM.addPass(OpenMPOptPass(ThinOrFullLTOPhase::FullLTOPostLink));
+
   // If we didn't decide to inline a function, check to see if we can
   // transform it to pass arguments by value instead of by reference.
   MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(ArgumentPromotionPass()));
Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===================================================================
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -513,8 +513,6 @@
   assert(CGOptLevelOrNone && "Invalid optimization level");
   Conf.CGOptLevel = *CGOptLevelOrNone;
   Conf.OptLevel = OptLevel[1] - '0';
-  if (Conf.OptLevel > 0)
-    Conf.UseDefaultPipeline = true;
   Conf.DefaultTriple = Triple.getTriple();
 
   LTOError = false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142650.492490.patch
Type: text/x-patch
Size: 1198 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230126/54679834/attachment-0001.bin>


More information about the cfe-commits mailing list