[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
This commit is contained in:
Ben Dunbobbin 2026-07-21 19:27:15 +01:00 committed by GitHub
parent 0aa8e45b04
commit 49d568a8d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 0 deletions

View file

@ -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 | \

View file

@ -227,6 +227,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.

View file

@ -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"