-
Notifications
You must be signed in to change notification settings - Fork 15.6k
[LTO][Veclib] Fix vector library handling with LTO #170638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-lto Author: Usha Gupta (usha1830) ChangesCommit #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 This PR completes the fix by ensuring that: LTOBackend.cpp, ThinLTOCodeGenerator.cpp, UpdateCompilerUsed.cpp all pass 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:
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
|
teresajohnson
left a comment
There was a problem hiding this 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.
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.VecLibwhen 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.