This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fix wrong-code bug caused by combine_simplify_rtx()
- From: Richard Sandiford <rsandifo at redhat dot com>
- To: Paul Schlie <schlie at comcast dot net>
- Cc: <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 08 Apr 2005 18:21:03 +0100
- Subject: Re: Fix wrong-code bug caused by combine_simplify_rtx()
- References: <BE7C3424.9BFF%schlie@comcast.net>
Paul Schlie <schlie@comcast.net> writes:
>> From: Richard Sandiford <rsandifo@redhat.com>
>> Paul Schlie <schlie@comcast.net> writes:
>>>> Anyway, combine misoptimises:
>>>>
>>>> int s;
>>>> ...
>>>> (signed char) (s - 100) - 5
>>>>
>>>> rewriting it into:
>>>>
>>>> (plus:SI (sign_extend:SI (subreg:QI (reg:SI s) 0))
>>>> (const_int -105))
>>>
>>> The following would have been optimally correct:
>>>
>>> (sign_ext:QI (plus:QI (subreg:QI (reg:SI s) 0)
>>> (const_int -105)))
>>
>> No, it's not correct. Consider s == -28:
>>
>> (signed char) (s - 100) - 5 == (signed char) -128 - 5 == -133
>>
>> Your version would give 123.
>
> Yup, which is correct, that's what (signed char)(-133)
No it's not. The result is not being cast to "signed char".
It's an "int".
Remember the usual integer promotions apply. I.e. "(signed char) -128"
is promoted to "int", 5 has type "int", and the result of the "-" is also
an "int".
Richard