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

I believe I fixed the immediate issues that were causing regressions
with this, and now this is leading to its own regressions in building
Pytorch apparently. This was explicitly marked as a hack, and this
should resolve an ongoing issue so we should revert this for now.

Should fix LCOMPILER-2396

This reverts commit eaff67c9838f98d221aa563c9e5d4e714d636674.


>From ed7b0464594311ab47d8b99e0fbc430623fe1911 Mon Sep 17 00:00:00 2001
From: Joseph Huber <[email protected]>
Date: Wed, 1 Jul 2026 06:57:30 -0500
Subject: [PATCH] Revert "[HIP][AMDGPU] Use non-LTO pipeline for non-RDC in the
 linker wrapper (#201135)"

I believe I fixed the immediate issues that were causing regressions
with this, and now this is leading to its own regressions in building
Pytorch apparently. This was explicitly marked as a hack, and this
should resolve an ongoing issue so we should revert this for now.

Should fix LCOMPILER-2396

This reverts commit eaff67c9838f98d221aa563c9e5d4e714d636674.
---
 clang/lib/Driver/ToolChains/Clang.cpp           | 13 -------------
 clang/test/Driver/hip-toolchain-no-rdc.hip      | 17 -----------------
 .../linker-wrapper-hip-no-rdc.c                 | 12 ------------
 .../clang-linker-wrapper/ClangLinkerWrapper.cpp | 13 -------------
 .../clang-linker-wrapper/LinkerWrapperOpts.td   |  3 ---
 5 files changed, 58 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index bb3fbc3c585a6..475dcfcb4126c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9786,19 +9786,6 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
           }
         }
       }
-
-      if (JA.getType() == types::TY_HIP_FATBIN && Kind == Action::OFK_HIP) {
-        // Non-RDC HIP uses the conventional non-LTO pipeline unless the user
-        // opts into offload LTO.
-        bool UsesProfileGenerate = Args.hasArg(
-            options::OPT_fprofile_generate, options::OPT_fprofile_generate_EQ,
-            options::OPT_fprofile_instr_generate,
-            options::OPT_fprofile_instr_generate_EQ);
-        if (!Args.hasArg(options::OPT_foffload_lto_EQ,
-                         options::OPT_fno_offload_lto) &&
-            !UsesProfileGenerate && !TC->getTriple().isSPIRV())
-          CmdArgs.push_back("--no-lto");
-      }
     }
   }
 
diff --git a/clang/test/Driver/hip-toolchain-no-rdc.hip 
b/clang/test/Driver/hip-toolchain-no-rdc.hip
index 6f148ce01ff30..465722121fc67 100644
--- a/clang/test/Driver/hip-toolchain-no-rdc.hip
+++ b/clang/test/Driver/hip-toolchain-no-rdc.hip
@@ -46,21 +46,6 @@
 // RUN:   %s -nogpuinc -nogpulib \
 // RUN: 2>&1 | FileCheck -check-prefixes=AMDGCNSPIRV-NEW %s
 
-// SPIR-V requires the LTO pipeline; --no-lto must not be passed.
-// RUN: %clang -### --target=x86_64-linux-gnu -fno-gpu-rdc \
-// RUN:   --offload-arch=amdgcnspirv -nogpuinc -nogpulib \
-// RUN:   %s 2>&1 | FileCheck -check-prefixes=SPIRV-NO-LTO %s
-// SPIRV-NO-LTO: {{".*clang-linker-wrapper}}
-// SPIRV-NO-LTO-NOT: "--no-lto"
-// SPIRV-NO-LTO-SAME: "--emit-fatbin-only"
-
-// Profile generation needs LTO, so the linker wrapper must not get --no-lto.
-// RUN: %clang -### --target=x86_64-linux-gnu -fno-gpu-rdc -fprofile-generate \
-// RUN:   -x hip --cuda-gpu-arch=gfx900 -nogpuinc -nogpulib 
--offload-new-driver \
-// RUN:   %s 2>&1 | FileCheck -check-prefixes=PGO 
-implicit-check-not="--no-lto" %s
-// PGO: {{".*clang-linker-wrapper}}
-// PGO-SAME: "--emit-fatbin-only"
-
 //
 // Compile device code in a.cu to code object for gfx803.
 //
@@ -123,7 +108,6 @@
 
 // NEW: [[WRAPPER:".*clang-linker-wrapper]]"
 // NEW-SAME: "--device-compiler=amdgcn-amd-amdhsa=-flto=full"
-// NEW-SAME: "--no-lto"
 // NEW-SAME: "--host-triple=x86_64-unknown-linux-gnu"
 // NEW-SAME: "--emit-fatbin-only"
 // NEW-SAME: "-o" "[[HIPFB_A:.*.hipfb]]" "[[PACKAGE_A]]"
