Bug 4620 - Wrong code generated with -O2 for sparc-sun-solaris2.5.1
Summary: Wrong code generated with -O2 for sparc-sun-solaris2.5.1
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: wrong-code
Depends on:
Reported: 2001-10-19 09:36 UTC by christophe.guillon
Modified: 2005-06-05 09:52 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:

gcc-bug1.i (196 bytes, text/x-c)
2003-05-21 15:17 UTC, christophe.guillon

Note You need to log in before you can comment on or make changes to this bug.
Description christophe.guillon 2001-10-19 09:36:02 UTC
GCC generates wrong assembly code with -O2 option on the
file gcc-bug1.i
with -O1 option the code is correct.

Regarding the assembly output, it seems that the an store is 
scheduled above an overlaping load.

The output should be :
$ ./a.out
Should print 1: 1
It is
$ ./a.out
Should print 1: 0

gcc version 3.0  sparc-sun-solaris2.5.1

$ uname -a
SunOS gnx1635 5.5.1 Generic_103640-34 sun4u sparc
$gcc -v
Reading specs from /apa/gnu/SunOS5/gcc/gcc-3.0/bin/../lib/gcc-lib/sparc-sun-solaris2.5.1/3.0/specs
Configured with: ./configure --prefix=/apa/gnu/SunOS5/.package/gcc-3.0 --x-includes=/usr/openwin/include --x-libraries=/usr/openwin/lib --with-local-prefix=/apa/gnu/SunOS5
Thread model: posix
gcc version 3.0
 /apa/gnu/SunOS5/gcc/gcc-3.0/bin/../lib/gcc-lib/sparc-sun-solaris2.5.1/3.0/cpp0 -lang-c -v -iprefix /apa/gnu/SunOS5/gcc/gcc-3.0/bin/../lib/gcc-lib/sparc-sun-solaris2.5.1/3.0/ -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=0 -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem=unix -Asystem=svr4 -D__OPTIMIZE__ -D__STDC_HOSTED__=1 -Wall -D__GCC_NEW_VARARGS__ -Acpu=sparc -Amachine=sparc gcc-bug1.c gcc-bug1.i
GNU CPP version 3.0 (cpplib) (sparc)
ignoring nonexistent directory "/apa/gnu/SunOS5/gcc/gcc-3.0/sparc-sun-solaris2.5.1/include"
ignoring nonexistent directory "/apa/gnu/SunOS5/.package/gcc-3.0/sparc-sun-solaris2.5.1/include"
ignoring duplicate directory "/apa/gnu/SunOS5/.package/gcc-3.0/lib/gcc-lib/sparc-sun-solaris2.5.1/3.0/include"
#include "..." search starts here:
#include <...> search starts here:
End of search list.
 /apa/gnu/SunOS5/gcc/gcc-3.0/bin/../lib/gcc-lib/sparc-sun-solaris2.5.1/3.0/cc1 -fpreprocessed gcc-bug1.i -quiet -dumpbase gcc-bug1.c -O2 -Wall -version -o gcc-bug1.s
GNU CPP version 3.0 (cpplib) (sparc)
GNU C version 3.0 (sparc-sun-solaris2.5.1)
        compiled by GNU C version egcs-2.91.60 19981201 (egcs-1.1.1 release).
 /usr/ccs/bin/as -V -Qy -s -o gcc-bug1.o gcc-bug1.s
/usr/ccs/bin/as: WorkShop Compilers 4.2 dev 13 May 1996
ld: Software Generation Utilities - Solaris/ELF (3.0)

$ /apa/gnu/SunOS5/gcc/gcc-3.0/bin/gcc -Wall -O2 gcc-bug1.i
$ ./a.out
Should print 1: 0
Comment 1 christophe.guillon 2001-10-19 09:36:02 UTC
Stephane Carrez, 2001-11-28 (just log some analysis):
It seems to be a mem aliasing problem.

During sched pass, the following insn:

(insn 14 54 52 (set (mem/f:DI (plus:SI (reg/f:SI 30 %fp)
                (const_int -24 [0xffffffe8])) 1)
        (reg:DI 10 %o2 [111])) 58 {*movdi_insn_sp32} (insn_list 13 (nil))
    (expr_list:REG_DEAD (reg:DI 10 %o2 [111])

is moved after:

(insn 54 64 14 (set (reg:SI 9 %o1)
        (mem:SI (plus:SI (reg/f:SI 30 %fp)
                (const_int -20 [0xffffffec])) 2)) 51 {*movsi_insn} (insn_list:REG_DEP_OUTPUT 65 (insn_list 23 (nil)))

because no dependency was found.  No dependency is found
because the two MEMs are in two different alias sets (1 and
2).  They should be in the same set (MEM of insn 14 is
a super set of MEM of insn 54).
Comment 2 Stephane Carrez 2001-11-28 05:37:18 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: confirmed as a bug (3.0.2 and 3.1)
Comment 3 Stephane Carrez 2001-11-28 13:37:19 UTC
From: ciceron@gcc.gnu.org
To: christophe.guillon@st.com, gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org,
  gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org
Subject: Re: optimization/4620: Wrong code generated with -O2 for sparc-sun-solaris2.5.1
Date: 28 Nov 2001 13:37:19 -0000

 Synopsis: Wrong code generated with -O2 for sparc-sun-solaris2.5.1
 State-Changed-From-To: open->analyzed
 State-Changed-By: ciceron
 State-Changed-When: Wed Nov 28 05:37:18 2001
     confirmed as a bug (3.0.2 and 3.1)
Comment 4 Richard Henderson 2002-04-03 00:41:49 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Not a bug.
      long long lll;
      unsigned *p;
      p = (unsigned *)&lll;
    This code violates ISO C aliasing rules (6.5/7).
    With GCC, one can use a union for this, though
    you should note that even that isn't portable.
Comment 5 Andrew Pinski 2005-06-05 09:50:29 UTC
Reopening to ...
Comment 6 Andrew Pinski 2005-06-05 09:52:19 UTC
Mark as a dup of bug 21920.

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