This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Teach SCCVN about ternary operators


This fixes a regression with folding fma to FMA_EXPR and SCCVN.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2010-11-16  Richard Guenther  <rguenther@suse.de>

	* tree-ssa-sccvn.c (visit_unary_op): Rename to ...
	(visit_nary_op): ... this.
	(visit_binary_op): Remove.
	(visit_use): Adjust and handle GIMPLE_TERNARY_RHS.

	* gcc.dg/tree-ssa/ssa-fre-30.c: New testcase.

Index: gcc/tree-ssa-sccvn.c
===================================================================
*** gcc/tree-ssa-sccvn.c	(revision 166793)
--- gcc/tree-ssa-sccvn.c	(working copy)
*************** visit_copy (tree lhs, tree rhs)
*** 2167,2207 ****
    return set_ssa_val_to (lhs, rhs);
  }
  
! /* Visit a unary operator RHS, value number it, and return true if the
     value number of LHS has changed as a result.  */
  
  static bool
! visit_unary_op (tree lhs, gimple stmt)
  {
    bool changed = false;
    tree result = vn_nary_op_lookup_stmt (stmt, NULL);
  
    if (result)
!     {
!       changed = set_ssa_val_to (lhs, result);
!     }
!   else
!     {
!       changed = set_ssa_val_to (lhs, lhs);
!       vn_nary_op_insert_stmt (stmt, lhs);
!     }
! 
!   return changed;
! }
! 
! /* Visit a binary operator RHS, value number it, and return true if the
!    value number of LHS has changed as a result.  */
! 
! static bool
! visit_binary_op (tree lhs, gimple stmt)
! {
!   bool changed = false;
!   tree result = vn_nary_op_lookup_stmt (stmt, NULL);
! 
!   if (result)
!     {
!       changed = set_ssa_val_to (lhs, result);
!     }
    else
      {
        changed = set_ssa_val_to (lhs, lhs);
--- 2167,2183 ----
    return set_ssa_val_to (lhs, rhs);
  }
  
! /* Visit a nary operator RHS, value number it, and return true if the
     value number of LHS has changed as a result.  */
  
  static bool
! visit_nary_op (tree lhs, gimple stmt)
  {
    bool changed = false;
    tree result = vn_nary_op_lookup_stmt (stmt, NULL);
  
    if (result)
!     changed = set_ssa_val_to (lhs, result);
    else
      {
        changed = set_ssa_val_to (lhs, lhs);
*************** visit_use (tree use)
*** 2909,2918 ****
  		  switch (get_gimple_rhs_class (gimple_assign_rhs_code (stmt)))
  		    {
  		    case GIMPLE_UNARY_RHS:
- 		      changed = visit_unary_op (lhs, stmt);
- 		      break;
  		    case GIMPLE_BINARY_RHS:
! 		      changed = visit_binary_op (lhs, stmt);
  		      break;
  		    case GIMPLE_SINGLE_RHS:
  		      switch (TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)))
--- 2885,2893 ----
  		  switch (get_gimple_rhs_class (gimple_assign_rhs_code (stmt)))
  		    {
  		    case GIMPLE_UNARY_RHS:
  		    case GIMPLE_BINARY_RHS:
! 		    case GIMPLE_TERNARY_RHS:
! 		      changed = visit_nary_op (lhs, stmt);
  		      break;
  		    case GIMPLE_SINGLE_RHS:
  		      switch (TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)))
*************** visit_use (tree use)
*** 2921,2930 ****
  			  /* VOP-less references can go through unary case.  */
  			  if ((gimple_assign_rhs_code (stmt) == REALPART_EXPR
  			       || gimple_assign_rhs_code (stmt) == IMAGPART_EXPR
! 			       || gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR )
  			      && TREE_CODE (TREE_OPERAND (gimple_assign_rhs1 (stmt), 0)) == SSA_NAME)
  			    {
! 			      changed = visit_unary_op (lhs, stmt);
  			      break;
  			    }
  			  /* Fallthrough.  */
--- 2896,2905 ----
  			  /* VOP-less references can go through unary case.  */
  			  if ((gimple_assign_rhs_code (stmt) == REALPART_EXPR
  			       || gimple_assign_rhs_code (stmt) == IMAGPART_EXPR
! 			       || gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR)
  			      && TREE_CODE (TREE_OPERAND (gimple_assign_rhs1 (stmt), 0)) == SSA_NAME)
  			    {
! 			      changed = visit_nary_op (lhs, stmt);
  			      break;
  			    }
  			  /* Fallthrough.  */
*************** visit_use (tree use)
*** 2935,2941 ****
  			case tcc_expression:
  			  if (gimple_assign_rhs_code (stmt) == ADDR_EXPR)
  			    {
! 			      changed = visit_unary_op (lhs, stmt);
  			      break;
  			    }
  			  /* Fallthrough.  */
--- 2910,2916 ----
  			case tcc_expression:
  			  if (gimple_assign_rhs_code (stmt) == ADDR_EXPR)
  			    {
! 			      changed = visit_nary_op (lhs, stmt);
  			      break;
  			    }
  			  /* Fallthrough.  */
Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-30.c
===================================================================
*** gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-30.c	(revision 0)
--- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-30.c	(revision 0)
***************
*** 0 ****
--- 1,12 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -ffinite-math-only -fdump-tree-optimized" } */
+ 
+ float foo(float x, float y, float z)
+ {
+   float a = __builtin_fmaf (x, y, z);
+   float b = __builtin_fmaf (x, y, z);
+   return a - b;
+ }
+ 
+ /* { dg-final { scan-tree-dump "return 0" "optimized" } } */
+ /* { dg-final { cleanup-tree-dump "optimized" } } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]