public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/41630]  New: Optimization error on vectors of uint64_t
@ 2009-10-08 13:49 emanuele dot cesena at gmail dot com
  2009-10-08 13:50 ` [Bug c/41630] " emanuele dot cesena at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: emanuele dot cesena at gmail dot com @ 2009-10-08 13:49 UTC (permalink / raw)
  To: gcc-bugs

System.
Fedora 11 - Linux 2.6.30.8-64.fc11.x86_64 #1 SMP
gcc-4.4.1, Release: 2.fc11 (Fedora's package)


Problem in short.
definitions:
  typedef uint64_t obj[1];
obj x0, x1, X[2];
then the following code doesn't work:
  X[0][0] = x0[0];
  X[1][0] = x1[0];
while this works:
  *X[0] = *x0;
  *X[1] = *x1;
(As far as I know these are equivalent).
Problem only with -O3 and 64-bit code.
Works perfectly at least with gcc34, -O2 and/or 32-bit code.


Detailed information.

The program gcc-bug.c compiled as
  gcc -Wall -O3 -o gcc-bug gcc-bug.c
produce the following (wrong) output:
(1) x0 = 12345
(1) x1 = 67890
(2) x0 = 12345
(2) x1 = 4195296
instead of the correct one:
(1) x0 = 12345
(1) x1 = 67890
(2) x0 = 12345
(2) x1 = 67890

In attachment gcc-bug.c and gcc-bug.i, generated with -v -save-temps.


-- 
           Summary: Optimization error on vectors of uint64_t
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: emanuele dot cesena at gmail dot com


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


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

* [Bug c/41630] Optimization error on vectors of uint64_t
  2009-10-08 13:49 [Bug c/41630] New: Optimization error on vectors of uint64_t emanuele dot cesena at gmail dot com
@ 2009-10-08 13:50 ` emanuele dot cesena at gmail dot com
  2009-10-08 13:52 ` emanuele dot cesena at gmail dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: emanuele dot cesena at gmail dot com @ 2009-10-08 13:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from emanuele dot cesena at gmail dot com  2009-10-08 13:50 -------
Created an attachment (id=18750)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18750&action=view)
source


-- 


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


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

* [Bug c/41630] Optimization error on vectors of uint64_t
  2009-10-08 13:49 [Bug c/41630] New: Optimization error on vectors of uint64_t emanuele dot cesena at gmail dot com
  2009-10-08 13:50 ` [Bug c/41630] " emanuele dot cesena at gmail dot com
@ 2009-10-08 13:52 ` emanuele dot cesena at gmail dot com
  2009-10-08 14:17 ` paolo dot carlini at oracle dot com
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: emanuele dot cesena at gmail dot com @ 2009-10-08 13:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from emanuele dot cesena at gmail dot com  2009-10-08 13:51 -------
Created an attachment (id=18751)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18751&action=view)
preprocessed file


-- 


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


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

* [Bug c/41630] Optimization error on vectors of uint64_t
  2009-10-08 13:49 [Bug c/41630] New: Optimization error on vectors of uint64_t emanuele dot cesena at gmail dot com
  2009-10-08 13:50 ` [Bug c/41630] " emanuele dot cesena at gmail dot com
  2009-10-08 13:52 ` emanuele dot cesena at gmail dot com
@ 2009-10-08 14:17 ` paolo dot carlini at oracle dot com
  2009-10-08 14:52 ` [Bug c/41630] [4.3/4.4 Regression] " rguenth at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-10-08 14:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from paolo dot carlini at oracle dot com  2009-10-08 14:16 -------
Whatever it is, doesn't happen in mainline.


-- 


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


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

* [Bug c/41630] [4.3/4.4 Regression] Optimization error on vectors of uint64_t
  2009-10-08 13:49 [Bug c/41630] New: Optimization error on vectors of uint64_t emanuele dot cesena at gmail dot com
                   ` (2 preceding siblings ...)
  2009-10-08 14:17 ` paolo dot carlini at oracle dot com
@ 2009-10-08 14:52 ` rguenth at gcc dot gnu dot org
  2009-10-08 15:03 ` rguenth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-10-08 14:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2009-10-08 14:52 -------
