🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #2525

optimizer bug

#2525
From: Eirik Fuller
Date: Tue, 11 Apr 1989 10:00
43 lines
1467 bytes
gcc 1.34 compiles the enclosed program incorrectly on a Tek 4316, when
invoked with -O.  Since the gcc configuration for the 4316 is similar
to the Sun 3 (68020/68881, m68k.md, tm-m68k.h), the same problem might
also occur on a Sun 3 configured for a 68881.

bug.c:

main()
{
  double d = 2, *p = &d;
  exit ( *p ? 0 : 1 );
}

bug.s:

#NO_APP
gcc_compiled.:
.text
	.even
.globl _main
_main:
	link a6,#-8
	movel #1073741824,a6@(-8)
	clrl a6@(-4)
	jeq L2
	clrl d0
	jra L3
L2:
	moveq #1,d0
L3:
	movel d0,sp@-
	jbsr _exit
	unlk a6
	rts

If I might venture a guess about what's going on ... the two
instructions after the link (movel,clrl) move the two halves of 2.0
into the stack frame (double d in bug.c).  Before optimization there
is an explicit compare against 0.0; after optimization the process of
moving 2.0 onto the stack is allowed to set the condition code.  It
seems reversing the order of these two instructions (clrl,movel) would
give correct code, though the conditional branch could, in principle,
be optimized out entirely in this case.
Technical Details
Message-ID: <8904111000.AA07961@elf.Stanford.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ELF.STANFORD.EDU!eirik

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ELF.STANFORD.EDU!eirik
From: eirik@ELF.STANFORD.EDU (Eirik Fuller)
Newsgroups: gnu.gcc.bug
Subject: optimizer bug
Message-ID: <8904111000.AA07961@elf.Stanford.EDU>
Date: 11 Apr 89 10:00:37 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 43