title: LLVM: Cannot select: intrinsic %llvm.spu.si.sf
body: <p>I am getting this error</p>
  
  <pre><code>&gt; clang -std=c99 -c derivative.c -o derivative.a
  fatal error: error in backend: Cannot select: intrinsic %llvm.spu.si.sf
  </code></pre>
  
  <p>when I try to compile this simple C program with Clang</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  
  int N = 100;
  double H = 0.001;
  double PI = 3.14159265;
  
  void derive(double* input, long elements, double* output) {
    for (int i = 1; i &lt; 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 &lt; N; i++) {
      f[i] = sin(i * 2 * PI / (double)N);
    }
  
    derive(f, N, f_prime);
  
    for (int i = 0; i &lt; N - 2; i++) {
      printf("%f  %f\n", i * 2 * PI / (double)N, f_prime[i]);
    }
  }
  </code></pre>
  
  <p>I already searched the Internet, but was not (yet) able to find a solution.</p>
  
  <p>When I compile to Bitcode, it compiles but the execution dumps core.</p>
  
  <pre><code>&gt; clang -emit-llvm -c derivative.c -o derivative.bc
  &gt; lli derivative.bc
  lli: BitcodeReader.cpp:283: llvm::Value* llvm::BitcodeReaderValueList::getValueFwdRef(unsigned int, llvm::Type*): Assertion `(Ty == 0 || Ty == V-&gt;getType()) &amp;&amp; "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&amp;, 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)
  </code></pre>
  
  <p>Trying <code>llvm-dis</code> on the bc-file yields an almost identical core dump.</p>
  
  <p><strong>EDIT</strong>:
  I tried to find the minimal failing example, and it seems, the problem is defining the array size via the constant.</p>
  
  <p>this fails:</p>
  
  <pre><code>int main() {
    int N = 100;
    double f[N];
  }
  </code></pre>
  
  <p>this works:</p>
  
  <pre><code>int main() {
    double f[100];
  }
  </code></pre>
  
  <p><strong>EDIT2</strong>:</p>
  
  <p>Changing <code>int N = 100</code> to <code>const int N = 100</code> makes the program compile with Clang.
  It makes sense that the variable should be <code>const</code>, but on the other hand, <code>gcc -std=c99 -Wall derivative.c -lm</code> does not complain if it is not <code>const</code>.</p>