Article View: gnu.gcc.bug
Article #252gcc 2.2.2 -fschedule-insns2 bug on Sparcstations (diff 1.15)
From: Lon Willett
Date: Tue, 04 Aug 1992 02:40
Date: Tue, 04 Aug 1992 02:40
113 lines
3550 bytes
3550 bytes
There is a bug in gcc 2.2.2 -fschedule-insns2 on Sparcstations which
prevents GNU diff 1.15 from compiling correctly with -O2.
Specifically, the function "diag" in file "analyze.c" ends up using a
corrupted index. What happens is that when compiled with:
gcc -O2 -fno-schedule-insns2 -c analyze.c
the code generates the instructions:
! ... calculates initial value for "bmid"; result in %l6
st %l6,[%fp-60]
ld [%fp-60],%o0
! uses %o0 as "bmid" value ...
which stores the "bmid" value in the stack frame, and then loads the
value from the stack frame into %o0. This isn't great code (a "mov
%l6,%o0" would be an improvement on the "ld"), but it is correct.
However, when compiled with "-fschedule-insns2", the "st" instruction
is moved to below the "ld" instruction, like this:
! ... calculates initial value for "bmid"; result in %l6
ld [%fp-60],%o0 ! *** Loads random garbage from stack ***
! uses %o0 as "bmid" value...
...
st %l6,[%fp-60] ! Heres where the store instr ended up
! still thinks "bmid" value is in %o0 ...
So a random value ends up being used for "bmid", resulting in core
dumps and generally bad behaviour.
The details on my configuration:
SparcStation ELC (Sun 4/25)
Sun OS 4.1.1
gcc 2.2.2
I assume the GNU diff 1.15 sources are widely enough available that I
can skip enclosing them. Sorry, but I don't have a simpler example
reproducing the bug.
More detailed (although still truncated) assembler output follows. I
did add some comments to it.
--Lon Willett willett@math.utah.edu
------------------------------------------------------------------------
! Lines starting with "<" are from: gcc -O2 -fno-schedule-insns2 -S analyze.c
! Lines starting with ">" are from: gcc -O2 -S analyze.c
gcc2_compiled.:
.text
.align 4
.proc 04
_diag:
!#PROLOGUE# 0
save %sp,-200,%sp
!#PROLOGUE# 1
mov %i0,%l3
mov %i1,%o4
mov %i2,%l4
mov %i3,%l5
st %i4,[%fp-20]
sethi %hi(_xvec),%i0
ld [%i0+%lo(_xvec)],%l6
< st %l6,[%fp-28]
sethi %hi(_yvec),%g3
ld [%g3+%lo(_yvec)],%l7
sub %l3,%l5,%o5
st %o5,[%fp-36]
< sub %o4,%l4,%l6
< st %l6,[%fp-44]
sub %l3,%l4,%o5
st %o5,[%fp-52]
ld [%fp-52],%o1
> mov 1,%l0
> st %l0,[%fp-100]
> mov 2,%o5
> st %o5,[%fp-84]
> st %l6,[%fp-28]
> sub %o4,%l4,%l6
> st %l6,[%fp-44]
< mov %o1,%o3
sub %o4,%l5,%l6
< st %l6,[%fp-60] ! Store "bmid" value (-fno-schedule-insns2)
ld [%fp-60],%o0 ! *** Loads bad %o0 ("bmid")
! Replace with "mov %l6,%o0" and the
! problem goes away.
< mov %o0,%o2
> mov %o1,%o3
sub %o1,%o0,%g2 ! *** First use of bad %o0 ("bmid")
and %g2,1,%g2
st %g2,[%fp-68]
< mov 1,%l0
< st %l0,[%fp-100]
< mov 2,%o5
< st %o5,[%fp-84]
sethi %hi(_fdiag),%g2
ld [%g2+%lo(_fdiag)],%l2
> st %l6,[%fp-60] ! *** Finally stores "bmid" value, but
! register %o0 (register "bmid") is still
! corrupted, and will be used below.
sll %o1,2,%g2
st %l3,[%l2+%g2]
sethi %hi(_bdiag),%g2
ld [%g2+%lo(_bdiag)],%l1
> mov %o0,%o2
sll %o0,2,%g2
st %o4,[%l1+%g2]
L2:
...
------------------------------------------------------------------------
Technical Details
Message-ID:
<9208040240.AA15094@holly>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!softt.UUCP!lonShow Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!softt.UUCP!lon From: lon@softt.UUCP (Lon Willett) Subject: gcc 2.2.2 -fschedule-insns2 bug on Sparcstations (diff 1.15) Message-ID: <9208040240.AA15094@holly> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Tue, 4 Aug 1992 02:40:24 GMT Approved: bug-gcc@prep.ai.mit.edu Lines: 114