From ee8a9b7b507013b0431cabd314a245461c3b86b9 Mon Sep 17 00:00:00 2001 From: Joern Rennecke Date: Wed, 10 Apr 2013 09:54:25 +0000 Subject: [PATCH] re PR tree-optimization/55524 (If fnma exists but not fms, convert_mult_to_fma should prefer to former over the latter.) gcc: 2013-04-10 Joern Rennecke PR tree-optimization/55524 * tree-ssa-math-opts.c (convert_mult_to_fma): Don't use an fms construct when we don't have an fms operation, but fnma, and it looks likely that we'll be able to use the latter. gcc/testsuite: 2013-04-10 Joern Rennecke PR tree-optimization/55524 * gcc.target/epiphany/fnma-1.c: New test. From-SVN: r197668 --- gcc/ChangeLog | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.target/epiphany/fnma-1.c | 9 +++++++++ gcc/tree-ssa-math-opts.c | 18 ++++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 gcc/testsuite/gcc.target/epiphany/fnma-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b8a67893a0a..98c6462794d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2013-04-10 Joern Rennecke + + PR tree-optimization/55524 + * tree-ssa-math-opts.c + (convert_mult_to_fma): Don't use an fms construct + when we don't have an fms operation, but fnma, and it looks + likely that we'll be able to use the latter. + 2013-04-10 Zhouyi Zhou * cif-code.def (OVERWRITABLE): Correct the comment for overwritable diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 13585fc0758..aacd0094a09 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-04-10 Joern Rennecke + + PR tree-optimization/55524 + * gcc.target/epiphany/fnma-1.c: New test. + 2013-04-10 Zhouyi Zhou * gcc.dg/tree-ssa/inline-11.c: New test diff --git a/gcc/testsuite/gcc.target/epiphany/fnma-1.c b/gcc/testsuite/gcc.target/epiphany/fnma-1.c new file mode 100644 index 00000000000..3155079f4a1 --- /dev/null +++ b/gcc/testsuite/gcc.target/epiphany/fnma-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-times "fmsub\[ \ta-zA-Z0-9\]*," 1 } } */ + +float +f (float ar, float ai, float br, float bi) +{ + return ar * br - ai * bi; +} diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index 2140ced495b..e7e09f6a9de 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -2570,6 +2570,24 @@ convert_mult_to_fma (gimple mul_stmt, tree op1, tree op2) return false; } + /* If the subtrahend (gimple_assign_rhs2 (use_stmt)) is computed + by a MULT_EXPR that we'll visit later, we might be able to + get a more profitable match with fnma. + OTOH, if we don't, a negate / fma pair has likely lower latency + that a mult / subtract pair. */ + if (use_code == MINUS_EXPR && !negate_p + && gimple_assign_rhs1 (use_stmt) == result + && optab_handler (fms_optab, TYPE_MODE (type)) == CODE_FOR_nothing + && optab_handler (fnma_optab, TYPE_MODE (type)) != CODE_FOR_nothing) + { + tree rhs2 = gimple_assign_rhs2 (use_stmt); + gimple stmt2 = SSA_NAME_DEF_STMT (rhs2); + + if (has_single_use (rhs2) + && gimple_assign_rhs_code (stmt2) == MULT_EXPR) + return false; + } + /* We can't handle a * b + a * b. */ if (gimple_assign_rhs1 (use_stmt) == gimple_assign_rhs2 (use_stmt)) return false;