This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Have fold convert -a/-b to a/b for signed types


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
--


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]