[Bug rtl-optimization/66248] subreg truncation not hoisted from loop

2025-01-06 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66248 Andrew Pinski changed: What|Removed |Added Status|UNCONFIRMED |NEW Target|arm, mips, sparc

[Bug rtl-optimization/66248] subreg truncation not hoisted from loop

2015-12-15 Thread pinskia at gcc dot gnu.org
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

[Bug rtl-optimization/66248] subreg truncation not hoisted from loop

2015-12-15 Thread sje at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66248 Steve Ellcey changed: What|Removed |Added Status|RESOLVED|UNCONFIRMED Resolution|INVALID

[Bug rtl-optimization/66248] subreg truncation not hoisted from loop

2015-12-15 Thread jon at beniston dot com
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.

[Bug rtl-optimization/66248] subreg truncation not hoisted from loop

2015-12-15 Thread sje at gcc dot gnu.org
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

[Bug rtl-optimization/66248] subreg truncation not hoisted from loop

2015-12-15 Thread jon at beniston dot com
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

[Bug rtl-optimization/66248] subreg truncation not hoisted from loop

2015-12-15 Thread sje at gcc dot gnu.org
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

[Bug rtl-optimization/66248] subreg truncation not hoisted from loop

2015-12-15 Thread jon at beniston dot com
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

[Bug rtl-optimization/66248] subreg truncation not hoisted from loop

2015-12-14 Thread sje at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66248 Steve Ellcey changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED CC|