public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [wide-int] resolve bootstrap issue
@ 2014-01-14 14:52 Mike Stump
  2014-01-14 15:25 ` Richard Sandiford
  0 siblings, 1 reply; 5+ messages in thread
From: Mike Stump @ 2014-01-14 14:52 UTC (permalink / raw)
  To: gcc-patches@gcc.gnu.org Patches

[-- Attachment #1: Type: text/plain, Size: 182 bytes --]

This resolves a bootstrap issue found after reducing the size of the maximal wide_int; the real code really does want a slightly larger type so we create on just for real.

Ok?


[-- Attachment #2: boot.diffs.txt --]
[-- Type: text/plain, Size: 4004 bytes --]

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 81bb407..f4ffdb0 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -685,10 +685,10 @@ c_readstr (const char *str, enum machine_mode mode)
   HOST_WIDE_INT tmp[MAX_BITSIZE_MODE_ANY_INT / HOST_BITS_PER_WIDE_INT];
 
   gcc_assert (GET_MODE_CLASS (mode) == MODE_INT);
-
   unsigned int len = (GET_MODE_PRECISION (mode) + HOST_BITS_PER_WIDE_INT - 1)
     / HOST_BITS_PER_WIDE_INT;
 
+  gcc_assert (len <= MAX_BITSIZE_MODE_ANY_INT / HOST_BITS_PER_WIDE_INT);
   for (i = 0; i < len; i++)
     tmp[i] = 0;
 
diff --git a/gcc/expmed.c b/gcc/expmed.c
index ce063eb..720d8c1 100644
--- a/gcc/expmed.c
+++ b/gcc/expmed.c
@@ -4963,6 +4963,7 @@ make_tree (tree type, rtx x)
       return t;
 
     case CONST_DOUBLE:
+      gcc_assert (HOST_BITS_PER_WIDE_INT * 2 <= MAX_BITSIZE_MODE_ANY_INT);
       if (TARGET_SUPPORTS_WIDE_INT == 0 && GET_MODE (x) == VOIDmode)
 	t = wide_int_to_tree (type,
 			      wide_int::from_array (&CONST_DOUBLE_LOW (x), 2,
diff --git a/gcc/lto-streamer-in.c b/gcc/lto-streamer-in.c
index d058307..08eba48 100644
--- a/gcc/lto-streamer-in.c
+++ b/gcc/lto-streamer-in.c
@@ -1312,6 +1312,7 @@ lto_input_tree_1 (struct lto_input_block *ib, struct data_in *data_in,
 
       for (i = 0; i < len; i++)
 	a[i] = streamer_read_hwi (ib);
+      gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
       result = wide_int_to_tree (type, wide_int::from_array
 				 (a, len, TYPE_PRECISION (type)));
       streamer_tree_cache_append (data_in->reader_cache, result, hash);
diff --git a/gcc/real.c b/gcc/real.c
index b060497..51d1868 100644
--- a/gcc/real.c
+++ b/gcc/real.c
@@ -1377,10 +1377,12 @@ real_to_integer (const REAL_VALUE_TYPE *r)
 wide_int
 real_to_integer (const REAL_VALUE_TYPE *r, bool *fail, int precision)
 {
+  typedef FIXED_WIDE_INT (WIDE_INT_MAX_PRECISION * 2) real_int;
   HOST_WIDE_INT val[2 * MAX_BITSIZE_MODE_ANY_INT / HOST_BITS_PER_WIDE_INT];
   int exp;
   int words;
   wide_int result;
+  real_int tmp;
   int w;
 
   switch (r->cl)
@@ -1440,10 +1442,10 @@ real_to_integer (const REAL_VALUE_TYPE *r, bool *fail, int precision)
 	}
 #endif
       w = SIGSZ * HOST_BITS_PER_LONG + words * HOST_BITS_PER_WIDE_INT;
-      result = wide_int::from_array
+      tmp = real_int::from_array
 	(val, (w + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT, w);
-      result = wi::lrshift (result, (words * HOST_BITS_PER_WIDE_INT) - exp);
-      result = wide_int::from (result, precision, UNSIGNED);
+      tmp = wi::lrshift<real_int> (tmp, (words * HOST_BITS_PER_WIDE_INT) - exp);
+      result = wide_int::from (tmp, precision, UNSIGNED);
 
       if (r->sign)
 	return -result;
diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index 00b5439..7c21afa 100644
--- a/gcc/simplify-rtx.c
+++ b/gcc/simplify-rtx.c
@@ -5384,6 +5384,7 @@ simplify_immed_subreg (enum machine_mode outermode, rtx op,
 		tmp[u] = buf;
 		base += HOST_BITS_PER_WIDE_INT;
 	      }
+	    gcc_assert (GET_MODE_PRECISION (outer_submode) <= MAX_BITSIZE_MODE_ANY_INT);
 	    r = wide_int::from_array (tmp, units,
 				      GET_MODE_PRECISION (outer_submode));
 	    elems[elem] = immed_wide_int_const (r, outer_submode);
diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c
index 50453b4..74d29d2 100644
--- a/gcc/tree-vect-generic.c
+++ b/gcc/tree-vect-generic.c
@@ -62,7 +62,7 @@ build_replicated_const (tree type, tree inner_type, HOST_WIDE_INT value)
   HOST_WIDE_INT a[WIDE_INT_MAX_ELTS];
   int i;
 
-  gcc_assert (n);
+  gcc_assert (n && n <= WIDE_INT_MAX_ELTS);
 
   if (width == HOST_BITS_PER_WIDE_INT)
     low = value;
@@ -75,6 +75,7 @@ build_replicated_const (tree type, tree inner_type, HOST_WIDE_INT value)
   for (i = 0; i < n; i++)
     a[i] = low;
 
+  gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
   return wide_int_to_tree
     (type, wide_int::from_array (a, n, TYPE_PRECISION (type)));
 }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [wide-int] resolve bootstrap issue
  2014-01-14 14:52 [wide-int] resolve bootstrap issue Mike Stump
@ 2014-01-14 15:25 ` Richard Sandiford
  2014-01-15 21:51   ` Mike Stump
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Sandiford @ 2014-01-14 15:25 UTC (permalink / raw)
  To: Mike Stump; +Cc: gcc-patches@gcc.gnu.org Patches

Mike Stump <mikestump@comcast.net> writes:
> diff --git a/gcc/expmed.c b/gcc/expmed.c
> index ce063eb..720d8c1 100644
> --- a/gcc/expmed.c
> +++ b/gcc/expmed.c
> @@ -4963,6 +4963,7 @@ make_tree (tree type, rtx x)
>        return t;
>  
>      case CONST_DOUBLE:
> +      gcc_assert (HOST_BITS_PER_WIDE_INT * 2 <= MAX_BITSIZE_MODE_ANY_INT);
>        if (TARGET_SUPPORTS_WIDE_INT == 0 && GET_MODE (x) == VOIDmode)
>  	t = wide_int_to_tree (type,
>  			      wide_int::from_array (&CONST_DOUBLE_LOW (x), 2,

I think this would be better as a STATIC_ASSERT.

> @@ -1440,10 +1442,10 @@ real_to_integer (const REAL_VALUE_TYPE *r, bool *fail, int precision)
>  	}
>  #endif
>        w = SIGSZ * HOST_BITS_PER_LONG + words * HOST_BITS_PER_WIDE_INT;
> -      result = wide_int::from_array
> +      tmp = real_int::from_array
>  	(val, (w + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT, w);
> -      result = wi::lrshift (result, (words * HOST_BITS_PER_WIDE_INT) - exp);
> -      result = wide_int::from (result, precision, UNSIGNED);
> +      tmp = wi::lrshift<real_int> (tmp, (words * HOST_BITS_PER_WIDE_INT) - exp);
> +      result = wide_int::from (tmp, precision, UNSIGNED);

Why did you need the <real_int>?  It was supposed to work without.

> diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
> index 00b5439..7c21afa 100644
> --- a/gcc/simplify-rtx.c
> +++ b/gcc/simplify-rtx.c
> @@ -5384,6 +5384,7 @@ simplify_immed_subreg (enum machine_mode outermode, rtx op,
>  		tmp[u] = buf;
>  		base += HOST_BITS_PER_WIDE_INT;
>  	      }
> +	    gcc_assert (GET_MODE_PRECISION (outer_submode) <= MAX_BITSIZE_MODE_ANY_INT);
>  	    r = wide_int::from_array (tmp, units,
>  				      GET_MODE_PRECISION (outer_submode));
>  	    elems[elem] = immed_wide_int_const (r, outer_submode);

Long line.

Looks good to me otherwise FWIW.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [wide-int] resolve bootstrap issue
  2014-01-14 15:25 ` Richard Sandiford
