Skip to content

Commit

Permalink
Fix for Issue #1413
Browse files Browse the repository at this point in the history
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 pawosm-arm committed May 14, 2024
1 parent 76a4fee commit 311671a
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 105 deletions.
11 changes: 8 additions & 3 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ static bool asanUseGlobalsGC(const Triple &T, const CodeGenOptions &CGOpts) {
}

static TargetLibraryInfoImpl *createTLII(llvm::Triple &TargetTriple,
const CodeGenOptions &CodeGenOpts) {
const CodeGenOptions &CodeGenOpts,
const clang::TargetOptions &TargetOpts) {
TargetLibraryInfoImpl *TLII = new TargetLibraryInfoImpl(TargetTriple);

switch (CodeGenOpts.getVecLib()) {
Expand All @@ -276,6 +277,10 @@ static TargetLibraryInfoImpl *createTLII(llvm::Triple &TargetTriple,
case CodeGenOptions::PGMATH:
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::PGMATH,
TargetTriple);
if (std::find(TargetOpts.Features.begin(), TargetOpts.Features.end(), "+avx512f") != TargetOpts.Features.end()) {
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::PGMATH_AVX512,
TargetTriple);
}
break;
#endif
case CodeGenOptions::SVML:
Expand Down Expand Up @@ -584,7 +589,7 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
raw_pwrite_stream *DwoOS) {
// Add LibraryInfo.
std::unique_ptr<TargetLibraryInfoImpl> TLII(
createTLII(TargetTriple, CodeGenOpts));
createTLII(TargetTriple, CodeGenOpts,TargetOpts));
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));

// Normal mode, emit a .s or .o file by running the code generator. Note,
Expand Down Expand Up @@ -914,7 +919,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
// Register the target library analysis directly and give it a customized
// preset TLI.
std::unique_ptr<TargetLibraryInfoImpl> TLII(
createTLII(TargetTriple, CodeGenOpts));
createTLII(TargetTriple, CodeGenOpts,TargetOpts));
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 @@ -98,6 +98,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 311671a

Please sign in to comment.