diff options
author | uros <uros@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-03-25 17:32:34 +0000 |
---|---|---|
committer | uros <uros@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-03-25 17:32:34 +0000 |
commit | c2c965913f11f7a2a85aff51f95818fa8a084ec3 (patch) | |
tree | 48e974648a8fcb1e216b90855fef2c32b4a4f150 | |
parent | 0a3cb44dceffbf167bf69bf95d499e5a3ece6cc4 (diff) | |
download | gcc-c2c965913f11f7a2a85aff51f95818fa8a084ec3.tar.gz |
PR middle-end/26717
* fold-const.c (fold_binary) [RDIV_EXPR]: Do not optimize A / A
to 1.0 for non-real operands. Implement A / A optimization for
complex operands.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@112379 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/fold-const.c | 20 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr26717.c | 7 |
4 files changed, 38 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f1f4982daa3..acaf8b6e4b8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2006-03-25 Uros Bizjak <uros@kss-loka.si> + Roger Sayle <roger@eyesopen.com> + + PR middle-end/26717 + * fold-const.c (fold_binary) [RDIV_EXPR]: Do not optimize A / A + to 1.0 for non-real operands. Implement A / A optimization for + complex operands. + 2006-03-25 H.J. Lu <hongjiu.lu@intel.com> * config/i386/i386.c (size_cost): Correct the comment for diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 4e05368fe2b..9ea3232d4f7 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8902,8 +8902,10 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) return NULL_TREE; /* Optimize A / A to 1.0 if we don't care about - NaNs or Infinities. */ - if (! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0))) + NaNs or Infinities. Skip the transformation + for non-real operands. */ + if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (arg0)) + && ! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0))) && ! HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg0))) && operand_equal_p (arg0, arg1, 0)) { @@ -8912,6 +8914,20 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) return omit_two_operands (type, r, arg0, arg1); } + /* The complex version of the above A / A optimization. */ + if (COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0)) + && operand_equal_p (arg0, arg1, 0)) + { + tree elem_type = TREE_TYPE (TREE_TYPE (arg0)); + if (! HONOR_NANS (TYPE_MODE (elem_type)) + && ! HONOR_INFINITIES (TYPE_MODE (elem_type))) + { + tree r = build_real (elem_type, dconst1); + /* omit_two_operands will call fold_convert for us. */ + return omit_two_operands (type, r, arg0, arg1); + } + } + /* (-A) / (-B) -> A / B */ if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1)) return fold_build2 (RDIV_EXPR, type, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ce46847eb1a..f9c591cd2b9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-03-25 Uros Bizjak <uros@kss-loka.si> + + PR middle-end/26717 + * gcc.dg/pr26717.c: New test. + 2006-03-25 Roger Sayle <roger@eyesopen.com> * gfortran.dg/dependency_12.f90: New test case. diff --git a/gcc/testsuite/gcc.dg/pr26717.c b/gcc/testsuite/gcc.dg/pr26717.c new file mode 100644 index 00000000000..d16b576ed24 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr26717.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O -ffast-math" } */ +_Complex float f (_Complex float a) +{ + _Complex float b = a / a; + return b; +} |