public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c/2480: aliasing problem with global structures
@ 2003-05-03 23:26 Dan Nicolaescu
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Nicolaescu @ 2003-05-03 23:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c/2480; it has been noted by GNATS.

From: Dan Nicolaescu <dann@ics.uci.edu>
To: bangerth@dealii.org
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c/2480: aliasing problem with global structures
Date: Sat, 03 May 2003 16:18:09 -0700

 With the tweaks below the code in this PR can be added to the
 GCC testsuite in case somebody wants to do that.
 
 /* { dg-do link } */
 
 struct example
 {
   char a;
   int b;
   char c;
 } *ex1;
 
 extern void link_error(void);
 
 void
 bar (void)
 {
   ex1->a = 1;
   ex1->b = 2;
   ex1->c = 3;
   
   if (ex1->a != 1)
     link_error ();
   if (ex1->b != 2)
     link_error ();
   if (ex1->c != 3)
     link_error ();
 
 }
 
 void
 foo (struct example *ex2)
 {
   ex2->a = 1;
   ex2->b = 2;
   ex2->c = 3;
 
   if (ex2->a != 1)
     link_error ();
   if (ex2->b != 2)
     link_error ();
   if (ex2->c != 3)
     link_error ();
 
 }
 
 int main (void)
 {
   bar ();
   foo (ex1);
   return 0;
 }


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

* Re: c/2480: aliasing problem with global structures
@ 2003-03-07  2:19 bangerth
  0 siblings, 0 replies; 3+ messages in thread
From: bangerth @ 2003-03-07  2:19 UTC (permalink / raw)
  To: dann, gcc-bugs, gcc-prs, nobody

Synopsis: aliasing problem with global structures

State-Changed-From-To: open->analyzed
State-Changed-By: bangerth
State-Changed-When: Fri Mar  7 02:19:07 2003
State-Changed-Why:
    Indeed. This odd behavior persists in 3.2, 3.3 and present
    mainline. Annoying. As noted, this is even better visible
    in x86 assembler:
    
    bar:
    	pushl %ebp
    	movl %esp,%ebp
    	movl ex1,%eax
    	movb $1,(%eax)
    	movl ex1,%eax    <-- this is the duplicate reload
    	movl $2,4(%eax)
    	movb $3,8(%eax)
    	movl %ebp,%esp
    	popl %ebp
    	ret
    
    foo:
    	pushl %ebp
    	movl %esp,%ebp
    	movl 8(%ebp),%eax
    	movb $1,(%eax)
    	movl $2,4(%eax)
    	movb $3,8(%eax)
    	movl %ebp,%esp
    	popl %ebp
    	ret
    
    W.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=2480


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

* c/2480: aliasing problem with global structures
@ 2001-04-03 16:56 Dan Nicolaescu
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Nicolaescu @ 2001-04-03 16:56 UTC (permalink / raw)
  To: gcc-gnats

>Number:         2480
>Category:       c
>Synopsis:       aliasing problem with global structures
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          pessimizes-code
>Submitter-Id:   net
>Arrival-Date:   Tue Apr 03 16:55:59 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Dan Nicolaescu <dann@godzilla.ics.uci.edu>
>Release:        gcc version 3.1 20010402 (experimental)
>Organization:
>Environment:
sun-sparc-solaris2.7
>Description:
The following code: 

struct example
{
  char a;
  int  b;
  char c;
} *ex1;

void
bar (void)
{
  ex1->a = 1;
  ex1->b = 2;
  ex1->c = 3;
}

void
foo (struct example *ex2)
{
  ex2->a = 1;
  ex2->b = 2;
  ex2->c = 3;
}

When compiled with -O2 -fstrict-aliasing -S on sun-sparc-solaris2.7 
with a GCC mainline snapshot from 2000-04-02 
(but the same problem occurs on the GCC-3.0 branch and 2.95.2)


bar:
	!#PROLOGUE# 0
	!#PROLOGUE# 1
	sethi	%hi(ex1), %o2
	ld	[%o2+%lo(ex1)], %o1
	mov	1, %o0
	stb	%o0, [%o1]
	ld	[%o2+%lo(ex1)], %o3
	^^^^^
	after the store ex1 is reloaded. 
	true_dependence returns true for these last 2 instructions, it
	seems that the ex1->a is put in the alias set 0. That is a
	mistake, but I couldn't find where that is done....
	
	It looks like GCC treats ex1->a as a char*, but that is
	incorrect, a store to ex1->a cannot alias ex1

	mov	3, %o0
	mov	2, %o1
	st	%o0, [%o3+8]
	^^^ 
	After this store ex1 is not reloaded, but in this case the
	struct member is an "int"
	
	retl
	st	%o1, [%o3+4]


foo:
	!#PROLOGUE# 0
	!#PROLOGUE# 1
	mov	3, %o1
	st	%o1, [%o0+8]
	mov	1, %o2
	mov	2, %o1
	stb	%o2, [%o0]
	retl
	st	%o1, [%o0+4]

nothing like that happens here, when the pointer to the structure is
passed as a parameter. 


This is an important pessimization. 
GCC itself contains a lot of global pointers to structures...


>How-To-Repeat:
Compile the code in the description with -O2 -S -fstrict-aliasing
and look at the resulting assembly
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2003-05-03 23:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-03 23:26 c/2480: aliasing problem with global structures Dan Nicolaescu
  -- strict thread matches above, loose matches on Subject: below --
2003-03-07  2:19 bangerth
2001-04-03 16:56 Dan Nicolaescu

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).