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][15/n] Merge from match-and-simplify, last conversion pattern


This merges the last conversion pattern from tree-ssa-forwprop.c.

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

Richard.

2014-11-10  Richard Biener  <rguenther@suse.de>

	* match.pd: Implement pattern from simplify_conversion_from_bitmask.
	* tree-ssa-forwprop.c (simplify_conversion_from_bitmask): Remove.
	(pass_forwprop::execute): Do not call simplify_conversion_from_bitmask.

Index: trunk/gcc/match.pd
===================================================================
*** trunk.orig/gcc/match.pd	2014-11-10 10:15:49.325550358 +0100
--- trunk/gcc/match.pd	2014-11-10 10:17:12.413546722 +0100
*************** along with GCC; see the file COPYING3.
*** 431,433 ****
--- 431,445 ----
  	(unsigned) significand_size (TYPE_MODE (inter_type))
  	>= inside_prec - !inside_unsignedp)
      (convert @0))))))
+ 
+ /* If we have a narrowing conversion to an integral type that is fed by a
+    BIT_AND_EXPR, we might be able to remove the BIT_AND_EXPR if it merely
+    masks off bits outside the final type (and nothing else).  */
+ (simplify
+   (convert (bit_and @0 INTEGER_CST@1))
+   (if (INTEGRAL_TYPE_P (type)
+        && INTEGRAL_TYPE_P (TREE_TYPE (@0))
+        && TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (@0))
+        && operand_equal_p (@1, build_low_bits_mask (TREE_TYPE (@1),
+ 						    TYPE_PRECISION (type)), 0))
+    (convert @0)))
Index: trunk/gcc/tree-ssa-forwprop.c
===================================================================
*** trunk.orig/gcc/tree-ssa-forwprop.c	2014-11-10 10:15:49.655550343 +0100
--- trunk/gcc/tree-ssa-forwprop.c	2014-11-10 10:20:47.391537314 +0100
*************** bailout:
*** 1214,1291 ****
  }
  
  
- /* GSI_P points to a statement which performs a narrowing integral
-    conversion.
- 
-    Look for cases like:
- 
-      t = x & c;
-      y = (T) t;
- 
-    Turn them into:
- 
-      t = x & c;
-      y = (T) x;
- 
-    If T is narrower than X's type and C merely masks off bits outside
-    of (T) and nothing else.
- 
-    Normally we'd let DCE remove the dead statement.  But no DCE runs
-    after the last forwprop/combine pass, so we remove the obviously
-    dead code ourselves.
- 
-    Return TRUE if a change was made, FALSE otherwise.  */
- 
- static bool 
- simplify_conversion_from_bitmask (gimple_stmt_iterator *gsi_p)
- {
-   gimple stmt = gsi_stmt (*gsi_p);
-   gimple rhs_def_stmt = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (stmt));
- 
-   /* See if the input for the conversion was set via a BIT_AND_EXPR and
-      the only use of the BIT_AND_EXPR result is the conversion.  */
-   if (is_gimple_assign (rhs_def_stmt)
-       && gimple_assign_rhs_code (rhs_def_stmt) == BIT_AND_EXPR
-       && has_single_use (gimple_assign_lhs (rhs_def_stmt)))
-     {
-       tree rhs_def_operand1 = gimple_assign_rhs1 (rhs_def_stmt);
-       tree rhs_def_operand2 = gimple_assign_rhs2 (rhs_def_stmt);
-       tree lhs_type = TREE_TYPE (gimple_assign_lhs (stmt));
- 
-       /* Now verify suitability of the BIT_AND_EXPR's operands.
- 	 The first must be an SSA_NAME that we can propagate and the
- 	 second must be an integer constant that masks out all the
- 	 bits outside the final result's type, but nothing else.  */
-       if (TREE_CODE (rhs_def_operand1) == SSA_NAME
- 	  && ! SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs_def_operand1)
- 	  && TREE_CODE (rhs_def_operand2) == INTEGER_CST
- 	  && operand_equal_p (rhs_def_operand2,
- 			      build_low_bits_mask (TREE_TYPE (rhs_def_operand2),
- 			       			   TYPE_PRECISION (lhs_type)),
- 						   0))
- 	{
- 	  /* This is an optimizable case.  Replace the source operand
- 	     in the conversion with the first source operand of the
- 	     BIT_AND_EXPR.  */
- 	  gimple_assign_set_rhs1 (stmt, rhs_def_operand1);
- 	  stmt = gsi_stmt (*gsi_p);
- 	  update_stmt (stmt);
- 
- 	  /* There is no DCE after the last forwprop pass.  It's
- 	     easy to clean up the first order effects here.  */
- 	  gimple_stmt_iterator si;
- 	  si = gsi_for_stmt (rhs_def_stmt);
- 	  gsi_remove (&si, true);
- 	  fwprop_invalidate_lattice (gimple_get_lhs (rhs_def_stmt));
- 	  release_defs (rhs_def_stmt);
- 	  return true;
- 	}
-     }
- 
-   return false;
- }
- 
- 
  /* Helper function for simplify_gimple_switch.  Remove case labels that
     have values outside the range of the new type.  */
  
--- 1214,1219 ----
*************** pass_forwprop::execute (function *fun)
*** 2940,2963 ****
  			&& maybe_clean_or_replace_eh_stmt (stmt, stmt))
  		      bitmap_set_bit (to_purge, bb->index);
  		  }
- 		else if (CONVERT_EXPR_CODE_P (code)
- 			 || code == FLOAT_EXPR
- 			 || code == FIX_TRUNC_EXPR)
- 		  {
- 		    /* If we have a narrowing conversion to an integral
- 		       type that is fed by a BIT_AND_EXPR, we might be
- 		       able to remove the BIT_AND_EXPR if it merely
- 		       masks off bits outside the final type (and nothing
- 		       else.  */
- 		    tree outer_type = TREE_TYPE (gimple_assign_lhs (stmt));
- 		    tree inner_type = TREE_TYPE (gimple_assign_rhs1 (stmt));
- 		    if (TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME
- 			&& INTEGRAL_TYPE_P (outer_type)
- 			&& INTEGRAL_TYPE_P (inner_type)
- 			&& (TYPE_PRECISION (outer_type)
- 			    <= TYPE_PRECISION (inner_type)))
- 		      changed = simplify_conversion_from_bitmask (&gsi);
- 		  }
  		else if (code == VEC_PERM_EXPR)
  		  {
  		    int did_something = simplify_permutation (&gsi);
--- 2868,2873 ----


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