https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/211790

Summary:
The change to the new driver used LTO. Clang defaults to O0 while LTO
defaults to lto<O2>. The reason for this is because most people do not
pass optimizations to the linker step and when linking libraries we will
have some that need optimizations and some that don't. In RDC-mode, we
only have a single <logical> TU, so we suppress optimizations.

Fixes: https://github.com/ROCm/ROCgdb/pull/231


>From 52ed14ecce2cbc265f5c67189ef5cd2bb7d5f144 Mon Sep 17 00:00:00 2001
From: Joseph Huber <[email protected]>
Date: Fri, 24 Jul 2026 08:32:41 -0500
Subject: [PATCH] [HIP] Pass `-O0` by default for HIP no-RDC compilations

Summary:
The change to the new driver used LTO. Clang defaults to O0 while LTO
defaults to lto<O2>. The reason for this is because most people do not
pass optimizations to the linker step and when linking libraries we will
have some that need optimizations and some that don't. In RDC-mode, we
only have a single <logical> TU, so we suppress optimizations.

Fixes: https://github.com/ROCm/ROCgdb/pull/231
---
 clang/lib/Driver/ToolChains/Clang.cpp   | 6 ++++++
 clang/test/Driver/hip-toolchain-opt.hip | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1178f625d1172..c40d2f2949943 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9892,6 +9892,12 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
         }
       }
 
+      // If no optimization level was requested we default to `-O0` for no-RDC
+      // mode compilations. Others default to `lto<O2>` as standard in ld.lld.
+      if (JA.getType() == types::TY_HIP_FATBIN &&
+          !ToolChainArgs.getLastArg(OPT_O_Group))
+        CompilerArgs.emplace_back("-O0");
+
       // If the user explicitly requested it via `--offload-arch` we should
       // extract it from any static libraries if present.
       for (StringRef Arg : ToolChainArgs.getAllArgValues(OPT_offload_arch_EQ))
diff --git a/clang/test/Driver/hip-toolchain-opt.hip 
b/clang/test/Driver/hip-toolchain-opt.hip
index 22edf4107004e..57e9d79afd324 100644
--- a/clang/test/Driver/hip-toolchain-opt.hip
+++ b/clang/test/Driver/hip-toolchain-opt.hip
@@ -75,7 +75,7 @@
 // O0-CGO2-NOT: "--lto-CGO2"
 
 // ALL: "{{.*}}clang-linker-wrapper{{.*}}" "--should-extract=gfx900"
-// DEFAULT-NOT: "--device-compiler=amdgcn-amd-amdhsa=-O{{.*}}"
+// DEFAULT: "--device-compiler=amdgcn-amd-amdhsa=-O0"
 // O0-SAME: "--device-compiler=amdgcn-amd-amdhsa=-O0"
 // O1-SAME: "--device-compiler=amdgcn-amd-amdhsa=-O1"
 // O2-SAME: "--device-compiler=amdgcn-amd-amdhsa=-O2"
@@ -86,7 +86,7 @@
 // O0-CGO2-SAME: "--device-compiler=amdgcn-amd-amdhsa=-O0"
 
 // ALL: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
-// DEFAULT-NOT: "-O{{.}}"
+// DEFAULT: "-O0"
 // O0-SAME: "-O0"
 // O1-SAME: "-O1"
 // O2-SAME: "-O2"

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to