public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/59538] New: Optimization of -O2 or higher creates incorrect code in loop
@ 2013-12-17 19:31 arsham at skrenes dot com
  2013-12-17 19:39 ` [Bug middle-end/59538] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: arsham at skrenes dot com @ 2013-12-17 19:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59538

            Bug ID: 59538
           Summary: Optimization of -O2 or higher creates incorrect code
                    in loop
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arsham at skrenes dot com

Created attachment 31462
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31462&action=edit
Small prime number calculating program that shows bug

I'm using Ubuntu 13.10 with all updates installed. GCC was recently updated for
the distribution to:
gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1

Before the update, everything worked correctly. After the update, the -O2 or
higher optimization flag breaks code (in this instance, it's a loop).

I have attached bug.c to this bug report, which compiles with no warnings or
errors. It determines the 10000th prime number (naive algorithm) 5 times and
reports the duration it took for each iteration. If you compile as follows, it
works correctly:
gcc -Wall -Wextra bug.c

If you compile it with optimization level -O2 or higher such as the following,
it breaks the loop:
gcc -O3 -Wall -Wextra bug.c

You will see that it returns the results almost instantly. In the code, I have
a commented print statement that shows the 10000th prime number. If you
uncomment this, it also suddenly works correctly with -O3. It seems the gcc is
"over-optimizing" and breaking the code if variable "i" is not printed.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-12-18  1:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-17 19:31 [Bug c/59538] New: Optimization of -O2 or higher creates incorrect code in loop arsham at skrenes dot com
2013-12-17 19:39 ` [Bug middle-end/59538] " pinskia at gcc dot gnu.org
2013-12-17 19:47 ` arsham at skrenes dot com
2013-12-17 21:13 ` pinskia at gcc dot gnu.org
2013-12-17 21:31 ` arsham at skrenes dot com
2013-12-17 22:28 ` dominiq at lps dot ens.fr
2013-12-18  1:24 ` arsham at skrenes dot com
2013-12-18  1:31 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).