Skip to content

Commit 311671a

Browse files
shivaramaaraopawosm-arm
authored andcommitted
Fix for Issue #1413
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 76a4fee commit 311671a

File tree

4 files changed

+145
-105
lines changed

4 files changed

+145
-105
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ static bool asanUseGlobalsGC(const Triple &T, const CodeGenOptions &CGOpts) {
256256
}
257257

258258
static TargetLibraryInfoImpl *createTLII(llvm::Triple &TargetTriple,
259-
const CodeGenOptions &CodeGenOpts) {
259+
const CodeGenOptions &CodeGenOpts,
260+
const clang::TargetOptions &TargetOpts) {
260261
TargetLibraryInfoImpl *TLII = new TargetLibraryInfoImpl(TargetTriple);
261262

262263
switch (CodeGenOpts.getVecLib()) {
@@ -276,6 +277,10 @@ static TargetLibraryInfoImpl *createTLII(llvm::Triple &TargetTriple,
276277
case CodeGenOptions::PGMATH:
277278
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::PGMATH,
278279
TargetTriple);
280+
if (std::find(TargetOpts.Features.begin(), TargetOpts.Features.end(), "+avx512f") != TargetOpts.Features.end()) {
281+
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::PGMATH_AVX512,
282+
TargetTriple);
283+
}
279284
break;
280285
#endif
281286
case CodeGenOptions::SVML:
@@ -584,7 +589,7 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
584589
raw_pwrite_stream *DwoOS) {
585590
// Add LibraryInfo.
586591
std::unique_ptr<TargetLibraryInfoImpl> TLII(
587-
createTLII(TargetTriple, CodeGenOpts));
592+
createTLII(TargetTriple, CodeGenOpts,TargetOpts));
588593
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));
589594

590595
// Normal mode, emit a .s or .o file by running the code generator. Note,
@@ -914,7 +919,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
914919
// Register the target library analysis directly and give it a customized
915920
// preset TLI.
916921
std::unique_ptr<TargetLibraryInfoImpl> TLII(
917-
createTLII(TargetTriple, CodeGenOpts));
922+
createTLII(TargetTriple, CodeGenOpts,TargetOpts));
918923
FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
919924

920925
// 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
@@ -98,6 +98,7 @@ class TargetLibraryInfoImpl {
9898
MASSV, // IBM MASS vector library.
9999
#ifdef ENABLE_CLASSIC_FLANG
100100
PGMATH, // PGI math library.
101+
PGMATH_AVX512, // PGI math library (AVX512 subset).
101102
#endif
102103
SVML, // Intel short vector math library.
103104
SLEEFGNUABI, // SLEEF - SIMD Library for Evaluating Elementary Functions.

0 commit comments

Comments
 (0)