Skip to content

Commit

Permalink
Disable -avx512f on LLVM < 5.0.0 to avoid bug 30542
Browse files Browse the repository at this point in the history
Prior to this commit, we could accidentally trigger llvm bug 30542
(https://bugs.llvm.org/show_bug.cgi?id=30542) on a cpu with the
`avx512f` feature. See WallarooLabs/wally#1925
for one particular example of this occurring.

This commit automagically disables `avx512f` if the LLVM in use is
below version 5.0.0 to work around the issue.
  • Loading branch information
dipinhora authored and SeanTAllen committed Jan 9, 2018
1 parent 884c62d commit bd4f985
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ There is experimental support for building with LLVM 4.0.1 or 5.0.0,
but this may result in decreased performance or crashes in generated
applications.

NOTE: If LLVM version < 5.0.0 is used, cpu feature `avx512f` is diabled automagically to avoid [LLVM bug 30542](https://bugs.llvm.org/show_bug.cgi?id=30542) otherwise the compiler crashes during the optimization phase.

Compiling Pony is only possible on x86 and ARM (either 32 or 64 bits).

## Building on Linux
Expand Down
19 changes: 19 additions & 0 deletions src/libponyc/codegen/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,12 +978,31 @@ bool codegen_pass_init(pass_opt_t* opt)
{
if(opt->features != NULL)
{
#if PONY_LLVM < 500
// Disable -avx512f on LLVM < 5.0.0 to avoid bug https://bugs.llvm.org/show_bug.cgi?id=30542
size_t temp_len = strlen(opt->features) + 9;
char* temp_str = (char*)ponyint_pool_alloc_size(temp_len);
snprintf(temp_str, temp_len, "%s,-avx512f", opt->features);

opt->features = temp_str;
#endif

opt->features = LLVMCreateMessage(opt->features);


#if PONY_LLVM < 500
// free memory for temp_str
ponyint_pool_free_size(temp_len, temp_str);
#endif
} else {
if((opt->cpu == NULL) && (opt->triple == NULL))
opt->features = LLVMGetHostCPUFeatures();
else
#if PONY_LLVM < 500
opt->features = LLVMCreateMessage("-avx512f");
#else
opt->features = LLVMCreateMessage("");
#endif
}

// Default triple, cpu and features.
Expand Down
10 changes: 10 additions & 0 deletions src/libponyc/codegen/host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ char* LLVMGetHostCPUFeatures()
for(auto it = features.begin(); it != features.end(); it++)
buf_size += (*it).getKey().str().length() + 2; // plus +/- char and ,/null

#if PONY_LLVM < 500
// Add extra buffer space for llvm bug workaround
buf_size += 9;
#endif

char* buf = (char*)malloc(buf_size);
pony_assert(buf != NULL);
buf[0] = 0;
Expand All @@ -64,6 +69,11 @@ char* LLVMGetHostCPUFeatures()
strcat(buf, ",");
}

#if PONY_LLVM < 500
// Disable -avx512f on LLVM < 5.0.0 to avoid bug https://bugs.llvm.org/show_bug.cgi?id=30542
strcat(buf, ",-avx512f");
#endif

return buf;
}

Expand Down

0 comments on commit bd4f985

Please sign in to comment.