https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66248
Andrew Pinski changed:
What|Removed |Added
Status|UNCONFIRMED |NEW
Target|arm, mips, sparc
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66248
--- Comment #8 from Andrew Pinski ---
Couldn't it be optimized as:
short func(short *a, int y)
{
short ret = 0;
unsigned int tmp = 0;
int i;
for(i = 0; i < y; i++)
tmp += (unsigned int)(int)a[i];
return (short)tmp;
}
Such that the addi
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66248
Steve Ellcey changed:
What|Removed |Added
Status|RESOLVED|UNCONFIRMED
Resolution|INVALID
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66248
--- Comment #6 from Jon Beniston ---
-fstrict-overflow (which is the default at -O2) tells us that we can assume it
will not overflow.
Even if it did, on most targets it makes no difference to the result.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66248
--- Comment #5 from Steve Ellcey ---
If we did not truncate ret on each loop iteration then ret could get large
enough to overflow the maximum integer value before we truncate it at the end,
leading to undefined results. But if we truncate ret o
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66248
--- Comment #4 from Jon Beniston ---
Well if it is just truncating the higher bits, why can't it be done at the end
of the loop?
What do you think will be different if it is done at the end of the loop? Can
you think of an example where the valu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66248
--- Comment #3 from Steve Ellcey ---
My understanding (I don't have a C/C++ standard handy) is that the addition
done by 'ret + a[i]' is done in integer mode (not as short). This results in
an integer value that may be outside the range of a sho
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66248
--- Comment #2 from Jon Beniston ---
Hi Steve. I'm not sure I'm follow your explanation.
As I understand it, signed overflow is undefined behaviour
(http://www.airs.com/blog/archives/120), so I'm not sure why we need to worry
about changing the
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66248
Steve Ellcey changed:
What|Removed |Added
Status|UNCONFIRMED |RESOLVED
CC|