aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRoger Sayle <roger@eyesopen.com>2004-07-11 21:56:37 +0000
committerRoger Sayle <sayle@gcc.gnu.org>2004-07-11 21:56:37 +0000
commitdf23e6bbfaa8254963aa5254a851c942f3c8b594 (patch)
treeacc595c4c6c4e009a369389090739103f3b7a6c8 /gcc
parentabd1b60de7c2ce3fc9a2d8b56c28df7639e3735a (diff)
downloadgcc-df23e6bbfaa8254963aa5254a851c942f3c8b594.zip
gcc-df23e6bbfaa8254963aa5254a851c942f3c8b594.tar.gz
gcc-df23e6bbfaa8254963aa5254a851c942f3c8b594.tar.bz2
fold-const.c (fold): Canonicalize X + -C as X - C for floating point additions...
* fold-const.c (fold) <PLUS_EXPR>: Canonicalize X + -C as X - C for floating point additions, to keep real immediate constant positive. <MINUS_EXPR>: For floating point subtractions, only transform X - -C into X + C, and leave positive real constants as X - C. From-SVN: r84535
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/fold-const.c16
2 files changed, 22 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 77123a0..89ff347 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2004-07-11 Roger Sayle <roger@eyesopen.com>
+
+ * fold-const.c (fold) <PLUS_EXPR>: Canonicalize X + -C as X - C for
+ floating point additions, to keep real immediate constant positive.
+ <MINUS_EXPR>: For floating point subtractions, only transform X - -C
+ into X + C, and leave positive real constants as X - C.
+
2004-07-11 John David Anglin <dave.anglin@nrc-cnrc.gc.ca>
* pa.c (hppa_gimplify_va_arg_expr): Remove comment.
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index f1927f2..bc1e877 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -6589,6 +6589,17 @@ fold (tree expr)
if (fold_real_zero_addition_p (TREE_TYPE (arg1), arg0, 0))
return non_lvalue (fold_convert (type, arg1));
+ /* Convert X + -C into X - C. */
+ if (TREE_CODE (arg1) == REAL_CST
+ && REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg1)))
+ {
+ tem = fold_negate_const (arg1, type);
+ if (!TREE_OVERFLOW (arg1) || !flag_trapping_math)
+ return fold (build2 (MINUS_EXPR, type,
+ fold_convert (type, arg0),
+ fold_convert (type, tem)));
+ }
+
/* Convert x+x into x*2.0. */
if (operand_equal_p (arg0, arg1, 0)
&& SCALAR_FLOAT_TYPE_P (type))
@@ -6921,7 +6932,10 @@ fold (tree expr)
/* A - B -> A + (-B) if B is easily negatable. */
if (!wins && negate_expr_p (arg1)
- && (FLOAT_TYPE_P (type)
+ && ((FLOAT_TYPE_P (type)
+ /* Avoid this transformation if B is a positive REAL_CST. */
+ && (TREE_CODE (arg1) != REAL_CST
+ || REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg1))))
|| (INTEGRAL_TYPE_P (type) && flag_wrapv && !flag_trapv)))
return fold (build2 (PLUS_EXPR, type, arg0, negate_expr (arg1)));