Commit 960f80d1 by Richard Guenther Committed by Richard Biener

re PR middle-end/27116 (Incorrect integer division (wrong sign).)

2006-06-08  Richard Guenther  <rguenther@suse.de>

	PR middle-end/27116
	* fold-const.c (negate_expr_p): We can negate BIT_NOT_EXPR
	only, if overflow is defined and not trapping.
	(negate_expr): Likewise.

	* gcc.dg/torture/pr27116.c: New testcase.
	* gcc.dg/pr15785-1.c: Remove test for invalid transformation.

From-SVN: r114483
parent 8e08deeb
2006-06-08 Richard Guenther <rguenther@suse.de>
PR middle-end/27116
* fold-const.c (negate_expr_p): We can negate BIT_NOT_EXPR
only, if overflow is defined and not trapping.
(negate_expr): Likewise.
2006-06-07 Zdenek Dvorak <dvorakz@suse.cz>
PR tree-optimization/27872
......
......@@ -945,7 +945,9 @@ negate_expr_p (tree t)
/* Check that -CST will not overflow type. */
return may_negate_without_overflow_p (t);
case BIT_NOT_EXPR:
return INTEGRAL_TYPE_P (type);
return INTEGRAL_TYPE_P (type)
&& (TYPE_UNSIGNED (type)
|| (flag_wrapv && !flag_trapv));
case REAL_CST:
case NEGATE_EXPR:
......@@ -1047,7 +1049,9 @@ negate_expr (tree t)
{
/* Convert - (~A) to A + 1. */
case BIT_NOT_EXPR:
if (INTEGRAL_TYPE_P (type))
if (INTEGRAL_TYPE_P (type)
&& (TYPE_UNSIGNED (type)
|| (flag_wrapv && !flag_trapv)))
return fold_build2 (PLUS_EXPR, type, TREE_OPERAND (t, 0),
build_int_cst (type, 1));
break;
......
2006-06-08 Richard Guenther <rguenther@suse.de>
PR middle-end/27116
* gcc.dg/torture/pr27116.c: New testcase.
* gcc.dg/pr15785-1.c: Remove test for invalid transformation.
2006-06-07 Zdenek Dvorak <dvorakz@suse.cz>
PR rtl-optimization/26449
......@@ -11,11 +11,6 @@ void b (int x) {
link_error ();
}
void c (int x) {
if (!(- (~x) - x))
link_error ();
}
void d (int x) {
if (!(~ (-x) - x))
link_error ();
......@@ -34,7 +29,6 @@ void f (int x) {
int main (int argc, char *argv[]) {
a(argc);
b(argc);
c(argc);
d(argc);
e(argc);
f(argc);
......
/* { dg-do run } */
extern void abort(void);
int f(int a, int b)
{
return (-1 - a) / (-b);
}
int main()
{
if (f(__INT_MAX__, 2) != __INT_MAX__/2 + 1)
abort ();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment