Skip to content

Commit d3c9d1a

Browse files
shivaramaaraobryanpkc
authored andcommitted
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 b50e2c5 commit d3c9d1a

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
@@ -613,8 +613,11 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
613613
raw_pwrite_stream &OS,
614614
raw_pwrite_stream *DwoOS) {
615615
// Add LibraryInfo.
616-
std::unique_ptr<TargetLibraryInfoImpl> TLII(
617-
llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
616+
bool TargetHasAVX512 =
617+
std::find(TargetOpts.Features.begin(), TargetOpts.Features.end(),
618+
"+avx512f") != TargetOpts.Features.end();
619+
std::unique_ptr<TargetLibraryInfoImpl> TLII(llvm::driver::createTLII(
620+
TargetTriple, CodeGenOpts.getVecLib(), TargetHasAVX512));
618621
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));
619622

620623
// Normal mode, emit a .s or .o file by running the code generator. Note,
@@ -964,8 +967,11 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
964967

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

971977
// 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)