Patchwork [wide-int] Use MAX_MODE_INT rather than mode_for_size

login
register
mail settings
Submitter Richard Sandiford
Date Nov. 9, 2013, 10:57 a.m.
Message ID <87d2m9g7wi.fsf@talisman.default>
Download mbox | patch
Permalink /patch/289968/
State New
Headers show

Comments

Richard Sandiford - Nov. 9, 2013, 10:57 a.m.
"mode_for_size (MAX_BITSIZE_MODE_ANY_INT, MODE_INT, 0)" isn't safe
because the widest mode might not have an integer counterpart.
We can get the widest integer mode directly using MAX_MODE_INT.

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

Thanks,
Richard
Kenneth Zadeck - Nov. 9, 2013, 3:15 p.m.
On 11/09/2013 05:57 AM, Richard Sandiford wrote:
> "mode_for_size (MAX_BITSIZE_MODE_ANY_INT, MODE_INT, 0)" isn't safe
> because the widest mode might not have an integer counterpart.
> We can get the widest integer mode directly using MAX_MODE_INT.
>
> Tested on powerpc64-linux-gnu and by rerunning the assembly comparison.
> OK to install?
>
> Thanks,
> Richard
>
>
> Index: gcc/simplify-rtx.c
> ===================================================================
> --- gcc/simplify-rtx.c	2013-11-09 09:39:28.925815686 +0000
> +++ gcc/simplify-rtx.c	2013-11-09 09:39:29.461819309 +0000
> @@ -1619,7 +1619,7 @@ simplify_const_unary_operation (enum rtx
>   	     a dangerous assumption as many times CONST_INTs are
>   	     created and used with garbage in the bits outside of the
>   	     precision of the implied mode of the const_int.  */
> -	  op_mode = mode_for_size (MAX_BITSIZE_MODE_ANY_INT, MODE_INT, 0);
> +	  op_mode = MAX_MODE_INT;
>   	}
>   
>         real_from_integer (&d, mode, std::make_pair (op, op_mode), SIGNED);
> @@ -1637,7 +1637,7 @@ simplify_const_unary_operation (enum rtx
>   	     a dangerous assumption as many times CONST_INTs are
>   	     created and used with garbage in the bits outside of the
>   	     precision of the implied mode of the const_int.  */
> -	  op_mode = mode_for_size (MAX_BITSIZE_MODE_ANY_INT, MODE_INT, 0);
> +	  op_mode = MAX_MODE_INT;
>   	}
>   
>         real_from_integer (&d, mode, std::make_pair (op, op_mode), UNSIGNED);
i guess you are correct.     i had assumed that the MAX_BITSIZE.. would 
always relate to a real integer because partial int modes have to be 
based on an underlying mode.   Obviously you have a counter example in 
mind, but this code is actually just as good so it ok to install.

kenny
Mike Stump - Nov. 9, 2013, 5:04 p.m.
On Nov 9, 2013, at 2:57 AM, Richard Sandiford <rdsandiford@googlemail.com> wrote:
> "mode_for_size (MAX_BITSIZE_MODE_ANY_INT, MODE_INT, 0)" isn't safe
> because the widest mode might not have an integer counterpart.
> We can get the widest integer mode directly using MAX_MODE_INT.

> OK to install?

Ah, curious.  Ok.  Long term, one might want a partial int mode that is larger that all in modes, and support conversions to/from thoseā€¦  but, to do that, we'd need a bit more code.

Patch

Index: gcc/simplify-rtx.c
===================================================================
--- gcc/simplify-rtx.c	2013-11-09 09:39:28.925815686 +0000
+++ gcc/simplify-rtx.c	2013-11-09 09:39:29.461819309 +0000
@@ -1619,7 +1619,7 @@  simplify_const_unary_operation (enum rtx
 	     a dangerous assumption as many times CONST_INTs are
 	     created and used with garbage in the bits outside of the
 	     precision of the implied mode of the const_int.  */
-	  op_mode = mode_for_size (MAX_BITSIZE_MODE_ANY_INT, MODE_INT, 0);
+	  op_mode = MAX_MODE_INT;
 	}
 
       real_from_integer (&d, mode, std::make_pair (op, op_mode), SIGNED);
@@ -1637,7 +1637,7 @@  simplify_const_unary_operation (enum rtx
 	     a dangerous assumption as many times CONST_INTs are
 	     created and used with garbage in the bits outside of the
 	     precision of the implied mode of the const_int.  */
-	  op_mode = mode_for_size (MAX_BITSIZE_MODE_ANY_INT, MODE_INT, 0);
+	  op_mode = MAX_MODE_INT;
 	}
 
       real_from_integer (&d, mode, std::make_pair (op, op_mode), UNSIGNED);