Skip to content

Commit

Permalink
Fix for Issue #1413 (cherry-pick flang-compiler#179 to release_18x) (f…
Browse files Browse the repository at this point in the history
…lang-compiler#185)

PGMATH has AVX512 runtime functions and can be executed only when the application is compiled
in avx512 mode. The VecFuncs.def has no information about the TargetOptions and avx512 functions
are selected even in avx2 mode. This issue is fixed by creating separate table for AVX512 functions
and using them only when avx512 mode is specified.
  • Loading branch information
shivaramaarao authored and bryanpkc committed Sep 18, 2024
1 parent 632e72e commit 48e3dbb
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 109 deletions.
14 changes: 10 additions & 4 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,11 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
raw_pwrite_stream &OS,
raw_pwrite_stream *DwoOS) {
// Add LibraryInfo.
std::unique_ptr<TargetLibraryInfoImpl> TLII(
llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
bool TargetHasAVX512 =
std::find(TargetOpts.Features.begin(), TargetOpts.Features.end(),
"+avx512f") != TargetOpts.Features.end();
std::unique_ptr<TargetLibraryInfoImpl> TLII(llvm::driver::createTLII(
TargetTriple, CodeGenOpts.getVecLib(), TargetHasAVX512));
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));

// Normal mode, emit a .s or .o file by running the code generator. Note,
Expand Down Expand Up @@ -930,8 +933,11 @@ void EmitAssemblyHelper::RunOptimizationPipeline(

// Register the target library analysis directly and give it a customized
// preset TLI.
std::unique_ptr<TargetLibraryInfoImpl> TLII(
llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
bool TargetHasAVX512 =
std::find(TargetOpts.Features.begin(), TargetOpts.Features.end(),
"+avx512f") != TargetOpts.Features.end();
std::unique_ptr<TargetLibraryInfoImpl> TLII(llvm::driver::createTLII(
TargetTriple, CodeGenOpts.getVecLib(), TargetHasAVX512));
FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });

// Register all the basic analyses with the managers.
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/Analysis/TargetLibraryInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class TargetLibraryInfoImpl {
MASSV, // IBM MASS vector library.
#ifdef ENABLE_CLASSIC_FLANG
PGMATH, // PGI math library.
PGMATH_AVX512, // PGI math library (AVX512 subset).
#endif
SVML, // Intel short vector math library.
SLEEFGNUABI, // SLEEF - SIMD Library for Evaluating Elementary Functions.
Expand Down
Loading

0 comments on commit 48e3dbb

Please sign in to comment.