Skip to content

Commit 7b4f17d

Browse files
Fix for Issue #1413 (cherry-pick #179 to release_18x) (#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.
1 parent 415352e commit 7b4f17d

File tree

6 files changed

+151
-109
lines changed

6 files changed

+151
-109
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,11 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
557557
raw_pwrite_stream &OS,
558558
raw_pwrite_stream *DwoOS) {
559559
// Add LibraryInfo.
560-
std::unique_ptr<TargetLibraryInfoImpl> TLII(
561-
llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
560+
bool TargetHasAVX512 =
561+
std::find(TargetOpts.Features.begin(), TargetOpts.Features.end(),
562+
"+avx512f") != TargetOpts.Features.end();
563+
std::unique_ptr<TargetLibraryInfoImpl> TLII(llvm::driver::createTLII(
564+
TargetTriple, CodeGenOpts.getVecLib(), TargetHasAVX512));
562565
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));
563566

564567
// Normal mode, emit a .s or .o file by running the code generator. Note,
@@ -890,8 +893,11 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
890893

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

897903
// Register all the basic analyses with the managers.

llvm/include/llvm/Analysis/TargetLibraryInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class TargetLibraryInfoImpl {
130130
MASSV, // IBM MASS vector library.
131131
#ifdef ENABLE_CLASSIC_FLANG
132132
PGMATH, // PGI math library.
133+
PGMATH_AVX512, // PGI math library (AVX512 subset).
133134
#endif
134135
SVML, // Intel short vector math library.
135136
SLEEFGNUABI, // SLEEF - SIMD Library for Evaluating Elementary Functions.

0 commit comments

Comments
 (0)