Skip to content

Instantly share code, notes, and snippets.

@lemire
Last active December 23, 2015 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lemire/6642148 to your computer and use it in GitHub Desktop.
Save lemire/6642148 to your computer and use it in GitHub Desktop.
Found a bug in the Intel compiler.
// Code sample illustrating a bug in the Intel compiler
// icpc (ICC) 13.0.1 20121010
// compile with:
// icc -restrict -std=c99 -O2 iccbug.c -o iccbug
// then run iccbug
// Tested in Linux Ubuntu 12.10 (Intel Core i7)
#include <stdint.h>
#include <stdio.h>
// expect: out[0] = in[0] + in[1] + in[2] + in[3];
// out[1] = in[4] + in[5] + in[6] + in[7];
__attribute__((noinline))
void broken_with_O2(int * restrict in,
int * out) {
for(int outer = 0; outer < 2; outer++) {
*out = *in++;
for (int inner = 1; inner < 4; inner++) {
*out += *in++;
}
++out;
}
}
int main() {
int in[8] = {1,1,1,1,1,1,1,1};
int out[2];
broken_with_O2(&in[0],&out[0]);
printf(" got = %d %d\n",out[0], out[1]);
printf(" expected = %d %d\n", 4,4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment