[PATCH] Have fold convert -a/-b to a/b for signed types
Roger Sayle
roger@eyesopen.com
Sat Nov 26 21:31:00 GMT 2005
On Sat, 26 Nov 2005, Andrew Pinski wrote:
> * fold-const.c (fold_binary): Convert -A/-B to A/B for signed types
> when overflow is undefined.
>
> * gcc.dg/tree-ssa/divide-1.c: New test.
> * gcc.dg/tree-ssa/divide-2.c: New test.
This is OK for mainline.
Be warned that this optimization has the potential of turning a silent
overflow into a core dump on some targets, as not all undefined overflows
are created equal.
For example, the following test program:
int foo(int x, int y, int z)
{
return -x/(y-z);
}
int main()
{
printf("%d\n", foo(0x80000000,3,2));
return 0;
}
will print out the value -2147483648 on x86 before your patch, but
will core dump with a "floating point exception" afterwards. This
isn't strictly a regression, as the program invokes "undefined"
behaviour (which can be worked around with -fwrapv), but worth
bearing in mind should anyone report related problems in bugzilla.
Roger
--
More information about the Gcc-patches
mailing list