Simplified testcase, fails at -O1.  Likely an aliasing issue, but I didn't
yet fully investigate (nor ruled out a non-conforming testcase - though
TBAA is out of the question here):

typedef unsigned long obj[1];
extern void abort (void);
static void test_level2(obj X[])
{
    if (*X[0] != 12345
        || *X[1] != 67890)
      abort ();
}
static void test_level1(obj x0, obj x1)
{
    obj X[2];

    X[0][0] = x0[0];
    X[1][0] = x1[0];

    if (*x0 != 12345
        || *x1 != 67890)
      abort ();
    test_level2 (X);
}
int main()
{
    obj X[2];
    *X[0] = 12345;
    *X[1] = 67890;
    test_level1(X[0], X[1]);
    return 0;
}


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
      Known to fail|                            |4.3.4 4.4.1
      Known to work|                            |4.2.4 4.5.0
   Last reconfirmed|0000-00-00 00:00:00         |2009-10-08 14:52:06
               date|                            |
            Summary|Optimization error on       |[4.3/4.4 Regression]
                   |vectors of uint64_t         |Optimization error on
                   |                            |vectors of uint64_t


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


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

* [Bug c/41630] [4.3/4.4 Regression] Optimization error on vectors of uint64_t
  2009-10-08 13:49 [Bug c/41630] New: Optimization error on vectors of uint64_t emanuele dot cesena at gmail dot com
                   ` (3 preceding siblings ...)
  2009-10-08 14:52 ` [Bug c/41630] [4.3/4.4 Regression] " rguenth at gcc dot gnu dot org
@ 2009-10-08 15:03 ` rguenth at gcc dot gnu dot org
  2009-10-08 15:08 ` rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-10-08 15:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2009-10-08 15:03 -------
What we can see after inlining is

<bb 2>:
  X[0][0] ={v} 12345;
  D.1614_1 = (long unsigned int *) &X[1];
  *D.1614_1 ={v} 67890;
  D.1614_2 = (long unsigned int *) &X[1];
  X.0_3 = (long unsigned int *) &X;
  D.1623_5 = *X.0_3;
  X[0][0] ={v} D.1623_5;
  D.1622_6 = *D.1614_2;
  X[1][0] ={v} D.1622_6;
  D.1623_7 = *X.0_3;
  if (D.1623_7 != 12345)
    goto <bb 4>;
...
<bb 6>:
  D.1625_10 = X[0][1];
  if (D.1625_10 != 67890)
    goto <bb 7>;
  else
    goto <bb 8>;

so the final check is reading from X[0][1] but we only ever store to X[1][0].

So the testcase can be simplified to

typedef unsigned long obj[1];
extern void abort (void);
static void test_level2(obj X[])
{
    if (*X[1] != 67890)
      abort ();
}
int main()
{
    obj X[2];
    X[1][0] = 67890;
    test_level2(X);
    return 0;
}

or even to

typedef unsigned long obj[1];
extern void abort (void);
int main()
{
    obj X[2];
    X[1][0] = 67890;
    if (X[0][1] != 67890)
      abort ();
    return 0;
}

which will also fail with 4.2.4 (but still not 4.5.0).  But that also
raises the question of the validity again.


-- 


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


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

* [Bug c/41630] [4.3/4.4 Regression] Optimization error on vectors of uint64_t
  2009-10-08 13:49 [Bug c/41630] New: Optimization error on vectors of uint64_t emanuele dot cesena at gmail dot com
                   ` (5 preceding siblings ...)
  2009-10-08 15:08 ` rguenth at gcc dot gnu dot org
@ 2009-10-08 15:08 ` rguenth at gcc dot gnu dot org
  2010-03-15 14:57 ` rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-10-08 15:08 UTC (permalink / raw)
  To: gcc-bugs



-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.3.5


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


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

* [Bug c/41630] [4.3/4.4 Regression] Optimization error on vectors of uint64_t
  2009-10-08 13:49 [Bug c/41630] New: Optimization error on vectors of uint64_t emanuele dot cesena at gmail dot com
                   ` (4 preceding siblings ...)
  2009-10-08 15:03 ` rguenth at gcc dot gnu dot org
