public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] wide-int: Fix up set_bit_large
       [not found]   ` <mpty2jrmuil.fsf@arm.com>
@ 2020-10-28  9:26     ` Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-10-28  9:26 UTC (permalink / raw)
  To: Andrew MacLeod, richard.sandiford; +Cc: gcc-patches

On Tue, Oct 27, 2020 at 05:46:42PM +0000, Richard Sandiford via Gcc wrote:
> >> and proceeds to call
> >> 
> >> wide_int new_lb = wi::set_bit (r.lower_bound (0), 127)
> >> 
> >> and creates the value:
> >> 
> >> p new_lb
> >> {<wide_int_storage> = {val = {-65535, -1, 0}, len = 2, precision = 128},
> >> static is_sign_extended = true}
> >
> > This is non-canonical and so invalid, if the low HWI has the MSB set
> > and the high HWI is -1, it should have been just
> > val = {-65535}, len = 1, precision = 128}
> >
> > I guess the bug is that wi::set_bit_large doesn't call canonize.
> 
> Yeah, looks like a micro-optimisation gone wrong.
> LGTM, thanks.

I've now successfully bootstrapped/regtested the patch and committed to
trunk.  I'll backport it later.

2020-10-28  Jakub Jelinek  <jakub@redhat.com>

	* wide-int.cc (wi::set_bit_large): Call canonize unless setting
	msb bit and clearing bits above it.

--- gcc/wide-int.cc.jj	2020-10-19 18:42:41.134426398 +0200
+++ gcc/wide-int.cc	2020-10-27 18:33:38.546703763 +0100
@@ -702,8 +702,11 @@ wi::set_bit_large (HOST_WIDE_INT *val, c
       /* If the bit we just set is at the msb of the block, make sure
 	 that any higher bits are zeros.  */
       if (bit + 1 < precision && subbit == HOST_BITS_PER_WIDE_INT - 1)
-	val[len++] = 0;
-      return len;
+	{
+	  val[len++] = 0;
+	  return len;
+	}
+      return canonize (val, len, precision);
     }
   else
     {


	Jakub


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-28  9:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <c55aa6bf-f2ae-fd55-44a7-f82391ce3e12@redhat.com>
     [not found] ` <20201027173552.GR7080@tucnak>
     [not found]   ` <mpty2jrmuil.fsf@arm.com>
2020-10-28  9:26     ` [committed] wide-int: Fix up set_bit_large Jakub Jelinek

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).