RFA: More uses of wi:: instead of const_binop

Richard Sandiford rdsandiford@googlemail.com
Sat May 10 19:29:00 GMT 2014


Following on from the patch for PR61136, this patch avoids some other
uses of const_binop in which we know both operands are INTEGER_CSTs
and where a wi:: routine would do.  As before, the idea is to avoid
creating an INTEGER_CST only to test whether it's zero.

Tested on x86_64-linux-gnu.  OK to install?

Thanks,
Richard


gcc/
	* fold-const.c (optimize_bit_field_compare): Use wi:: operations
	instead of const_binop.
	(fold_binary_loc): Likewise.

Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c	2014-05-10 14:13:50.222904190 +0100
+++ gcc/fold-const.c	2014-05-10 15:48:29.505451808 +0100
@@ -3444,7 +3444,7 @@ optimize_bit_field_compare (location_t l
 {
   HOST_WIDE_INT lbitpos, lbitsize, rbitpos, rbitsize, nbitpos, nbitsize;
   tree type = TREE_TYPE (lhs);
-  tree signed_type, unsigned_type;
+  tree unsigned_type;
   int const_p = TREE_CODE (rhs) == INTEGER_CST;
   enum machine_mode lmode, rmode, nmode;
   int lunsignedp, runsignedp;
@@ -3489,7 +3489,6 @@ optimize_bit_field_compare (location_t l
 
   /* Set signed and unsigned types of the precision of this mode for the
      shifts below.  */
-  signed_type = lang_hooks.types.type_for_mode (nmode, 0);
   unsigned_type = lang_hooks.types.type_for_mode (nmode, 1);
 
   /* Compute the bit position and size for the new reference and our offset
@@ -3538,10 +3537,7 @@ optimize_bit_field_compare (location_t l
 
   if (lunsignedp)
     {
-      if (! integer_zerop (const_binop (RSHIFT_EXPR,
-					fold_convert_loc (loc,
-							  unsigned_type, rhs),
-					size_int (lbitsize))))
+      if (wi::lrshift (rhs, lbitsize) != 0)
 	{
 	  warning (0, "comparison is always %d due to width of bit-field",
 		   code == NE_EXPR);
@@ -3550,10 +3546,8 @@ optimize_bit_field_compare (location_t l
     }
   else
     {
-      tree tem = const_binop (RSHIFT_EXPR,
-			      fold_convert_loc (loc, signed_type, rhs),
-			      size_int (lbitsize - 1));
-      if (! integer_zerop (tem) && ! integer_all_onesp (tem))
+      wide_int tem = wi::arshift (rhs, lbitsize - 1);
+      if (tem != 0 && tem != -1)
 	{
 	  warning (0, "comparison is always %d due to width of bit-field",
 		   code == NE_EXPR);
@@ -10356,9 +10350,8 @@ fold_binary_loc (location_t loc,
 	      && TREE_CODE (arg1) == BIT_AND_EXPR
 	      && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
 	      && TREE_CODE (TREE_OPERAND (arg1, 1)) == INTEGER_CST
-	      && integer_zerop (const_binop (BIT_AND_EXPR,
-					     TREE_OPERAND (arg0, 1),
-					     TREE_OPERAND (arg1, 1))))
+	      && wi::bit_and (TREE_OPERAND (arg0, 1),
+			      TREE_OPERAND (arg1, 1)) == 0)
 	    {
 	      code = BIT_IOR_EXPR;
 	      goto bit_ior;
@@ -11478,9 +11471,8 @@ fold_binary_loc (location_t loc,
 	  && TREE_CODE (arg1) == BIT_AND_EXPR
 	  && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
 	  && TREE_CODE (TREE_OPERAND (arg1, 1)) == INTEGER_CST
-	  && integer_zerop (const_binop (BIT_AND_EXPR,
-					 TREE_OPERAND (arg0, 1),
-					 TREE_OPERAND (arg1, 1))))
+	  && wi::bit_and (TREE_OPERAND (arg0, 1),
+			  TREE_OPERAND (arg1, 1)) == 0)
 	{
 	  code = BIT_IOR_EXPR;
 	  goto bit_ior;



More information about the Gcc-patches mailing list