public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/57488] New: [4.9 regression] loop terminates early at -O3
@ 2013-05-31 19:41 dhazeghi at yahoo dot com
  2013-05-31 20:50 ` [Bug tree-optimization/57488] " jakub at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: dhazeghi at yahoo dot com @ 2013-05-31 19:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57488
           Summary: [4.9 regression] loop terminates early at -O3
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dhazeghi at yahoo dot com

The following code is miscompiled with current gcc trunk at -O3 on x86_64-linux
in both 32 and 64-bit modes.  The innermost loop in foo should execute 48
times, but at -O3 it does not (note the only place 'v' is touched is in that
loop).  I've tried reducing the testcase further, but any perturabation seems
to hide the bug.


$ gcc-trunk -v
gcc version 4.9.0 20130531 (experimental) [trunk revision 199531] (GCC) 
$ gcc-trunk -O2 wrong.c 
$ ./a.out 
0
$ gcc-4.8 -O3 wrong.c 
$ ./a.out 
0
$ gcc-trunk -O3 wrong.c 
$ ./a.out 
24
$

---------------------------------------
int printf(const char *, ...);

int i, j, *pj = &j, **ppj = &pj;
int x, *px = &x;

short s, *ps = &s, k;

unsigned short u, *pu = &u, **ppu = &pu;

char c, *pc = &c;

unsigned char v = 48;

int
bar (int p)
{
    p = k;
    *px = **ppu = i;
    *ppj = &p;
    if (**ppj)
        *pj = p;
    return p;
}

void
foo ()
{
    for (; i <= 3; i++)
        for (; j; j--);

    u ^= bar (*pj);

    for (k = 1; k >= 0; k--)
    {
        int l;
        bar (0);
        for (l = 1; l < 5; l++)
        {
            int m;
            for (m = 6; m; m--)
            {
                v--;
                *ps = *pc;
            }
        }
    }
}

int
main ()
{
    foo ();
    printf ("%d\n", v);
    return 0;
}


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

end of thread, other threads:[~2013-10-23 11:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-31 19:41 [Bug tree-optimization/57488] New: [4.9 regression] loop terminates early at -O3 dhazeghi at yahoo dot com
2013-05-31 20:50 ` [Bug tree-optimization/57488] " jakub at gcc dot gnu.org
2013-06-03  8:38 ` rguenth at gcc dot gnu.org
2013-06-20 11:19 ` rguenth at gcc dot gnu.org
2013-06-20 13:04 ` rguenth at gcc dot gnu.org
2013-06-24 10:22 ` rguenth at gcc dot gnu.org
2013-10-23 11:59 ` rguenth at gcc dot gnu.org
2013-10-23 11:59 ` rguenth 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).