@@ -198,7 +182,6 @@
 
 // NEW: [[WRAPPER:".*clang-linker-wrapper]]"
 // NEW-SAME: "--device-compiler=amdgcn-amd-amdhsa=-flto=full"
-// NEW-SAME: "--no-lto"
 // NEW-SAME: "--emit-fatbin-only"
 // NEW-SAME: "-o" "[[HIPFB_B:.*.hipfb]]" "[[PACKAGE_B]]"
 
diff --git 
a/clang/test/OffloadTools/clang-linker-wrapper/linker-wrapper-hip-no-rdc.c 
b/clang/test/OffloadTools/clang-linker-wrapper/linker-wrapper-hip-no-rdc.c
index 80ac493825aad..aae330bd3f6de 100644
--- a/clang/test/OffloadTools/clang-linker-wrapper/linker-wrapper-hip-no-rdc.c
+++ b/clang/test/OffloadTools/clang-linker-wrapper/linker-wrapper-hip-no-rdc.c
@@ -55,15 +55,3 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: test -s %t.gfx9-4-generic-xnack+.co
 // RUN: test -f %t.gfx1200.co
 // RUN: test -s %t.gfx1200.co
-
-// Without --no-lto the AMDGPU device compilation uses the LTO pipeline
-// (-flto).
-// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu 
--wrapper-verbose --dry-run --emit-fatbin-only --linker-path=/usr/bin/ld %t.out 
-o %t.lto.hipfb 2>&1 | FileCheck %s --check-prefix=LTO
-// LTO: clang{{.*}} -mcpu=gfx1200
-
-// With --no-lto the AMDGPU device compilation uses the conventional non-LTO
-// pipeline: -flto must not be passed, and '-x ir' must be passed so Clang
-// compiles the bitcode (stored in an object-extension file) instead of
-// handing it to the LTO link.
-// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu 
--wrapper-verbose --dry-run --no-lto --emit-fatbin-only 
--linker-path=/usr/bin/ld %t.out -o %t.nolto.hipfb 2>&1 | FileCheck %s 
--check-prefix=NO-LTO
-// NO-LTO: clang{{.*}} -mcpu=gfx1200{{.*}} -x ir {{.*}}-flto=none
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index a4a67eed7d47f..76be0f776e561 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -543,16 +543,6 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, 
const ArgList &Args,
   if (!Triple.isNVPTX() && !Triple.isSPIRV())
     CmdArgs.push_back("-Wl,--no-undefined");
 
-  // The device inputs are bitcode stored in files with an object extension.
-  // Force the IR input language so Clang runs the compile and backend phases
-  // instead of treating them as linker inputs, which would defer codegen to
-  // the LTO link and defeat the non-LTO pipeline.
-  // FIXME: This is a stop-gap for non-RDC. Longer term, RDC and non-RDC should
-  //        share a unified interface.
-  // SPIR-V has no non-LTO pipeline so a --no-lto leaked from a concrete arch 
in
-  // a multi-target compile is ignored. Which is a workaround to remove.
-  if (Args.hasArg(OPT_no_lto) && !Triple.isSPIRV())
-    CmdArgs.append({"-x", "ir"});
   for (StringRef InputFile : InputFiles)
     CmdArgs.push_back(InputFile);
 
@@ -615,9 +605,6 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, 
const ArgList &Args,
   for (StringRef Arg : Args.getAllArgValues(OPT_compiler_arg_EQ))
     CmdArgs.push_back(Args.MakeArgString(Arg));
 
-  if (Args.hasArg(OPT_no_lto) && !Triple.isSPIRV())
-    CmdArgs.append({"-flto=none", "-Wno-unused-command-line-argument"});
-
   if (Error Err = executeCommands(*ClangPath, CmdArgs))
     return std::move(Err);
 
diff --git a/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td 
b/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
index 87a26ca90a66f..53b6c596de291 100644
--- a/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
+++ b/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
@@ -39,9 +39,6 @@ def print_wrapped_module : Flag<["--"], 
"print-wrapped-module">,
   HelpText<"Print the wrapped module's IR for testing">;
 def save_temps : Flag<["--"], "save-temps">,
   Flags<[WrapperOnlyOption]>, HelpText<"Save intermediate results">;
-def no_lto : Flag<["--"], "no-lto">,
-             Flags<[WrapperOnlyOption]>,
-             HelpText<"Use the non-LTO device compilation pipeline">;
 def compress : Flag<["--"], "compress">,
   Flags<[WrapperOnlyOption]>, HelpText<"Compress bundled files">;
 def compression_level_eq : Joined<["--"], "compression-level=">,

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

Reply via email to