public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Dan Nicolaescu <dann@godzilla.ics.uci.edu> To: gcc-gnats@gcc.gnu.org Subject: c/2480: aliasing problem with global structures Date: Tue, 03 Apr 2001 16:56:00 -0000 [thread overview] Message-ID: <20010403234820.13970.qmail@sourceware.cygnus.com> (raw) >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:
next reply other threads:[~2001-04-03 16:56 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2001-04-03 16:56 Dan Nicolaescu [this message] 2003-03-07 2:19 bangerth 2003-05-03 23:26 Dan Nicolaescu
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20010403234820.13970.qmail@sourceware.cygnus.com \ --to=dann@godzilla.ics.uci.edu \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).