From: Marc Glisse Date: Wed, 20 Mar 2013 15:16:09 +0000 (+0100) Subject: re PR tree-optimization/56355 (abs and multiplication) X-Git-Tag: upstream/12.2.0~70781 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1fc5eced1bd73eef1975f803279b799f4b47c879;p=platform%2Fupstream%2Fgcc.git re PR tree-optimization/56355 (abs and multiplication) 2013-03-20 Marc Glisse PR tree-optimization/56355 gcc/ * fold-const.c (tree_binary_nonnegative_warnv_p) : Also handle integers with undefined overflow. gcc/testsuite/ * gcc.dg/pr56355-1.c: New file. From-SVN: r196829 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9873aca..1f4bb6d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2013-03-20 Marc Glisse + + PR tree-optimization/56355 + * fold-const.c (tree_binary_nonnegative_warnv_p) : + Also handle integers with undefined overflow. + 2013-03-20 Catherine Moore Maciej W. Rozycki Tom de Vries diff --git a/gcc/fold-const.c b/gcc/fold-const.c index de7117e..ae03938 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -15294,15 +15294,18 @@ tree_binary_nonnegative_warnv_p (enum tree_code code, tree type, tree op0, break; case MULT_EXPR: - if (FLOAT_TYPE_P (type)) + if (FLOAT_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type)) { - /* x * x for floating point x is always non-negative. */ - if (operand_equal_p (op0, op1, 0)) - return true; - return (tree_expr_nonnegative_warnv_p (op0, - strict_overflow_p) - && tree_expr_nonnegative_warnv_p (op1, - strict_overflow_p)); + /* x * x is always non-negative for floating point x + or without overflow. */ + if (operand_equal_p (op0, op1, 0) + || (tree_expr_nonnegative_warnv_p (op0, strict_overflow_p) + && tree_expr_nonnegative_warnv_p (op1, strict_overflow_p))) + { + if (TYPE_OVERFLOW_UNDEFINED (type)) + *strict_overflow_p = true; + return true; + } } /* zero_extend(x) * zero_extend(y) is non-negative if x and y are diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a3f78a7..ef7bdd6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-03-20 Marc Glisse + + PR tree-optimization/56355 + * gcc.dg/pr56355-1.c: New file. + 2013-03-20 Catherine Moore Richard Sandiford diff --git a/gcc/testsuite/gcc.dg/pr56355-1.c b/gcc/testsuite/gcc.dg/pr56355-1.c new file mode 100644 index 0000000..08b9c2e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr56355-1.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wstrict-overflow=4" } */ + +int +f (int i) +{ + return __builtin_abs (i * i); /* { dg-warning "assuming signed overflow" } */ +}