Article View: gnu.gcc.bug
Article #356FIX FOR: optimization bug
From: Chip Salzenberg
Date: Fri, 10 Apr 1992 13:31
Date: Fri, 10 Apr 1992 13:31
51 lines
2171 bytes
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
Technical Details
Message-ID:
<m0lZLh1-0006weC@tct.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!tct.COM!chipReferences:
<9204081123.AA28568@jclark.com>Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!tct.COM!chip From: chip@tct.COM (Chip Salzenberg) Subject: FIX FOR: optimization bug Message-ID: <m0lZLh1-0006weC@tct.com> Sender: gnulists@ai.mit.edu Organization: TC Telemanagement, Clearwater, FL References: <9204081123.AA28568@jclark.com> Distribution: gnu Date: Fri, 10 Apr 1992 13:31:00 GMT Approved: bug-gcc@prep.ai.mit.edu Lines: 52