From 19da70e088b9cf8012cacc0c5aa7a2e1e7eb9e03 Mon Sep 17 00:00:00 2001 From: chrbr Date: Wed, 22 Aug 2007 14:38:16 +0000 Subject: [PATCH] fixed -ffinite-math-only A-A missing optimisation git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@127705 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 5 +---- gcc/simplify-rtx.c | 8 ++------ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/fold-sub.c | 12 ++++++++++++ 5 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/fold-sub.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f81021a..8845523 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2007-02-16 Christian Bruel + Richard Guenther + + * fold-const.c (fold_binary): Optimize A-A if -ffinite-math-only. + * simplify_rtx (simplify_binary_operation_1): Likewise. + 2007-08-22 Rask Ingemann Lambertsen PR rtl-optimization/32557 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 7718759..ed05f1f 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -10149,10 +10149,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) Also note that operand_equal_p is always false if an operand is volatile. */ - if ((! FLOAT_TYPE_P (type) - || (flag_unsafe_math_optimizations - && !HONOR_NANS (TYPE_MODE (type)) - && !HONOR_INFINITIES (TYPE_MODE (type)))) + if ((!FLOAT_TYPE_P (type) || !HONOR_NANS (TYPE_MODE (type))) && operand_equal_p (arg0, arg1, 0)) return fold_convert (type, integer_zero_node); diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 1acb34c..d9cf023 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -1769,14 +1769,10 @@ simplify_binary_operation_1 (enum rtx_code code, enum machine_mode mode, case MINUS: /* We can't assume x-x is 0 even with non-IEEE floating point, but since it is zero except in very strange circumstances, we - will treat it as zero with -funsafe-math-optimizations and - -ffinite-math-only. */ + will treat it as zero with -ffinite-math-only. */ if (rtx_equal_p (trueop0, trueop1) && ! side_effects_p (op0) - && (! FLOAT_MODE_P (mode) - || (flag_unsafe_math_optimizations - && !HONOR_NANS (mode) - && !HONOR_INFINITIES (mode)))) + && (!FLOAT_MODE_P (mode) || !HONOR_NANS (mode))) return CONST0_RTX (mode); /* Change subtraction from zero into negation. (0 - x) is the diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 02cc97c..6068fa9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2007-08-21 Christian Bruel + + * gcc.dg/fold-sub.c: New test. + 2007-08-22 Uros Bizjak * gcc.dg/20000724-1.c, gcc.dg/980312-1.c, gcc.dg/980313-1.c, diff --git a/gcc/testsuite/gcc.dg/fold-sub.c b/gcc/testsuite/gcc.dg/fold-sub.c new file mode 100644 index 0000000..28a8dd5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-sub.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-ffinite-math-only -fdump-tree-gimple" } */ + +float f(float x) +{ + return x - x; +} + +/* Substraction should be turned into 0. */ + +/* { dg-final { scan-tree-dump-not " - " "gimple" } } */ +/* { dg-final { cleanup-tree-dump "gimple" } } */ -- 2.7.4