Bug 7632 - gcc 3.2 for PowerPC: instruction scheduling ignores dependency in variable asignments
Summary: gcc 3.2 for PowerPC: instruction scheduling ignores dependency in variable as...
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: unknown
: P2 critical
Target Milestone: ---
Assignee: David Edelsohn
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-08-19 04:56 UTC by horst.lehser
Modified: 2005-11-10 03:55 UTC (History)
51 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description horst.lehser 2002-08-19 04:56:01 UTC
the following C source will generate incorrect code

double a;
double foo(void)
{
	((int *)&a)[1] += 5;
	return;
}
Generated assembler
foo:
        lis %r3,a+4@ha
        lis %r5,a@ha
        lwz %r4,a+4@l(%r3)
        lfd %f1,a@l(%r5)	/* a not modified yet */
        addi %r0,%r4,10
        stw %r0,a+4@l(%r3)
        blr

Release:
unknown

How-To-Repeat:
compile the following code with
gcc -O3 -S

double a;
double foo(void)
{
	((int *)&a)[1] += 10;
	return a;
}
Comment 1 Andrew Pinski 2002-08-19 08:22:57 UTC
From: Andrew Pinski <pinskia@physics.uc.edu>
To: Horst.Lehser@hightec-rt.com
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: optimization/7632: gcc 3.2 for PowerPC: instruction scheduling ignores dependency in variable asignments
Date: Mon, 19 Aug 2002 08:22:57 -0400

 It is an invalid use of pointers conversion of ISO C aka aliasing rules.
 
 Thanks,
 Andrew Pinski
 
 On Monday, August 19, 2002, at 07:49 , Horst.Lehser@hightec-
 rt.com wrote:
 
 > double a;
 > double foo(void)
 > {
 > 	((int *)&a)[1] += 5;
 > 	return;
 > }
 

Comment 2 Daniel Jacobowitz 2002-08-19 09:33:59 UTC
From: Daniel Jacobowitz <drow@mvista.com>
To: Horst.Lehser@hightec-rt.com
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: optimization/7632: gcc 3.2 for PowerPC: instruction scheduling ignores dependency in variable asignments
Date: Mon, 19 Aug 2002 09:33:59 -0400

 On Mon, Aug 19, 2002 at 11:49:16AM -0000, Horst.Lehser@hightec-rt.com wrote:
 > 
 > >Number:         7632
 > >Category:       optimization
 > >Synopsis:       gcc 3.2 for PowerPC: instruction scheduling ignores dependency in variable asignments
 > >Confidential:   no
 > >Severity:       critical
 > >Priority:       medium
 > >Responsible:    unassigned
 > >State:          open
 > >Class:          sw-bug
 > >Submitter-Id:   net
 > >Arrival-Date:   Mon Aug 19 04:56:01 PDT 2002
 > >Closed-Date:
 > >Last-Modified:
 > >Originator:     Horst Lehser
 > >Release:        unknown-1.0
 > >Organization:
 > >Environment:
 > 
 > >Description:
 > the following C source will generate incorrect code
 > 
 > double a;
 > double foo(void)
 > {
 > 	((int *)&a)[1] += 5;
 > 	return;
 > }
 > Generated assembler
 > foo:
 >         lis %r3,a+4@ha
 >         lis %r5,a@ha
 >         lwz %r4,a+4@l(%r3)
 >         lfd %f1,a@l(%r5)	/* a not modified yet */
 >         addi %r0,%r4,10
 >         stw %r0,a+4@l(%r3)
 >         blr
 
 (I assume you meant "return a" above).
 
 You may want to read the documentation for -fno-strict-aliasing; your
 code is illegal C.  With -fno-strict-aliasing I get the expected
 result.
 
 -- 
 Daniel Jacobowitz
 MontaVista Software                         Debian GNU/Linux Developer
Comment 3 David Edelsohn 2002-09-11 12:06:03 UTC
Responsible-Changed-From-To: unassigned->dje
Responsible-Changed-Why: PowerPC
Comment 4 David Edelsohn 2002-09-11 12:06:03 UTC
State-Changed-From-To: open->closed
State-Changed-Why: The source code example violates ISO C aliasing rules due to cast.  Either compile with -fno-strict-aliasing or correct the code as described in GCC documentation (e.g., union).
Comment 5 Andrew Pinski 2005-11-10 03:55:20 UTC
Reopening to ...
Comment 6 Andrew Pinski 2005-11-10 03:55:37 UTC
A dup of bug 21920.

*** This bug has been marked as a duplicate of 21920 ***