diff mbox

[wide-int] Make more use of const references

Message ID 87wqkhg9pt.fsf@talisman.default
State New
Headers show

Commit Message

Richard Sandiford Nov. 9, 2013, 10:17 a.m. UTC
Some cases where we could use const references instead of passing by value.

Tested on powerpc64-linux-gnu and by rerunning the assembly comparison.
OK to install?

Thanks,
Richard

Comments

Kenneth Zadeck Nov. 9, 2013, 3 p.m. UTC | #1
looks good to me.

On 11/09/2013 05:17 AM, Richard Sandiford wrote:
> Some cases where we could use const references instead of passing by value.
>
> Tested on powerpc64-linux-gnu and by rerunning the assembly comparison.
> OK to install?
>
> Thanks,
> Richard
>
>
> Index: gcc/fold-const.c
> ===================================================================
> --- gcc/fold-const.c	2013-11-09 09:39:27.373805197 +0000
> +++ gcc/fold-const.c	2013-11-09 09:39:28.207810833 +0000
> @@ -9886,7 +9886,7 @@ exact_inverse (tree type, tree cst)
>   /*  Mask out the tz least significant bits of X of type TYPE where
>       tz is the number of trailing zeroes in Y.  */
>   static wide_int
> -mask_with_tz (tree type, wide_int x, wide_int y)
> +mask_with_tz (tree type, const wide_int &x, const wide_int &y)
>   {
>     int tz = wi::ctz (y);
>     if (tz > 0)
> Index: gcc/tree-ssanames.c
> ===================================================================
> --- gcc/tree-ssanames.c	2013-11-09 09:39:17.714739914 +0000
> +++ gcc/tree-ssanames.c	2013-11-09 09:39:28.208810840 +0000
> @@ -179,7 +179,7 @@ make_ssa_name_fn (struct function *fn, t
>   /* Store range information MIN, and MAX to tree ssa_name NAME.  */
>   
>   void
> -set_range_info (tree name, widest_int min, widest_int max)
> +set_range_info (tree name, const widest_int &min, const widest_int &max)
>   {
>     gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
>     range_info_def *ri = SSA_NAME_RANGE_INFO (name);
> @@ -201,16 +201,15 @@ set_range_info (tree name, widest_int mi
>     if (wi::cmp (min, max, TYPE_SIGN (TREE_TYPE (name))) != 1)
>       {
>         int prec = TYPE_PRECISION (TREE_TYPE (name));
> -      widest_int xorv;
>   
> -      min = wi::zext (min, prec);
> -      max = wi::zext (max, prec);
> -      xorv = min ^ max;
> +      widest_int ext_min = wi::zext (min, prec);
> +      widest_int ext_max = wi::zext (max, prec);
> +      widest_int xorv = ext_min ^ ext_max;
>         if (xorv != 0)
>   	xorv = wi::mask <widest_int> (MAX_BITSIZE_MODE_ANY_INT
>   				      - wi::clz (xorv),
>   				      false);
> -      ri->nonzero_bits = ri->nonzero_bits & (min | xorv);
> +      ri->nonzero_bits = ri->nonzero_bits & (ext_min | xorv);
>       }
>   }
>   
> @@ -254,7 +253,7 @@ get_range_info (const_tree name, widest_
>   /* Change non-zero bits bitmask of NAME.  */
>   
>   void
> -set_nonzero_bits (tree name, widest_int mask)
> +set_nonzero_bits (tree name, const widest_int &mask)
>   {
>     gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
>     if (SSA_NAME_RANGE_INFO (name) == NULL)
> Index: gcc/tree-ssanames.h
> ===================================================================
> --- gcc/tree-ssanames.h	2013-11-09 09:39:17.714739914 +0000
> +++ gcc/tree-ssanames.h	2013-11-09 09:39:28.208810840 +0000
> @@ -70,11 +70,11 @@ #define ssa_name(i) ((*cfun->gimple_df->
>   enum value_range_type { VR_UNDEFINED, VR_RANGE, VR_ANTI_RANGE, VR_VARYING };
>   
>   /* Sets the value range to SSA.  */
> -extern void set_range_info (tree, widest_int, widest_int);
> +extern void set_range_info (tree, const widest_int &, const widest_int &);
>   /* Gets the value range from SSA.  */
>   extern enum value_range_type get_range_info (const_tree, widest_int *,
>   					     widest_int *);
> -extern void set_nonzero_bits (tree, widest_int);
> +extern void set_nonzero_bits (tree, const widest_int &);
>   extern widest_int get_nonzero_bits (const_tree);
>   extern void init_ssanames (struct function *, int);
>   extern void fini_ssanames (void);
Mike Stump Nov. 9, 2013, 4:38 p.m. UTC | #2
On Nov 9, 2013, at 2:17 AM, Richard Sandiford <rdsandiford@googlemail.com> wrote:
> Some cases where we could use const references instead of passing by value.

> OK to install?

Ok.
diff mbox

Patch

Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c	2013-11-09 09:39:27.373805197 +0000
+++ gcc/fold-const.c	2013-11-09 09:39:28.207810833 +0000
@@ -9886,7 +9886,7 @@  exact_inverse (tree type, tree cst)
 /*  Mask out the tz least significant bits of X of type TYPE where
     tz is the number of trailing zeroes in Y.  */
 static wide_int
-mask_with_tz (tree type, wide_int x, wide_int y)
+mask_with_tz (tree type, const wide_int &x, const wide_int &y)
 {
   int tz = wi::ctz (y);
   if (tz > 0)
Index: gcc/tree-ssanames.c
===================================================================
--- gcc/tree-ssanames.c	2013-11-09 09:39:17.714739914 +0000
+++ gcc/tree-ssanames.c	2013-11-09 09:39:28.208810840 +0000
@@ -179,7 +179,7 @@  make_ssa_name_fn (struct function *fn, t
 /* Store range information MIN, and MAX to tree ssa_name NAME.  */
 
 void
-set_range_info (tree name, widest_int min, widest_int max)
+set_range_info (tree name, const widest_int &min, const widest_int &max)
 {
   gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
   range_info_def *ri = SSA_NAME_RANGE_INFO (name);
@@ -201,16 +201,15 @@  set_range_info (tree name, widest_int mi
   if (wi::cmp (min, max, TYPE_SIGN (TREE_TYPE (name))) != 1)
     {
       int prec = TYPE_PRECISION (TREE_TYPE (name));
-      widest_int xorv;
 
-      min = wi::zext (min, prec);
-      max = wi::zext (max, prec);
-      xorv = min ^ max;
+      widest_int ext_min = wi::zext (min, prec);
+      widest_int ext_max = wi::zext (max, prec);
+      widest_int xorv = ext_min ^ ext_max;
       if (xorv != 0)
 	xorv = wi::mask <widest_int> (MAX_BITSIZE_MODE_ANY_INT
 				      - wi::clz (xorv),
 				      false);
-      ri->nonzero_bits = ri->nonzero_bits & (min | xorv);
+      ri->nonzero_bits = ri->nonzero_bits & (ext_min | xorv);
     }
 }
 
@@ -254,7 +253,7 @@  get_range_info (const_tree name, widest_
 /* Change non-zero bits bitmask of NAME.  */
 
 void
-set_nonzero_bits (tree name, widest_int mask)
+set_nonzero_bits (tree name, const widest_int &mask)
 {
   gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
   if (SSA_NAME_RANGE_INFO (name) == NULL)
Index: gcc/tree-ssanames.h
===================================================================
--- gcc/tree-ssanames.h	2013-11-09 09:39:17.714739914 +0000
+++ gcc/tree-ssanames.h	2013-11-09 09:39:28.208810840 +0000
@@ -70,11 +70,11 @@  #define ssa_name(i) ((*cfun->gimple_df->
 enum value_range_type { VR_UNDEFINED, VR_RANGE, VR_ANTI_RANGE, VR_VARYING };
 
 /* Sets the value range to SSA.  */
-extern void set_range_info (tree, widest_int, widest_int);
+extern void set_range_info (tree, const widest_int &, const widest_int &);
 /* Gets the value range from SSA.  */
 extern enum value_range_type get_range_info (const_tree, widest_int *,
 					     widest_int *);
-extern void set_nonzero_bits (tree, widest_int);
+extern void set_nonzero_bits (tree, const widest_int &);
 extern widest_int get_nonzero_bits (const_tree);
 extern void init_ssanames (struct function *, int);
 extern void fini_ssanames (void);