LLVM: Cannot select: intrinsic %llvm.spu.si.sf
clang, intrinsics, llvm
Solution
This is ubuntu bug: https://bugs.launchpad.net/ubuntu/+source/llvm-3.2/+bug/1131614. Looks like they patched llvm+clang blindly, without understanding what they are doing.
Problem
I am getting this error ``` > clang -std=c99 -c derivative.c -o derivative.a fatal error: error in backend: Cannot select: intrinsic %llvm.spu.si.sf ``` when I try to compile this simple C program with Clang ``` #include <stdio.h> #include <math.h> int N = 100; double H = 0.001; double PI = 3.14159265; void derive(double* input, long elements, double* output) { for (int i = 1; i < elements - 1; i++) { output[i - 1] = (input[i + 1] - input[i - 1])/ (2 * H); } } int main() { double f[N]; double f_prime[N - 2]; for (int i = 0; i < N; i++) { f[i] = sin(i * 2 * PI / (double)N); } derive(f, N, f_prime); for (int i = 0; i < N - 2; i++) { printf("%f %f\n", i * 2 * PI / (double)N, f_prime[i]); } } ``` I already searched the Internet, but was not (yet) able to find a solution. When I compile to Bitcode, it compiles but the execution dumps core. ``` > clang -emit-llvm -c derivative.c -o derivative.bc > lli derivative.bc lli: BitcodeReader.cpp:283: llvm::Value* llvm::BitcodeReaderValueList::getValueFwdRef(unsigned int, llvm::Type*): Assertion `(Ty == 0 || Ty == V->getType()) && "Type mismatch in value table!"' failed. 0 lli 0x0000000000c6fb02 1 lli 0x0000000000c6ff93 2 libpthread.so.0 0x00007f304d7dbbd0 3 libc.so.6 0x00007f304ca19037 gsignal + 55 4 libc.so.6 0x00007f304ca1c698 abort + 328 5 libc.so.6 0x00007f304ca11e03 6 libc.so.6 0x00007f304ca11eb2 7 lli 0x000000000052eeb0 llvm::BitcodeReaderValueList::getConstantFwdRef(unsigned int, llvm::Type*) + 0 8 lli 0x0000000000538943 llvm::BitcodeReader::ParseFunctionBody(llvm::Function*) + 10275 9 lli 0x000000000053acb1 llvm::BitcodeReader::Materialize(llvm::GlobalValue*, std::string*) + 241 10 lli 0x0000000000535195 llvm::BitcodeReader::MaterializeModule(llvm::Module*, std::string*) + 85 11 lli 0x0000000000c0a82f llvm::Module::MaterializeAllPermanently(std::string*) + 31 12 lli 0x00000000005360fc llvm::ParseBitcodeFile(llvm::MemoryBuffer*, llvm::LLVMContext&, std::string*) + 44 13 lli 0x00000000004f70b7 14 lli 0x00000000004e74f3 main + 339 15 libc.so.6 0x00007f304ca03ea5 __libc_start_main + 245 16 lli 0x00000000004f0f41 Stack dump: 0. Program arguments: lli derivative.bc Aborted (core dumped) ``` Trying `llvm-dis` on the bc-file yields an almost identical core dump. EDIT: I tried to find the minimal failing example, and it seems, the problem is defining the array size via the constant. this fails: ``` int main() { int N = 100; double f[N]; } ``` this works: ``` int main() { double f[100]; } ``` EDIT2: Changing `int N = 100` to `const int N = 100` makes the program compile with Clang. It makes sense that the variable should be `const`, but on the other hand, `gcc -std=c99 -Wall derivative.c -lm` does not complain if it is not `const`.