Abusive (?) promotions to int

Mike Stump mrs@apple.com
Wed Sep 24 19:31:00 GMT 2003


On Wednesday, September 24, 2003, at 03:15 AM, Andreas Schwab wrote:
>> I've been looking for macros to control integer promotions, 
>> especially for
>> temporary statements. Consider for instance the following code:
>>
>>     char c;
>>     ...
>>     if (c + 4 > 10) ...
>>
>> On my target, c gets zero_extended to int, then the addition and 
>> comparison
>> are performed in SImode, while it is not really necessary (could be 
>> done in
>> QImode as well and would save the zero_extend).
>
> No, it cannot.  You would get wrong behaviour if c >= 252 (assuming 
> char
> is unsigned 8 bit), because (char)(c + 4) < 10, but c + 4 > 10.

?  But, while we can envision bad code gen, can't we also envision good 
sequences as well:

cond = c + 4 > 10;
cond = ((int)c + 4) > 10;
cond = ((int)c) > 6);
cond = ((char)c) > (char)6);

or is there something I'm missing?  When the compiler is used on small 
machines, this type of optimization, if possible, is useful.



More information about the Gcc mailing list