[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
Tue Sep 22 22:53:05 PDT 2026
https://github.com/arichardson updated https://github.com/llvm/llvm-project/pull/225130
>From 3975b852340525c0d7301e2c3ba8401166711e6e 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 e89e1e4f0687d3..883244f1854f73 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 4594c52fb5f6e1..e307b7f1c16e85 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 3b72b412d0b2e0..080ba6d542f71d 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 e213ec14a2a580..f27943f5457ac4 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 f9145941ab45bfac89fad55e3b57c5d103ff72b2 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 080ba6d542f71d..d96c5d18a0ae3d 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