From 49d568a8d60d5912a5a7d8b2c3ac1caf58dab3e6 Mon Sep 17 00:00:00 2001 From: Ben Dunbobbin Date: Tue, 21 Jul 2026 19:27:15 +0100 Subject: [PATCH] [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 --- 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 e808adf9cf9e..ddc9883199c4 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 1d42d09d0820..6946abe47077 100644 --- a/llvm/lib/DTLTO/DTLTO.cpp +++ b/llvm/lib/DTLTO/DTLTO.cpp @@ -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. diff --git a/llvm/test/ThinLTO/X86/dtlto/json.ll b/llvm/test/ThinLTO/X86/dtlto/json.ll index ee1c428c31c7..e705e97bd885 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"