From c72f711f8aa995eef830a3189fd0ca65c663544e Mon Sep 17 00:00:00 2001 From: Andrew Pinski Date: Mon, 25 Jul 2005 20:23:50 +0000 Subject: [PATCH] tree-ssa-reassoc.c (reassociate_expr): Allow scaler floating point types when flag_unsafe_math_optimizations is true. 2005-07-25 Andrew Pinski * tree-ssa-reassoc.c (reassociate_expr): Allow scaler floating point types when flag_unsafe_math_optimizations is true. 2005-07-25 Andrew Pinski * gcc.dg/tree-ssa/reassoc-3.c: New test. * gcc.dg/tree-ssa/reassoc-4.c: New test. From-SVN: r102368 --- gcc/ChangeLog | 5 +++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/tree-ssa/reassoc-3.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/reassoc-4.c | 18 ++++++++++++++++++ gcc/tree-ssa-reassoc.c | 11 +++++++---- 5 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-3.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-4.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7d8d6f77845..22171428681 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2005-07-25 Andrew Pinski + + * tree-ssa-reassoc.c (reassociate_expr): Allow scaler floating point + types when flag_unsafe_math_optimizations is true. + 2005-07-25 Mark Mitchell * gcc.c (option_map): Add --sysroot. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index affa4b6933a..bcdb54cf70e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-07-25 Andrew Pinski + + * gcc.dg/tree-ssa/reassoc-3.c: New test. + * gcc.dg/tree-ssa/reassoc-4.c: New test. + 2005-07-25 Adam Nemet * lib/profopt.exp (profopt-execute): Check for profiling data diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-3.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-3.c new file mode 100644 index 00000000000..3800497e900 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-3.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -ffast-math" } */ +float a, b, c, d; +extern int printf (const char *, ...); +int main(void) +{ + float e; + float f; + /* We should be able to transform these into the same expression, and only have two additions. */ + e = a + b; + e = e + c; + f = c + a; + f = f + b; + printf ("%f %f\n", e, f); +} + +/* { dg-final { scan-tree-dump-times "\\\+" 2 "optimized"} } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-4.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-4.c new file mode 100644 index 00000000000..6f46752df86 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-4.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +float a, b, c, d; +extern int printf (const char *, ...); +int main(void) +{ + float e; + float f; + /* We should not be able to transform these into the same expression, and only have two additions. */ + e = a + b; + e = e + c; + f = c + a; + f = f + b; + printf ("%f %f\n", e, f); +} + +/* { dg-final { scan-tree-dump-times "\\\+" 4 "optimized"} } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 395c5495455..e0d45612b01 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -435,10 +435,13 @@ reassociate_expr (tree bexpr, block_stmt_iterator *currbsi) unsigned int lhsrank = get_rank (lhs); unsigned int rhsrank = get_rank (rhs); - /* I don't want to get into the business of floating point - reassociation. */ - if (!INTEGRAL_TYPE_P (TREE_TYPE (lhs)) - || !INTEGRAL_TYPE_P (TREE_TYPE (rhs))) + /* If unsafe math optimizations we can do reassociation for non integal + types. */ + if ((!INTEGRAL_TYPE_P (TREE_TYPE (lhs)) + || !INTEGRAL_TYPE_P (TREE_TYPE (rhs))) + && (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (rhs)) + || !SCALAR_FLOAT_TYPE_P (TREE_TYPE(lhs)) + || !flag_unsafe_math_optimizations)) return false; /* We want the greater ranked operand to be our "LHS" for simplicity -- 2.30.2