Chris Lattner wrote:
> On Dec 17, 2006, at 12:40 PM, Rask Engelmann Lamberts wrote:
>> I seem unable to get a QImode shift instruction from this code:
>>
>> unsigned char x;
>>
>> void qishifttest2 (unsigned int c)
>> {
>>    x <<= c;
>> }
>> 
>> should have been generated. Also, notice the redundant zero extension.
>> Why are we not generating a QImode shift instruction?
>
> Consider when c = 16. With the (required) integer promotion, the result
> is defined (the result is zero). If converted to QImode, the shift would
> be undefined, because the (dynamic) shift amount would be larger than the
> data type.

??? A left shift >= the precision of its shifted unsigned operand can only
logically result in a value of 0 regardless of its potential promotion.

Although integer promotion as specified by C may technically be performed
lazily as a function of the implicit target precision required for a given
operation, GCC tends to initially promote everything and then attempt to
determine if an operation's precision may be subsequently lowered after
having already lost critical knowledge of its originally specified operand's
precision.

Thereby although many operands tend to remain unnecessarily promoted, this
is often benign for larger machines with int or larger sized registers
(being the focus of GCC development efforts) as char -> int promotion is
effectively free; although potentially very expensive for smaller machines
(which tend receive less development attention).


Reply via email to