🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1538

GCC 2.3.2: Bug in combiner

#1538
From: Andreas Schwab
Date: Mon, 14 Dec 1992 11:47
63 lines
2016 bytes
GCC 2.3.2 (m68k, Atari TT) generates wrong code for this function:

-------------------- x.c
struct rect { short x, y, w, h; };

f (struct rect r)
{
  short x[4];
  x[0] = r.x;
  x[1] = r.y;
  x[2] = r.x + r.w - 1;
  x[3] = r.y + r.h - 1;
  g (x);
}
--------------------

when compiled with: gcc -S -O2 x.c

-------------------- x.s
#NO_APP
gcc2_compiled.:
.text
	.even
.globl _f
_f:
	link a6,#-8
	movel d2,sp@-
	movel a6@(8),d1
	movel a6@(12),d2
	bfexts d1{#0:#16},d0
	movew d0,a6@(-8)
	movew d1,a6@(-6)
	addw d2,d0		| <-- d2 should be upper half of d2
	subqw #1,d0
	movew d0,a6@(-4)
	addw d2,d1
	subqw #1,d1
	movew d1,a6@(-2)
	pea a6@(-8)
	jbsr _g
	movel a6@(-12),d2
	unlk a6
	rts
--------------------

I guess that the bug is in combine.c:num_sign_bit_copies near line 6454:

--------------------
  /* If we haven't been able to figure it out by one of the above rules,
     see if some of the high-order bits are known to be zero.  If so,
     count those bits and return one less than that amount.  If we can't
     safely compute the mask for this mode, always return BITWIDTH.  */

  if (bitwidth > HOST_BITS_PER_WIDE_INT)
    return bitwidth;
--------------------

This seems wrong. If the number of sign bit copies cannot be computed,
the value for the worst case should be returned, which is 1.
If this is changed, the above example compiles correctly.
--
Andreas Schwab
schwab@ls5.informatik.uni-dortmund.de
Technical Details
Message-ID: <9212140947.AA07658@lamothe.informatik.uni-dortmund.de>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!lamothe.informatik.uni-dortmund.de!schwab

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!lamothe.informatik.uni-dortmund.de!schwab
From: schwab@lamothe.informatik.uni-dortmund.de (Andreas Schwab)
Subject: GCC 2.3.2: Bug in combiner
Message-ID: <9212140947.AA07658@lamothe.informatik.uni-dortmund.de>
Sender: gnulists@ai.mit.edu
Reply-To: schwab@ls5.informatik.uni-dortmund.de (Andreas Schwab)
Organization: GNUs Not Usenet
Distribution: gnu
Date: Mon, 14 Dec 1992 11:47:25 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 64