@ 2009-10-08 15:08 ` rguenth at gcc dot gnu dot org
  2009-10-08 15:08 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-10-08 15:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from rguenth at gcc dot gnu dot org  2009-10-08 15:07 -------
With 4.3 and 4.4 it is SRA that does not avoid generating wrong code, with
4.5 SRA optimizes the code correctly and recognizes both forms access the
same memory (and thus we optimize the program to return 0).

Workaround: -fno-tree-sra


-- 


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


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

* [Bug c/41630] [4.3/4.4 Regression] Optimization error on vectors of uint64_t
  2009-10-08 13:49 [Bug c/41630] New: Optimization error on vectors of uint64_t emanuele dot cesena at gmail dot com
                   ` (6 preceding siblings ...)
  2009-10-08 15:08 ` rguenth at gcc dot gnu dot org
@ 2010-03-15 14:57 ` rguenth at gcc dot gnu dot org
  2010-03-15 15:17 ` joseph at codesourcery dot com
  2010-03-15 15:24 ` rguenth at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-03-15 14:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenth at gcc dot gnu dot org  2010-03-15 14:56 -------
Joseph, is this a valid testcase?

typedef unsigned long obj[1];
extern void abort (void);
int main()
{
    obj X[2];
    X[1][0] = 67890;
    if (X[0][1] != 67890)
      abort ();
    return 0;
}


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jsm28 at gcc dot gnu dot org


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


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

* [Bug c/41630] [4.3/4.4 Regression] Optimization error on vectors of uint64_t
  2009-10-08 13:49 [Bug c/41630] New: Optimization error on vectors of uint64_t emanuele dot cesena at gmail dot com
                   ` (7 preceding siblings ...)
  2010-03-15 14:57 ` rguenth at gcc dot gnu dot org
@ 2010-03-15 15:17 ` joseph at codesourcery dot com
  2010-03-15 15:24 ` rguenth at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: joseph at codesourcery dot com @ 2010-03-15 15:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from joseph at codesourcery dot com  2010-03-15 15:17 -------
Subject: Re:  [4.3/4.4 Regression] Optimization error on vectors
 of uint64_t

On Mon, 15 Mar 2010, rguenth at gcc dot gnu dot org wrote:

> Joseph, is this a valid testcase?
> 
> typedef unsigned long obj[1];
> extern void abort (void);
> int main()
> {
>     obj X[2];
>     X[1][0] = 67890;
>     if (X[0][1] != 67890)

This access to X[0][1] looks like an out-of-bounds access that is 
undefined behavior like the example in Annex J: "An array subscript is out 
of range, even if an object is apparently accessible with the given 
subscript (as in the lvalue expression a[1][7] given the declaration int 
a[4][5]) (6.5.6).".  (This originates in C90 DR#017; the example was added 
in C90 TC1.)


-- 


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


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

* [Bug c/41630] [4.3/4.4 Regression] Optimization error on vectors of uint64_t
  2009-10-08 13:49 [Bug c/41630] New: Optimization error on vectors of uint64_t emanuele dot cesena at gmail dot com
                   ` (8 preceding siblings ...)
  2010-03-15 15:17 ` joseph at codesourcery dot com
@ 2010-03-15 15:24 ` rguenth at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-03-15 15:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from rguenth at gcc dot gnu dot org  2010-03-15 15:23 -------
Invalid then.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


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


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

end of thread, other threads:[~2010-03-15 15:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-08 13:49 [Bug c/41630] New: Optimization error on vectors of uint64_t emanuele dot cesena at gmail dot com
2009-10-08 13:50 ` [Bug c/41630] " emanuele dot cesena at gmail dot com
2009-10-08 13:52 ` emanuele dot cesena at gmail dot com
2009-10-08 14:17 ` paolo dot carlini at oracle dot com
2009-10-08 14:52 ` [Bug c/41630] [4.3/4.4 Regression] " rguenth at gcc dot gnu dot org
2009-10-08 15:03 ` rguenth at gcc dot gnu dot org
2009-10-08 15:08 ` rguenth at gcc dot gnu dot org
2009-10-08 15:08 ` rguenth at gcc dot gnu dot org
2010-03-15 14:57 ` rguenth at gcc dot gnu dot org
2010-03-15 15:17 ` joseph at codesourcery dot com
2010-03-15 15:24 ` rguenth at gcc dot gnu dot 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).