Hello,
On Mon, 8 Apr 2013, Laurent Alfonsi wrote:
I have identified a big performance regression between 4.6 and 4.7. (I have
enclosed a pathological test).
After investigation, it is because of the += statement applied on 2 signed
chars.
- It is now type-promoted to "int" when it is written "result += foo()".
(since 4.7)
- it is type promoted to "unsigned char" when it is written "result =
result + foo()".
The "char->int->char" cast is blocking some optimizations in later phases.
Which ones?
Anyway, this doesn't look wrong, so I extended fold optimization in order to
catch this case. (patch enclosed)
The patch basically transforms :
(TypeA) ( (TypeB) a1 + (TypeB) a2 ) /* with a1 and a2 of
the signed type TypeA */
into :
a1 + a2
I believe this is legal for any licit a1/a2 input values (no overflow on
signed char).
I don't think this is ok, please refer to the discussion around the
PR and patch that added this conversion, it was done on purpose.
According to this (4th item)
http://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html
char a=100;
a+=a;
is perfectly defined and a is -56 (assuming a signed 8 bit char and a
strictly larger int). However, your transformation turns it into undefined
behavior: an addition that overflows in a type with
TYPE_OVERFLOW_UNDEFINED.
--
Marc Glisse