🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by James Clark Wed, 08 Apr 1992 11:23
optimization bug
#251
Author: James Clark
Date: Wed, 08 Apr 1992 11:23
28 lines
1342 bytes
gcc 2.1 misoptimizes the following program:

$ cat bug.c

main()
{
  signed char c = -1;
  printf("%d\n", c < 0);
  exit(0);
}
$ gcc -v -O bug.c
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.1/specs
gcc version 2.1
 /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.1/cpp -lang-c -v -undef -D__GNUC__=2 -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -D__OPTIMIZE__ bug.c /usr/tmp/cca28545.i
GNU CPP version 2.1 (sparc)
 /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.1/cc1 /usr/tmp/cca28545.i -quiet -dumpbase bug.c -O -version -o /usr/tmp/cca28545.s
GNU C version 2.1 (sparc) compiled by GNU C version 2.0.
 /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.1/as -o bug.o /usr/tmp/cca28545.s
 /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.1/ld -e start -dc -dp /lib/crt0.o -L/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.1/ -L/usr/local/lib/ bug.o -lgcc -lc -lgcc
$ ./a.out
0
$ gcc bug.c
$ ./a.out
1
$ 

James Clark
jjc@jclark.com
FIX FOR: optimization bug
#356
Author: Chip Salzenberg
Date: Fri, 10 Apr 1992 13:31
51 lines
2171 bytes
A bug report from James Clark <jjc@jclark.com> reports that GCC 2.1
misoptimizes this program:
	main()
	{
	  signed char c = -1;
	  printf("%d\n", c < 0);
	  exit(0);
	}
It prints zero instead of one.

I've found this bug.  The optimizer is noting that "c" equals 0xFF,
but it is forgetting that 0xFF is a _byte_ value (QImode).  So when
the optimizer SIGN_EXTENDs that constant, the constant looks like it
has already been extended.  This bug results in a wrong value of 255
(which is, of course, not less than zero) instead of the correct -1.

The below patch makes GCC generate and retain the correct machine
modes for constants.

----------------------------------------------------------------------------

Thu Apr  9 17:22:19 1992  Chip Salzenberg  (chip at tct.com)

	* emit-rtl.c (gen_rtx): Generate CONST_INT with requested MODE.
	  (gen_lowpart_common): Ditto.

Index: emit-rtl.c
*************** gen_rtx (va_alist)
*** 257,260 ****
--- 257,261 ----
  
        rt_val = rtx_alloc (code);
+       rt_val->mode = mode;
        INTVAL (rt_val) = arg;
      }
*************** gen_lowpart_common (mode, x)
*** 533,537 ****
  	    : (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_INT
  	       && GET_CODE (x) == CONST_INT) ? x
! 	    : gen_rtx (CONST_INT, VOIDmode,
  		       (GET_MODE_MASK (mode)
  			& (GET_CODE (x) == CONST_INT
--- 534,538 ----
  	    : (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_INT
  	       && GET_CODE (x) == CONST_INT) ? x
! 	    : gen_rtx (CONST_INT, mode,
  		       (GET_MODE_MASK (mode)
  			& (GET_CODE (x) == CONST_INT
-- 
Chip Salzenberg at Teltronics/TCT  <chip@tct.com>, <73717.366@compuserve.com>
      "Informix 4GL is not a 4G, and it's barely an L."  -- John Tombs
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads