public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR48067
@ 2011-03-11 15:12 Richard Guenther
  0 siblings, 0 replies; only message in thread
From: Richard Guenther @ 2011-03-11 15:12 UTC (permalink / raw)
  To: gcc-patches


We shouldn't try to make use of the multiplication result twice in
FMA_EXPR building.  The following ensures that if the uses go
through a negate.

Bootstrap and regtest processing on x86_64-unknown-linux-gnu.

Richard.

2011-03-11  Richard Guenther  <rguenther@suse.de>

	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.

Index: gcc/tree-ssa-math-opts.c
===================================================================
*** gcc/tree-ssa-math-opts.c	(revision 170873)
--- gcc/tree-ssa-math-opts.c	(working copy)
*************** convert_mult_to_fma (gimple mul_stmt, tr
*** 1557,1562 ****
--- 1557,1565 ----
        /* 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
*************** convert_mult_to_fma (gimple mul_stmt, tr
*** 1565,1570 ****
--- 1568,1578 ----
  			       &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))
Index: gcc/testsuite/gcc.dg/pr48067.c
===================================================================
*** gcc/testsuite/gcc.dg/pr48067.c	(revision 0)
--- gcc/testsuite/gcc.dg/pr48067.c	(revision 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;
+ }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-03-11 15:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-11 15:12 [PATCH] Fix PR48067 Richard Guenther

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).