http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59845
Bug ID: 59845 Summary: loop optimization problem when profiling Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: arshamidi at gmail dot com I'm using g++ with GCC 4.8.1; when I use fprofile-generate too optimize my code, it actually slows down the process time: (constant folding problem within loop?) int main(){ int n; int i; //int n2; printf("Enter a number: "); scanf("%d", &n); //n2 = n/2; printf("divisors are:\n\n"); for (i=1; i <= /*n2*/ n/2; i++) if (n%i == 0) printf("\n%d", i); printf("\n\n end.\n"); return 0; } Here I must use the constant 'n2' (commented out) too actually get the desired speed -in combination with -fprofile-generate. I'm using the following switches: -Ofast;-fomit-frame-pointer;-march=core2; -mfpmath=sse; -fprofile-generate; -Wall no problem without -fprofile-generate and -fprofile-use