This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
fold-const.c extract_muldiv bug fix
- To: gcc-patches at gcc dot gnu dot org
- Subject: fold-const.c extract_muldiv bug fix
- From: Jim Wilson <wilson at cygnus dot com>
- Date: Wed, 03 May 2000 13:05:45 -0700
This fixes another extract_muldiv bug. Gcc is failing for the following
testcase for targets where sizetype is a larger type than int. This was
reported to me against the ia64 compiler, but it also shows up with the alpha
compiler.
Gcc is converting
signed max (a, b) * unsigned c
to
unsigned max (a * c, b * c)
which is wrong, as signed max and unsigned max give different results.
I checked in this testcase as gcc.c-torture/execute/20000503-1.c.
unsigned long
sub (int a)
{
return ((0 > a - 2) ? 0 : a - 2) * sizeof (long);
}
main ()
{
if (sub1 (0) != 0)
abort ();
exit (0);
}
Wed May 3 12:55:46 2000 Jim Wilson <wilson@cygnus.com>
* fold-const.c (extract_muldiv, case MAX_EXPR): Don't allow signedness
change.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fold-const.c,v
retrieving revision 1.115
diff -p -r1.115 fold-const.c
*** fold-const.c 2000/04/17 00:54:25 1.115
--- fold-const.c 2000/05/03 19:55:20
*************** extract_muldiv (t, c, code, wide_type)
*** 4402,4407 ****
--- 4402,4412 ----
break;
case MIN_EXPR: case MAX_EXPR:
+ /* If widening the type changes the signedness, then we can't perform
+ this optimization as that changes the result. */
+ if (ctype != type && TREE_UNSIGNED (ctype) != TREE_UNSIGNED (type))
+ break;
+
/* MIN (a, b) / 5 -> MIN (a / 5, b / 5) */
if ((t1 = extract_muldiv (op0, c, code, wide_type)) != 0
&& (t2 = extract_muldiv (op1, c, code, wide_type)) != 0)