https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/211215
Backport c012610ab9924f465baea5e62397056ea9594567 49d568a8d60d5912a5a7d8b2c3ac1caf58dab3e6 Requested by: @bd1976bris >From 6183a4e71a1f2e03d8c56db91ef333ea0d8ad8c0 Mon Sep 17 00:00:00 2001 From: Ben Dunbobbin <[email protected]> Date: Thu, 16 Jul 2026 09:56:40 +0100 Subject: [PATCH 1/2] [DTLTO] Add remote compiler option forwarding coverage (#208589) Add a cross-project DTLTO test that checks the existing LTO configuration state serialized into the remote Clang command line. The test uses the validate.py distributor to inspect the generated DTLTO JSON. Cover all the existing forwarded options. Add paired negative checks for optional flags so the test also verifies they are not emitted when the corresponding configuration state is not set. (cherry picked from commit c012610ab9924f465baea5e62397056ea9594567) --- cross-project-tests/CMakeLists.txt | 1 + cross-project-tests/dtlto/remote-options.test | 90 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 cross-project-tests/dtlto/remote-options.test diff --git a/cross-project-tests/CMakeLists.txt b/cross-project-tests/CMakeLists.txt index 4dab5d3d51fd6..85102065e79e6 100644 --- a/cross-project-tests/CMakeLists.txt +++ b/cross-project-tests/CMakeLists.txt @@ -26,6 +26,7 @@ set(CROSS_PROJECT_TEST_DEPS llvm-config llvm-dis llvm-dwarfdump + llvm-lto2 llvm-modextract llvm-objdump not diff --git a/cross-project-tests/dtlto/remote-options.test b/cross-project-tests/dtlto/remote-options.test new file mode 100644 index 0000000000000..e808adf9cf9e1 --- /dev/null +++ b/cross-project-tests/dtlto/remote-options.test @@ -0,0 +1,90 @@ +REQUIRES: ld.lld + +## Check that DTLTO passes LTO configuration to the remote Clang via the +## command line. + +RUN: rm -rf %t && split-file %s %t && cd %t + +RUN: %clang --target=x86_64-unknown-linux-gnu -flto=thin -c test.c -o elf.o +RUN: %clang --target=x86_64-pc-windows-msvc -flto=thin -c test.c -o coff.o +RUN: touch profile.prof + +## The validate.py distributor prints the DTLTO JSON and then exits without +## producing native objects, so each llvm-lto2 command is expected to fail after +## the JSON has been emitted. +DEFINE: %{base} = not llvm-lto2 run \ +DEFINE: -dtlto-distributor=%python \ +DEFINE: -dtlto-distributor-arg=%llvm_src_root/utils/dtlto/validate.py \ +DEFINE: -dtlto-compiler=%clang \ +DEFINE: -o test.out + +DEFINE: %{lld} = not ld.lld elf.o \ +DEFINE: --thinlto-distributor=%python \ +DEFINE: --thinlto-distributor-arg=%llvm_src_root/utils/dtlto/validate.py \ +DEFINE: --thinlto-remote-compiler=%clang \ +DEFINE: -o test.elf + +DEFINE: %{lto2-elf} = %{base} elf.o -r=elf.o,foo,px +DEFINE: %{lto2-coff} = %{base} coff.o -r=coff.o,foo,px + +ARGS: "args": [ + +## Optimization level. +RUN: %{lto2-elf} -O0 2>&1 | FileCheck %s --check-prefixes=ARGS,O0,ERR +RUN: %{lto2-elf} -O3 2>&1 | FileCheck %s --check-prefixes=ARGS,O3,ERR +O0: "-O0" +O3: "-O3" + +## Address-significance table, function sections, and data sections. +RUN: %{lto2-elf} -addrsig -function-sections -data-sections 2>&1 | \ +RUN: FileCheck %s --check-prefixes=ARGS,SECTIONS,ERR +SECTIONS: "-faddrsig" +SECTIONS: "-ffunction-sections" +SECTIONS: "-fdata-sections" + +RUN: %{lto2-elf} 2>&1 | FileCheck %s --check-prefixes=ARGS,NO-SECTIONS,ERR +NO-SECTIONS-NOT: "-faddrsig" +NO-SECTIONS-NOT: "-ffunction-sections" +NO-SECTIONS-NOT: "-fdata-sections" + +## PIC is forwarded as -fpic for ELF targets but not for COFF targets because +## Clang does not accept -fpic for every target. +RUN: %{lto2-elf} -relocation-model=pic 2>&1 | \ +RUN: FileCheck %s --check-prefixes=ARGS,PIC,ERR +PIC: "-fpic" + +RUN: %{lto2-elf} -relocation-model=static 2>&1 | \ +RUN: FileCheck %s --check-prefixes=ARGS,NO-PIC,ERR +NO-PIC-NOT: "-fpic" + +RUN: %{lto2-coff} -relocation-model=pic 2>&1 | \ +RUN: FileCheck %s --check-prefixes=COFF-PIC,ERR +COFF-PIC-NOT: "-fpic" + +## Sample profile forwarding and common-input serialization. +RUN: %{lto2-elf} -lto-sample-profile-file=profile.prof 2>&1 | \ +RUN: FileCheck %s --check-prefixes=ARGS,SAMPLE,ERR +SAMPLE: "-fprofile-sample-use=profile.prof" +SAMPLE: "inputs": [ +SAMPLE: "profile.prof" + +RUN: %{lto2-elf} 2>&1 | FileCheck %s --check-prefixes=ARGS,NO-SAMPLE,ERR +NO-SAMPLE-NOT: "-fprofile-sample-use=profile.prof" +NO-SAMPLE-NOT: "profile.prof" + +## PGO warning mismatch control is an LLD-driver option rather than an +## llvm-lto2 option, so check it through the ELF linker. +RUN: %{lld} --no-lto-pgo-warn-mismatch 2>&1 | \ +RUN: FileCheck %s --check-prefixes=ARGS,PGO-WARN,ERR +PGO-WARN: "-mllvm" +PGO-WARN-NEXT: "-no-pgo-warn-mismatch" + +RUN: %{lld} 2>&1 | \ +RUN: FileCheck %s --check-prefixes=ARGS,NO-PGO-WARN,ERR +NO-PGO-WARN-NOT: "-no-pgo-warn-mismatch" + +## Check for the expected error from the use of validate.py. +ERR: DTLTO backend compilation: cannot open native object file: + +#--- test.c +void foo(void) {} >From 0c02d581ca4ff486e9916473bd3d275df8eefc95 Mon Sep 17 00:00:00 2001 From: Ben Dunbobbin <[email protected]> Date: Tue, 21 Jul 2026 19:27:15 +0100 Subject: [PATCH 2/2] [DTLTO] Forward loop interchange to DTLTO remote compilations (#208591) Recent upstream LLVM changes enabled `LoopInterchangePass` by default through `PipelineTuningOptions`. TLTO observes that state directly from the LTO config, but DTLTO was not forwarding the equivalent Clang option to the remote compiler. As a result, TLTO could run loop interchange pass while DTLTO did not, producing codegen differences for configurations that exposed profitable/legally interchangeable loops. Note that this was a pre-existing issue, the change in default has simply exposed it. Forward `C.PTO.LoopInterchange` as `-floop-interchange` when constructing the common DTLTO remote compiler options. Extend the testing to check that the SN-DBS remote command line includes the forwarded option. The code for forwarding such options is only intended as a temporary measure. A more comprehensive solution is in discussion here: https://discourse.llvm.org/t/synchronizing-lto-code-generation-configuration-between-clang-and-lld-dtlto (cherry picked from commit 49d568a8d60d5912a5a7d8b2c3ac1caf58dab3e6) --- cross-project-tests/dtlto/remote-options.test | 9 +++++++++ llvm/lib/DTLTO/DTLTO.cpp | 2 ++ llvm/test/ThinLTO/X86/dtlto/json.ll | 1 + 3 files changed, 12 insertions(+) diff --git a/cross-project-tests/dtlto/remote-options.test b/cross-project-tests/dtlto/remote-options.test index e808adf9cf9e1..ddc9883199c49 100644 --- a/cross-project-tests/dtlto/remote-options.test +++ b/cross-project-tests/dtlto/remote-options.test @@ -47,6 +47,15 @@ NO-SECTIONS-NOT: "-faddrsig" NO-SECTIONS-NOT: "-ffunction-sections" NO-SECTIONS-NOT: "-fdata-sections" +## Loop interchange. +RUN: %{lto2-elf} -enable-loopinterchange=true 2>&1 | \ +RUN: FileCheck %s --check-prefixes=ARGS,LOOP-INTERCHANGE,ERR +LOOP-INTERCHANGE: "-floop-interchange" + +RUN: %{lto2-elf} -enable-loopinterchange=false 2>&1 | \ +RUN: FileCheck %s --check-prefixes=ARGS,NO-LOOP-INTERCHANGE,ERR +NO-LOOP-INTERCHANGE-NOT: "-floop-interchange" + ## PIC is forwarded as -fpic for ELF targets but not for COFF targets because ## Clang does not accept -fpic for every target. RUN: %{lto2-elf} -relocation-model=pic 2>&1 | \ diff --git a/llvm/lib/DTLTO/DTLTO.cpp b/llvm/lib/DTLTO/DTLTO.cpp index bca05fa53e889..c12a621b9815e 100644 --- a/llvm/lib/DTLTO/DTLTO.cpp +++ b/llvm/lib/DTLTO/DTLTO.cpp @@ -195,6 +195,8 @@ void lto::DTLTO::buildCommonRemoteCompilerOptions() { Ops.push_back("-ffunction-sections"); if (C.Options.DataSections) Ops.push_back("-fdata-sections"); + if (C.PTO.LoopInterchange) + Ops.push_back("-floop-interchange"); if (C.RelocModel == Reloc::PIC_) // Clang doesn't have -fpic for all triples. diff --git a/llvm/test/ThinLTO/X86/dtlto/json.ll b/llvm/test/ThinLTO/X86/dtlto/json.ll index ee1c428c31c7c..e705e97bd8858 100644 --- a/llvm/test/ThinLTO/X86/dtlto/json.ll +++ b/llvm/test/ThinLTO/X86/dtlto/json.ll @@ -37,6 +37,7 @@ LLVM-NEXT: "clang" CHECK-NEXT: "-c" CHECK-NEXT: "--target=x86_64-unknown-linux-gnu" CHECK-NEXT: "-O2" +CHECK-NEXT: "-floop-interchange" CHECK-NEXT: "-fpic" CHECK-NEXT: "-Wno-unused-command-line-argument" CHECK-NEXT: "--rota1=10" _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
