This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix wrong-code bug caused by combine_simplify_rtx()


> 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) is equivalent to:

     -28 =   1110,0100
    -100 =   1001,1100
      -5 =   1111,1011
    -------------------
     123 =   0111,1011
(as -133 = 1,0111,1011)




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]