From a758fd670cbf0935c6fa6cac3336b184f5c3c92a Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Fri, 11 Mar 2011 16:36:16 +0000 Subject: [PATCH] re PR tree-optimization/48067 (FMA with no add operand produced by convert_mul_to_fma) 2011-03-11 Richard Guenther PR tree-optimization/48067 * tree-ssa-math-opts.c (convert_mult_to_fma): Verify the multiplication result will be only used once on the target stmt. * gcc.dg/pr48067.c: New testcase. From-SVN: r170877 --- gcc/ChangeLog | 7 +++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr48067.c | 11 +++++++++++ gcc/tree-ssa-math-opts.c | 8 ++++++++ 4 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr48067.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8a5ca08feee..78a6a324ffb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2011-03-11 Richard Guenther + + PR tree-optimization/48067 + * tree-ssa-math-opts.c (convert_mult_to_fma): Verify the + multiplication result will be only used once on the target + stmt. + 2011-03-11 Richard Guenther * doc/invoke.texi (max-inline-insns-single): Adjust default value. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 69b6ad51d63..5976bb4fd34 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-03-11 Richard Guenther + + PR tree-optimization/48067 + * gcc.dg/pr48067.c: New testcase. + 2011-03-11 Richard Guenther PR lto/48073 diff --git a/gcc/testsuite/gcc.dg/pr48067.c b/gcc/testsuite/gcc.dg/pr48067.c new file mode 100644 index 00000000000..779690918ce --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr48067.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ffast-math -fno-tree-forwprop -fno-tree-reassoc" } */ +/* { dg-options "-O2 -ffast-math -fno-tree-forwprop -fno-tree-reassoc -mfma4" { target x86_64-*-* i?86-*-* } } */ + +float +foo (float x, float cim) +{ + float c = x * cim; + float d = -c; + return c - d; +} diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index ed9b7a9d546..6e2213ccea2 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -1557,6 +1557,9 @@ convert_mult_to_fma (gimple mul_stmt, tree op1, tree op2) /* A negate on the multiplication leads to FNMA. */ if (use_code == NEGATE_EXPR) { + ssa_op_iter iter; + tree use; + result = gimple_assign_lhs (use_stmt); /* Make sure the negate statement becomes dead with this @@ -1565,6 +1568,11 @@ convert_mult_to_fma (gimple mul_stmt, tree op1, tree op2) &use_p, &neguse_stmt)) return false; + /* Make sure the multiplication isn't also used on that stmt. */ + FOR_EACH_SSA_TREE_OPERAND (use, neguse_stmt, iter, SSA_OP_USE) + if (use == mul_result) + return false; + /* Re-validate. */ use_stmt = neguse_stmt; if (gimple_bb (use_stmt) != gimple_bb (mul_stmt)) -- 2.30.2