Skip to content

Conversation

@usha1830
Copy link
Contributor

@usha1830 usha1830 commented Dec 4, 2025

Commit #167996 moved VecLib into TargetOptions and ensured clang properly sets it. However, some LTO backend code paths were still creating TargetLibraryInfoImpl without passing the VecLib parameter from TargetMachine::Options.

This PR completes the fix by ensuring that:

LTOBackend.cpp, ThinLTOCodeGenerator.cpp, UpdateCompilerUsed.cpp all pass TM->Options.VecLib when constructing TargetLibraryInfoImpl.

Without this fix, vector library information (e.g., -fveclib=ArmPL) would not be properly recognized during LTO optimization and code generation, potentially causing incorrect optimizations or linker errors when vector library functions are referenced.

@usha1830 usha1830 marked this pull request as ready for review December 5, 2025 19:03
@llvmbot llvmbot added the LTO Link time optimization (regular/full LTO or ThinLTO) label Dec 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 5, 2025

@llvm/pr-subscribers-lto

Author: Usha Gupta (usha1830)

Changes

Commit #167996 moved VecLib into TargetOptions and ensured clang properly sets it. However, some LTO backend code paths were still creating TargetLibraryInfoImpl without passing the VecLib parameter from TargetMachine::Options.

This PR completes the fix by ensuring that:

LTOBackend.cpp, ThinLTOCodeGenerator.cpp, UpdateCompilerUsed.cpp all pass TM->Options.VecLib when constructing TargetLibraryInfoImpl.

Without this fix, vector library information (e.g., -fveclib=ArmPL) would not be properly recognized during LTO optimization and code generation, potentially causing incorrect optimizations or linker errors when vector library functions are referenced.


Full diff: https://github.com/llvm/llvm-project/pull/170638.diff

3 Files Affected:

  • (modified) llvm/lib/LTO/LTOBackend.cpp (+2-2)
  • (modified) llvm/lib/LTO/ThinLTOCodeGenerator.cpp (+1-1)
  • (modified) llvm/lib/LTO/UpdateCompilerUsed.cpp (+1-1)
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 93118becedbac..705bdbae4acf7 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -278,7 +278,7 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
   RegisterPassPlugins(Conf.PassPlugins, PB);
 
   std::unique_ptr<TargetLibraryInfoImpl> TLII(
-      new TargetLibraryInfoImpl(TM->getTargetTriple()));
+      new TargetLibraryInfoImpl(TM->getTargetTriple(), TM->Options.VecLib));
   if (Conf.Freestanding)
     TLII->disableAllFunctions();
   FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
@@ -444,7 +444,7 @@ static void codegen(const Config &Conf, TargetMachine *TM,
   // keep the pointer and may use it until their destruction. See #138194.
   {
     legacy::PassManager CodeGenPasses;
-    TargetLibraryInfoImpl TLII(Mod.getTargetTriple());
+    TargetLibraryInfoImpl TLII(Mod.getTargetTriple(), TM->Options.VecLib);
     CodeGenPasses.add(new TargetLibraryInfoWrapperPass(TLII));
     // No need to make index available if the module is empty.
     // In theory these passes should not use the index for an empty
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index ff94c54ab3e6e..ed26c931d0629 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -249,7 +249,7 @@ static void optimizeModule(Module &TheModule, TargetMachine &TM,
   PassBuilder PB(&TM, PTO, PGOOpt, &PIC);
 
   std::unique_ptr<TargetLibraryInfoImpl> TLII(
-      new TargetLibraryInfoImpl(TM.getTargetTriple()));
+      new TargetLibraryInfoImpl(TM.getTargetTriple(), TM.Options.VecLib));
   if (Freestanding)
     TLII->disableAllFunctions();
   FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
diff --git a/llvm/lib/LTO/UpdateCompilerUsed.cpp b/llvm/lib/LTO/UpdateCompilerUsed.cpp
index 1889c2b762ff7..f79a3744afad3 100644
--- a/llvm/lib/LTO/UpdateCompilerUsed.cpp
+++ b/llvm/lib/LTO/UpdateCompilerUsed.cpp
@@ -57,7 +57,7 @@ class PreserveLibCallsAndAsmUsed {
   // same names are added to llvm.compiler.used to prevent them from being
   // deleted by optimizations.
   void initializeLibCalls(const Module &TheModule) {
-    TargetLibraryInfoImpl TLII(TM.getTargetTriple());
+    TargetLibraryInfoImpl TLII(TM.getTargetTriple(), TM.Options.VecLib);
     TargetLibraryInfo TLI(TLII);
 
     // TargetLibraryInfo has info on C runtime library calls on the current

Copy link
Contributor

@teresajohnson teresajohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes seem straightforward, but it needs tests (probably in llvm/test/LTO/ARM?). Since you are modifying both the old and new LTO APIs, you'd want one using llvm-lto (old LTO API) and one using llvm-lto2 (new LTO API). As examples, there are some llvm-lto tests already in that directory, and some llvm-lto2 tests under the X86 directory.

@usha1830 usha1830 merged commit edf80dc into llvm:main Dec 9, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LTO Link time optimization (regular/full LTO or ThinLTO)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants