[llvm] [LTO][Veclib] Fix vector library handling with LTO (PR #170638)

via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 5 11:03:51 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lto

Author: Usha Gupta (usha1830)

<details>
<summary>Changes</summary>

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

``````````

</details>


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


More information about the llvm-commits mailing list