Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable -avx512f on LLVM < 5.0.0 to avoid LLVM bug 30542 #2475

Merged
merged 1 commit into from
Jan 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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