[llvm-branch-commits] [llvm] [LTO] Preserve module inline asm target properties for .lto_discard and symvers (PR #225130)
Alexander Richardson via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Sep 23 23:13:40 PDT 2026
https://github.com/arichardson updated https://github.com/llvm/llvm-project/pull/225130
>From 72bd3aefc1df1862ca83b2a6e1ce4bdc6aebd90a Mon Sep 17 00:00:00 2001
From: Alex Richardson <alexrichardson at google.com>
Date: Mon, 21 Sep 2026 23:42:19 -0700
Subject: [PATCH 1/2] [LTO] Preserve module inline asm target properties for
.lto_discard and symvers
Previously, LTO::addRegularLTO() and IRLinker::run() called
prependModuleInlineAsm() and appendModuleInlineAsm() with a plain string when
synthesizing `.lto_discard` and imported `.symver` directives, creating a new
GlobalAsmFragment with empty TargetCPU and TargetFeatures instead of preserving
the existing module inline asm's properties. Copy the front fragment's Props so
these synthesized directives are merged into the module's inline asm with the
same target features.
This commit was created with the help of AI tools
---
cross-project-tests/riscv/lto-inline-asm-abi.c | 7 ++-----
llvm/lib/LTO/LTO.cpp | 2 +-
llvm/lib/Linker/IRMover.cpp | 3 ++-
llvm/test/LTO/RISCV/module-asm.ll | 5 +----
4 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/cross-project-tests/riscv/lto-inline-asm-abi.c b/cross-project-tests/riscv/lto-inline-asm-abi.c
index e89e1e4f0687d..883244f1854f7 100644
--- a/cross-project-tests/riscv/lto-inline-asm-abi.c
+++ b/cross-project-tests/riscv/lto-inline-asm-abi.c
@@ -22,15 +22,12 @@
// RUN: llvm-objdump -d --show-all-symbols --no-show-raw-insn %t.thin.so | FileCheck %s --check-prefix=DISASM
// RUN: llvm-objdump -t %t.thin.so | FileCheck %s --check-prefix=SYMS --implicit-check-not='\$x'
//
-/// TODO: LTO::addRegularLTO and IRLinker::run drop target_features and
-/// target_cpu when synthesizing .lto_discard and imported .symver directives.
-// REGULAR-IR: module asm{{$}}
+// REGULAR-IR: module asm(target_features: "+64bit,{{.*}}", target_cpu: "generic-rv64")
// REGULAR-IR-NEXT: ".lto_discard "
-// REGULAR-IR-NEXT: module asm(target_features: "+64bit,{{.*}}", target_cpu: "generic-rv64")
// REGULAR-IR-NEXT: "nop"
// REGULAR-IR-NEXT: ".symver symver_fn, symver_fn at VER_1.0"
//
-// THIN-IR: module asm{{$}}
+// THIN-IR: module asm(target_features: "+64bit,{{.*}}", target_cpu: "generic-rv64")
// THIN-IR-NEXT: ".symver symver_fn, symver_fn at VER_1.0"
//
// FLAGS: Flags [ (0x5)
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 4594c52fb5f6e..e307b7f1c16e8 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1129,7 +1129,7 @@ LTO::addRegularLTO(InputFile &Input, ArrayRef<SymbolResolution> InputRes,
NewIA += " " + llvm::join(NonPrevailingAsmSymbols, ", ");
}
NewIA += "\n";
- M.prependModuleInlineAsm(NewIA);
+ M.prependModuleInlineAsm({NewIA, M.getModuleInlineAsm().front().Props});
}
assert(MsymI == MsymE);
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index 3b72b412d0b2e..080ba6d542f71 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -1576,7 +1576,8 @@ Error IRLinker::run() {
S += Name;
S += ", ";
S += Alias;
- DstM.appendModuleInlineAsm(std::string(S));
+ DstM.appendModuleInlineAsm(
+ {std::string(S), SrcM->getModuleInlineAsm().front().Props});
}
});
}
diff --git a/llvm/test/LTO/RISCV/module-asm.ll b/llvm/test/LTO/RISCV/module-asm.ll
index e213ec14a2a58..f27943f5457ac 100644
--- a/llvm/test/LTO/RISCV/module-asm.ll
+++ b/llvm/test/LTO/RISCV/module-asm.ll
@@ -7,11 +7,8 @@
; NM: T func
-;; TODO: LTO::addRegularLTO prepends ".lto_discard" without preserving the
-;; existing module inline asm's TargetCPU and TargetFeatures.
-; IR: module asm
+; IR: module asm(target_features: "+d")
; IR-NEXT: ".lto_discard"
-; IR-NEXT: module asm(target_features: "+d")
; IR-NEXT: ".globl func"
; IR-NEXT: "func:"
; IR-NEXT: "fld f0, 0(sp)"
>From 4f63905fdf183df3aff135ad1e21d9dc8500986f Mon Sep 17 00:00:00 2001
From: Alex Richardson <alexrichardson at google.com>
Date: Tue, 22 Sep 2026 22:52:24 -0700
Subject: [PATCH 2/2] address feedback
---
llvm/lib/Linker/IRMover.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index 080ba6d542f71..d96c5d18a0ae3 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -1577,7 +1577,7 @@ Error IRLinker::run() {
S += ", ";
S += Alias;
DstM.appendModuleInlineAsm(
- {std::string(S), SrcM->getModuleInlineAsm().front().Props});
+ {std::string(S), SrcM->getModuleInlineAsm().back().Props});
}
});
}
More information about the llvm-branch-commits
mailing list