@ 2014-01-15 21:51   ` Mike Stump
  2014-01-16 10:55     ` Richard Sandiford
  0 siblings, 1 reply; 5+ messages in thread
From: Mike Stump @ 2014-01-15 21:51 UTC (permalink / raw)
  To: Richard Sandiford; +Cc: gcc-patches@gcc.gnu.org Patches

On Jan 14, 2014, at 7:25 AM, Richard Sandiford <rsandifo@linux.vnet.ibm.com> wrote:
> Mike Stump <mikestump@comcast.net> writes:
>> diff --git a/gcc/expmed.c b/gcc/expmed.c
>> index ce063eb..720d8c1 100644
>> --- a/gcc/expmed.c
>> +++ b/gcc/expmed.c
>> @@ -4963,6 +4963,7 @@ make_tree (tree type, rtx x)
>>       return t;
>> 
>>     case CONST_DOUBLE:
>> +      gcc_assert (HOST_BITS_PER_WIDE_INT * 2 <= MAX_BITSIZE_MODE_ANY_INT);
>>       if (TARGET_SUPPORTS_WIDE_INT == 0 && GET_MODE (x) == VOIDmode)
>> 	t = wide_int_to_tree (type,
>> 			      wide_int::from_array (&CONST_DOUBLE_LOW (x), 2,
> 
> I think this would be better as a STATIC_ASSERT.

The cost should be the same in generated code.  The C folks can read and understand the gcc_assert easier, and the static property of the check we don't make any use of.  I could change it, but there are 0 of these in *.c presently, and I think we want to tread lightly on those folks that know and like C, and don't want gcc to be `different' for no good reason.  That said, if people think it would be good to use it, I'd be happy to change it.

>> @@ -1440,10 +1442,10 @@ real_to_integer (const REAL_VALUE_TYPE *r, bool *fail, int precision)
>> 	}
>> #endif
>>       w = SIGSZ * HOST_BITS_PER_LONG + words * HOST_BITS_PER_WIDE_INT;
>> -      result = wide_int::from_array
>> +      tmp = real_int::from_array
>> 	(val, (w + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT, w);
>> -      result = wi::lrshift (result, (words * HOST_BITS_PER_WIDE_INT) - exp);
>> -      result = wide_int::from (result, precision, UNSIGNED);
>> +      tmp = wi::lrshift<real_int> (tmp, (words * HOST_BITS_PER_WIDE_INT) - exp);
>> +      result = wide_int::from (tmp, precision, UNSIGNED);
> 
> Why did you need the <real_int>?  It was supposed to work without.

The code in question needs something that is max int + max significand real in size, we made the max int smaller (smaller than this quantity on x86) so, this code needs a special wide int that is bigger.  The type is free as vrp uses the same type.  As for why Kenny choose this method, I'd defer to him.

>> diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
>> index 00b5439..7c21afa 100644
>> --- a/gcc/simplify-rtx.c
>> +++ b/gcc/simplify-rtx.c
>> @@ -5384,6 +5384,7 @@ simplify_immed_subreg (enum machine_mode outermode, rtx op,
>> 		tmp[u] = buf;
>> 		base += HOST_BITS_PER_WIDE_INT;
>> 	      }
>> +	    gcc_assert (GET_MODE_PRECISION (outer_submode) <= MAX_BITSIZE_MODE_ANY_INT);
>> 	    r = wide_int::from_array (tmp, units,
>> 				      GET_MODE_PRECISION (outer_submode));
>> 	    elems[elem] = immed_wide_int_const (r, outer_submode);
> 
> Long line.

Fixed:

Index: simplify-rtx.c
===================================================================
--- simplify-rtx.c	(revision 206601)
+++ simplify-rtx.c	(working copy)
@@ -5384,7 +5384,8 @@ simplify_immed_subreg (enum machine_mode
 		tmp[u] = buf;
 		base += HOST_BITS_PER_WIDE_INT;
 	      }
-	    gcc_assert (GET_MODE_PRECISION (outer_submode) <= MAX_BITSIZE_MODE_ANY_INT);
+	    gcc_assert (GET_MODE_PRECISION (outer_submode)
+			<= MAX_BITSIZE_MODE_ANY_INT);
 	    r = wide_int::from_array (tmp, units,
 				      GET_MODE_PRECISION (outer_submode));
 	    elems[elem] = immed_wide_int_const (r, outer_submode);

Thanks for the review.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [wide-int] resolve bootstrap issue
  2014-01-15 21:51   ` Mike Stump
@ 2014-01-16 10:55     ` Richard Sandiford
  2014-01-17 20:29       ` Mike Stump
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Sandiford @ 2014-01-16 10:55 UTC (permalink / raw)
  To: Mike Stump; +Cc: gcc-patches@gcc.gnu.org Patches

Mike Stump <mikestump@comcast.net> writes:
> On Jan 14, 2014, at 7:25 AM, Richard Sandiford
> <rsandifo@linux.vnet.ibm.com> wrote:
>> Mike Stump <mikestump@comcast.net> writes:
>>> diff --git a/gcc/expmed.c b/gcc/expmed.c
>>> index ce063eb..720d8c1 100644
>>> --- a/gcc/expmed.c
>>> +++ b/gcc/expmed.c
>>> @@ -4963,6 +4963,7 @@ make_tree (tree type, rtx x)
>>>       return t;
>>> 
>>>     case CONST_DOUBLE:
>>> +      gcc_assert (HOST_BITS_PER_WIDE_INT * 2 <= MAX_BITSIZE_MODE_ANY_INT);
>>>       if (TARGET_SUPPORTS_WIDE_INT == 0 && GET_MODE (x) == VOIDmode)
>>> 	t = wide_int_to_tree (type,
>>> 			      wide_int::from_array (&CONST_DOUBLE_LOW (x), 2,
>> 
>> I think this would be better as a STATIC_ASSERT.
>
> The cost should be the same in generated code.  The C folks can read and
> understand the gcc_assert easier, and the static property of the check
> we don't make any use of.  I could change it, but there are 0 of these
> in *.c presently, and I think we want to tread lightly on those folks
> that know and like C, and don't want gcc to be `different' for no good
> reason.  That said, if people think it would be good to use it, I'd be
> happy to change it.

Static asserts are better than run-time asserts because they're caught
earlier, at GCC compile time.  Yes, wide-int is the first thing to make
much use of it, but something has to be first.

>>> @@ -1440,10 +1442,10 @@ real_to_integer (const REAL_VALUE_TYPE *r, bool *fail, int precision)
>>> 	}
>>> #endif
>>>       w = SIGSZ * HOST_BITS_PER_LONG + words * HOST_BITS_PER_WIDE_INT;
>>> -      result = wide_int::from_array
>>> +      tmp = real_int::from_array
>>> 	(val, (w + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT, w);
>>> -      result = wi::lrshift (result, (words * HOST_BITS_PER_WIDE_INT) - exp);
>>> -      result = wide_int::from (result, precision, UNSIGNED);
>>> +      tmp = wi::lrshift<real_int> (tmp, (words * HOST_BITS_PER_WIDE_INT) - exp);
>>> +      result = wide_int::from (tmp, precision, UNSIGNED);
>> 
>> Why did you need the <real_int>?  It was supposed to work without.
>
> The code in question needs something that is max int + max significand
> real in size, we made the max int smaller (smaller than this quantity on
> x86) so, this code needs a special wide int that is bigger.  The type is
> free as vrp uses the same type.  As for why Kenny choose this method,
> I'd defer to him.

To be clear, I was only talking about the <real_int> in
"wi::lrshift<real_int>".  Just "wi::lrshift" should be fine.

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

Thanks,
Richard


Index: gcc/expmed.c
===================================================================
--- gcc/expmed.c	2014-01-15 16:39:39.881276576 +0000
+++ gcc/expmed.c	2014-01-15 16:39:40.375274550 +0000
@@ -4963,7 +4963,7 @@ make_tree (tree type, rtx x)
       return t;
 
     case CONST_DOUBLE:
-      gcc_assert (HOST_BITS_PER_WIDE_INT * 2 <= MAX_BITSIZE_MODE_ANY_INT);
+      STATIC_ASSERT (HOST_BITS_PER_WIDE_INT * 2 <= MAX_BITSIZE_MODE_ANY_INT);
       if (TARGET_SUPPORTS_WIDE_INT == 0 && GET_MODE (x) == VOIDmode)
 	t = wide_int_to_tree (type,
 			      wide_int::from_array (&CONST_DOUBLE_LOW (x), 2,
Index: gcc/real.c
===================================================================
--- gcc/real.c	2014-01-15 16:39:39.883276568 +0000
+++ gcc/real.c	2014-01-15 16:39:40.376274546 +0000
@@ -1444,7 +1444,7 @@ real_to_integer (const REAL_VALUE_TYPE *
       w = SIGSZ * HOST_BITS_PER_LONG + words * HOST_BITS_PER_WIDE_INT;
       tmp = real_int::from_array
 	(val, (w + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT, w);
-      tmp = wi::lrshift<real_int> (tmp, (words * HOST_BITS_PER_WIDE_INT) - exp);
+      tmp = wi::lrshift (tmp, (words * HOST_BITS_PER_WIDE_INT) - exp);
       result = wide_int::from (tmp, precision, UNSIGNED);
 
       if (r->sign)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [wide-int] resolve bootstrap issue
  2014-01-16 10:55     ` Richard Sandiford
@ 2014-01-17 20:29       ` Mike Stump
  0 siblings, 0 replies; 5+ messages in thread
From: Mike Stump @ 2014-01-17 20:29 UTC (permalink / raw)
  To: Richard Sandiford; +Cc: gcc-patches@gcc.gnu.org Patches

On Jan 16, 2014, at 2:55 AM, Richard Sandiford <rsandifo@linux.vnet.ibm.com> wrote:
>>> Why did you need the <real_int>?  It was supposed to work without.
>> 
>> The code in question needs something that is max int + max significand
>> real in size, we made the max int smaller (smaller than this quantity on
>> x86) so, this code needs a special wide int that is bigger.  The type is
>> free as vrp uses the same type.  As for why Kenny choose this method,
>> I'd defer to him.
> 
> To be clear, I was only talking about the <real_int> in
> "wi::lrshift<real_int>".  Just "wi::lrshift" should be fine.
> 
> Tested on x86_64-linux-gnu.  OK to install?

Ah, yes, I was trying to get it to compile at one point and added that; I now see what you mean. Yes, this is fine.

> Index: gcc/real.c
> ===================================================================
> --- gcc/real.c	2014-01-15 16:39:39.883276568 +0000
> +++ gcc/real.c	2014-01-15 16:39:40.376274546 +0000
> @@ -1444,7 +1444,7 @@ real_to_integer (const REAL_VALUE_TYPE *
>       w = SIGSZ * HOST_BITS_PER_LONG + words * HOST_BITS_PER_WIDE_INT;
>       tmp = real_int::from_array
> 	(val, (w + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT, w);
> -      tmp = wi::lrshift<real_int> (tmp, (words * HOST_BITS_PER_WIDE_INT) - exp);
> +      tmp = wi::lrshift (tmp, (words * HOST_BITS_PER_WIDE_INT) - exp);
>       result = wide_int::from (tmp, precision, UNSIGNED);
> 
>       if (r->sign)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-01-17 20:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-14 14:52 [wide-int] resolve bootstrap issue Mike Stump
2014-01-14 15:25 ` Richard Sandiford
2014-01-15 21:51   ` Mike Stump
2014-01-16 10:55     ` Richard Sandiford
2014-01-17 20:29       ` Mike Stump

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).