http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48774
Summary: gcc-4.6.0 optimization regression on x86_64-unknown-linux-gnu Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: mariah.le...@gmail.com /* gcc-4.6.0 optimization regression on x86_64-unknown-linux-gnu: % gcc -O1 -funroll-loops -o foo foo.c foo order= 11 % % gcc -O2 -funroll-loops -o foo foo.c foo # hangs make: *** [bad] Interrupt % % gcc-4.5.1 -O2 -funroll-loops -o foo foo.c foo order=11 % % gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/local/gcc-4.6.0/x86_64-Linux-core2-fc/libexec/gcc/x86_64-unknown-linux-gnu/4.6.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: /usr/local/gcc-4.6.0/src/gcc-4.6.0/configure --enable-languages=c,c++,fortran --with-gnu-as --with-gnu-as=/usr/local/binutils-2.21/x86_64-Linux-core2-fc-gcc-4.5.1-rh/bin/as --with-gnu-ld --with-ld=/usr/local/binutils-2.21/x86_64-Linux-core2-fc-gcc-4.5.1-rh/bin/ld --with-gmp=/usr/local/mpir-2.3.0/x86_64-Linux-core2-fc-gcc-4.5.1-rh --with-mpfr=/usr/local/mpfr-3.0.0/x86_64-Linux-core2-fc-mpir-2.3.0-gcc-4.5.1-rh --with-mpc=/usr/local/mpc-0.9/x86_64-Linux-core2-fc-mpir-2.3.0-mpfr-3.0.0-gcc-4.5.1-rh --prefix=/usr/local/gcc-4.6.0/x86_64-Linux-core2-fc Thread model: posix gcc version 4.6.0 (GCC) % Apologies that this code is so long, but I can not find any way to shorten it further and still demonstrate the bug. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define SIZE 12 unsigned long int ss[SIZE][2]; #define SET_BIT_MASK(x) ((unsigned long)1<<(x)) #define SET_ELEMENT_CONTAINS(e,v) ((e)&SET_BIT_MASK(v)) #define SET_CONTAINS_FAST(s,a) (SET_ELEMENT_CONTAINS((s)[0], (a))) #define SET_CONTAINS(s,a) (((a)<SET_MAX_SIZE(s))?SET_CONTAINS_FAST(s,a):0) #define SET_MAX_SIZE(s) ((s)[-1]) typedef struct graph graph_t; struct graph { int n; unsigned long *edges[SIZE]; } gg; #define GRAPH_IS_EDGE(g,i,j) \ (((j)<(((g)->edges[(0)]))[-1])?SET_CONTAINS_FAST((g)->edges[(i)],j):0) /* SET_CONTAINS((g)->edges[(i)], (j)) */ int bar(graph_t *g) { int i,j,v; int tmp_used[SIZE]; int degree[SIZE]; int order[SIZE]; int maxdegree,maxvertex=0; int samecolor; for (i = 0; i < SIZE; i++) { order[i] = 0; degree[i] = 0; } for (i=0; i < g->n; i++) { for (j=0; j < g->n; j++) { if ((i==j) && GRAPH_IS_EDGE(g,i,j)) { exit(0);; } if (GRAPH_IS_EDGE(g,i,j)) degree[i]++; } } v=0; while (v < SIZE) { memset(tmp_used,0,SIZE * sizeof(int)); do { maxdegree=0; samecolor=0; for (i=0; i < SIZE; i++) { if (!tmp_used[i] && degree[i] >= maxdegree) { maxvertex=i; maxdegree=degree[i]; samecolor=1; } } if (samecolor) { order[v]=maxvertex; degree[maxvertex]=-1; v++; for (i=0; i < SIZE; i++) { if (GRAPH_IS_EDGE(g,maxvertex,i)) { tmp_used[i]=1; degree[i]--; } } } } while (samecolor); } return order[0]; } graph_t *make_graph() { graph_t *g; int i; for (i=0; i < SIZE; i++) { ss[i][0] = SIZE; } ss[0][1] = 2114; ss[1][1] = 37; ss[2][1] = 1034; ss[3][1] = 532; ss[4][1] = 296; ss[5][1] = 82; ss[6][1] = 161; ss[7][1] = 2368; ss[8][1] = 656; ss[9][1] = 1288; ss[10][1] = 2564; ss[11][1] = 1153; g = ≫ g->n=SIZE; for (i=0; i < SIZE; i++) { g->edges[i]=&(ss[i][1]); } return g; } int main(int argc, char **argv) { graph_t *g; int order; g = make_graph(); order = bar(g); printf("order= %d\n", order); return 0; }