Article View: gnu.gcc.bug
Article #5954gcc-2.7.2 missed optimization
From: Bruno Haible
Date: Mon, 13 Jan 1997 00:00
Date: Mon, 13 Jan 1997 00:00
71 lines
3092 bytes
3092 bytes
Hi,
Here is an optimization gcc could perform in its pointer and aliasing
analysis:
If p is a pointer to a (non-volatile) word in memory, and a copy of this word
is also in a register, then writing this word out to somewhere in memory does
_not_ make the register copy of *p invalid, assuming that alignof(word) ==
sizeof(word). (Because if in the assignment "*q = *p", q != p, then *p wasn't
affected, while if q == p, it was overwritten with itself.)
Here is a test case which shows a superfluous memory fetch:
========================== foo.c ===============================
typedef struct mylist {
struct bfd * abfd;
struct mylist * next;
struct mylist ** prev;
} mylist;
void mylist_insert (struct mylist ** p, struct mylist * n)
{
n->next = *p;
if (*p)
(*p)->prev = &n->next;
n->prev = p;
*p = n;
}
========================= gcc -O3 -S foo.c =====================
gcc2_compiled.:
___gnu_compiled_c:
.text
.align 4
.global _mylist_insert
.proc 020
_mylist_insert:
!#PROLOGUE# 0
!#PROLOGUE# 1
ld [%o0],%g2 ; fetch *p
st %g2,[%o1+4] ; store it in memory
ld [%o0],%g3 ; <-------- fetch *p again, superfluous
cmp %g3,0
be L4
add %o1,4,%g2
st %g2,[%g3+8]
L4:
st %o0,[%o1+8]
retl
st %o1,[%o0]
================================================================
Compilation log:
$ gcc -v -O3 -S -Wall foo.c
Reading specs from /nfs/ishare/lib/gnu/gcc/2.7.2/sunos/lib/gcc-lib/sparc-sun-sunos4.1.3/2.7.2/specs
gcc version 2.7.2
/nfs/ishare/lib/gnu/gcc/2.7.2/sunos/lib/gcc-lib/sparc-sun-sunos4.1.3/2.7.2/cpp -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=7 -Dsparc -Dsun -Dunix -D__GCC_NEW_VARARGS__ -D__sparc__ -D__sun__ -D__unix__ -D__GCC_NEW_VARARGS__ -D__sparc -D__sun -D__unix -Asystem(unix) -Asystem(bsd) -Acpu(sparc) -Amachine(sparc) -D__OPTIMIZE__ -Wall foo.c /usr/tmp/cca11611.i
GNU CPP version 2.7.2 (sparc)
#include "..." search starts here:
#include <...> search starts here:
/nfs/ishare/lib/gnu/gcc/2.7.2/sunos/include
/nfs/ishare/lib/gnu/gcc/2.7.2/sunos/sparc-sun-sunos4.1.3/include
/nfs/ishare/lib/gnu/gcc/2.7.2/sunos/lib/gcc-lib/sparc-sun-sunos4.1.3/2.7.2/include
/usr/include
End of search list.
/nfs/ishare/lib/gnu/gcc/2.7.2/sunos/lib/gcc-lib/sparc-sun-sunos4.1.3/2.7.2/cc1 /usr/tmp/cca11611.i -quiet -dumpbase foo.c -O3 -Wall -version -o foo.s
GNU C version 2.7.2 (sparc) compiled by GNU C version 2.7.2.
$
Bruno Haible email: <haible@ilog.fr>
Software Engineer phone: +33-1-49083585
Technical Details
Message-ID:
<c4803a2afa6b331a52c103315d4367d5@wretched.mailer.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113d02,9ebeb888e234b3d9,start X-Google-Attributes: gid113d02,public From: haible@ilog.fr (Bruno Haible) Subject: gcc-2.7.2 missed optimization Date: 1997/01/13 Message-ID: <c4803a2afa6b331a52c103315d4367d5@wretched.mailer.com> X-Deja-AN: 209676219 sender: bug-gcc-request@prep.ai.mit.edu x-gateway: kong.UU.NET from bug-gcc to gnu.gcc.bug; Mon, 13 Jan 1997 12:17:12 EST return-path: <gnulists-usenet-ownrr@prep.ai.mit.edu> newsgroups: gnu.gcc.bug