Use u16 codegen for u8 x u8 ops
In g_typeadjust, before we apply the integral promotions, we check if both types are unsigned char. If so, we promote to unsigned int, rather than int, which would be chosen by the standard rules. This is only a performance optimization and does not affect correctness, as the flags returned by g_typeadjust are only used for code generation, and not to determine types of other expressions containing this one. All unsigned char bit-patterns are valid as both int and unsigned int and represent the same value, so either signed or unsigned int operations can be used. This special case part is not duplicated by ArithmeticConvert. Partial fix for #1308.
This commit is contained in:
committed by
Oliver Schmidt
parent
81edc3f582
commit
5db74b4b19
@@ -1432,6 +1432,19 @@ unsigned g_typeadjust (unsigned lhs, unsigned rhs)
|
||||
|
||||
/* Note that this logic is largely duplicated by ArithmeticConvert. */
|
||||
|
||||
/* Before we apply the integral promotions, we check if both types are unsigned char.
|
||||
** If so, we return unsigned int, rather than int, which would be returned by the standard
|
||||
** rules. This is only a performance optimization and does not affect correctness, as
|
||||
** the flags are only used for code generation, and not to determine types of other
|
||||
** expressions containing this one. All unsigned char bit-patterns are valid as both int
|
||||
** and unsigned int and represent the same value, so either signed or unsigned int operations
|
||||
** can be used. This special case part is not duplicated by ArithmeticConvert.
|
||||
*/
|
||||
if ((lhs & CF_TYPEMASK) == CF_CHAR && (lhs & CF_UNSIGNED) &&
|
||||
(rhs & CF_TYPEMASK) == CF_CHAR && (rhs & CF_UNSIGNED)) {
|
||||
return const_flag | CF_UNSIGNED | CF_INT;
|
||||
}
|
||||
|
||||
/* Apply integral promotions for types char/short. */
|
||||
lhs = g_intpromotion (lhs);
|
||||
rhs = g_intpromotion (rhs);
|
||||
|
||||
Reference in New Issue
Block a user