From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id AD8D33858CD1 for ; Mon, 31 Jul 2023 08:40:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD8D33858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 686951F74C; Mon, 31 Jul 2023 08:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1690792833; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=82hnQoVDo3dqah1fNOVRmla1qH3HCEZJ0OGnbOMG45g=; b=pltaTVT+ZPj3G8YQxoeHOmtcrR/ogmedwXSfjwp5djzGwnm9vf8OI7i+Vx29xIlVODbd/0 m4GvRDxAYG3uSPfn0RZUSV6qSVYGWdvDgcDGPreNMNz1tdYSmHZBRNddsX8Vd/SW53xqoJ KlgdAWETAeCV0/9WS7/05TOf/zpfENQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1690792833; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=82hnQoVDo3dqah1fNOVRmla1qH3HCEZJ0OGnbOMG45g=; b=izpnPmwB0ihpdydlq5DwJPac2pdrOkSncbCPr/VdqFxCbWXojCuKSCwgnwY3DdaYv/bYJi g/xM5tnHfMLPzpAA== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 477202C142; Mon, 31 Jul 2023 08:40:33 +0000 (UTC) Date: Mon, 31 Jul 2023 08:40:33 +0000 (UTC) From: Richard Biener To: Jakub Jelinek cc: "Joseph S. Myers" , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] gimple-fold: Handle _BitInt in __builtin_clear_padding [PR102989] In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, 28 Jul 2023, Jakub Jelinek wrote: > Hi! > > The comments about _Atomic _BitInt made me figure out I forgot (although > earlier was planning to do that) to implement __builtin_clear_padding > support for _BitInt. > > The following patch (incremental to the _BitInt series) does that. OK. Thanks, Richard. > 2023-07-28 Jakub Jelinek > > PR c/102989 > * gimple-fold.cc (clear_padding_unit): Mention in comment that > _BitInt types don't need to fit either. > (clear_padding_bitint_needs_padding_p): New function. > (clear_padding_type_may_have_padding_p): Handle BITINT_TYPE. > (clear_padding_type): Likewise. > > * gcc.dg/bitint-16.c: New test. > > --- gcc/gimple-fold.cc.jj 2023-07-11 15:28:54.704679510 +0200 > +++ gcc/gimple-fold.cc 2023-07-28 12:37:18.971789595 +0200 > @@ -4103,8 +4103,8 @@ gimple_fold_builtin_realloc (gimple_stmt > return false; > } > > -/* Number of bytes into which any type but aggregate or vector types > - should fit. */ > +/* Number of bytes into which any type but aggregate, vector or > + _BitInt types should fit. */ > static constexpr size_t clear_padding_unit > = MAX_BITSIZE_MODE_ANY_MODE / BITS_PER_UNIT; > /* Buffer size on which __builtin_clear_padding folding code works. */ > @@ -4595,6 +4595,26 @@ clear_padding_real_needs_padding_p (tree > && (fmt->signbit_ro == 79 || fmt->signbit_ro == 95)); > } > > +/* _BitInt has padding bits if it isn't extended in the ABI and has smaller > + precision than bits in limb or corresponding number of limbs. */ > + > +static bool > +clear_padding_bitint_needs_padding_p (tree type) > +{ > + struct bitint_info info; > + gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), &info)); > + if (info.extended) > + return false; > + scalar_int_mode limb_mode = as_a (info.limb_mode); > + if (TYPE_PRECISION (type) < GET_MODE_PRECISION (limb_mode)) > + return true; > + else if (TYPE_PRECISION (type) == GET_MODE_PRECISION (limb_mode)) > + return false; > + else > + return (((unsigned) TYPE_PRECISION (type)) > + % GET_MODE_PRECISION (limb_mode)) != 0; > +} > + > /* Return true if TYPE might contain any padding bits. */ > > bool > @@ -4611,6 +4631,8 @@ clear_padding_type_may_have_padding_p (t > return clear_padding_type_may_have_padding_p (TREE_TYPE (type)); > case REAL_TYPE: > return clear_padding_real_needs_padding_p (type); > + case BITINT_TYPE: > + return clear_padding_bitint_needs_padding_p (type); > default: > return false; > } > @@ -4855,6 +4877,57 @@ clear_padding_type (clear_padding_struct > memset (buf->buf + buf->size, ~0, sz); > buf->size += sz; > break; > + case BITINT_TYPE: > + { > + struct bitint_info info; > + gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), &info)); > + scalar_int_mode limb_mode = as_a (info.limb_mode); > + if (TYPE_PRECISION (type) <= GET_MODE_PRECISION (limb_mode)) > + { > + gcc_assert ((size_t) sz <= clear_padding_unit); > + if ((unsigned HOST_WIDE_INT) sz + buf->size > + > clear_padding_buf_size) > + clear_padding_flush (buf, false); > + if (!info.extended > + && TYPE_PRECISION (type) < GET_MODE_PRECISION (limb_mode)) > + { > + int tprec = GET_MODE_PRECISION (limb_mode); > + int prec = TYPE_PRECISION (type); > + tree t = build_nonstandard_integer_type (tprec, 1); > + tree cst = wide_int_to_tree (t, wi::mask (prec, true, tprec)); > + int len = native_encode_expr (cst, buf->buf + buf->size, sz); > + gcc_assert (len > 0 && (size_t) len == (size_t) sz); > + } > + else > + memset (buf->buf + buf->size, 0, sz); > + buf->size += sz; > + break; > + } > + tree limbtype > + = build_nonstandard_integer_type (GET_MODE_PRECISION (limb_mode), 1); > + fldsz = int_size_in_bytes (limbtype); > + nelts = int_size_in_bytes (type) / fldsz; > + for (HOST_WIDE_INT i = 0; i < nelts; i++) > + { > + if (!info.extended > + && i == (info.big_endian ? 0 : nelts - 1) > + && (((unsigned) TYPE_PRECISION (type)) > + % TYPE_PRECISION (limbtype)) != 0) > + { > + int tprec = GET_MODE_PRECISION (limb_mode); > + int prec = (((unsigned) TYPE_PRECISION (type)) % tprec); > + tree cst = wide_int_to_tree (limbtype, > + wi::mask (prec, true, tprec)); > + int len = native_encode_expr (cst, buf->buf + buf->size, > + fldsz); > + gcc_assert (len > 0 && (size_t) len == (size_t) fldsz); > + buf->size += fldsz; > + } > + else > + clear_padding_type (buf, limbtype, fldsz, for_auto_init); > + } > + break; > + } > default: > gcc_assert ((size_t) sz <= clear_padding_unit); > if ((unsigned HOST_WIDE_INT) sz + buf->size > clear_padding_buf_size) > --- gcc/testsuite/gcc.dg/bitint-16.c.jj 2023-07-28 12:47:37.641180784 +0200 > +++ gcc/testsuite/gcc.dg/bitint-16.c 2023-07-28 12:47:30.488280320 +0200 > @@ -0,0 +1,31 @@ > +/* PR c/102989 */ > +/* { dg-do compile { target bitint } } */ > +/* { dg-options "-O2 -std=c2x -pedantic-errors" } */ > + > +_BitInt(15) a; > +_BitInt(42) b; > +#if __BITINT_MAXWIDTH__ >= 115 > +_BitInt(115) c; > +#endif > +#if __BITINT_MAXWIDTH__ >= 192 > +_BitInt(192) d; > +#endif > +#if __BITINT_MAXWIDTH__ >= 575 > +_BitInt(575) e; > +#endif > + > +int > +main () > +{ > + __builtin_clear_padding (&a); > + __builtin_clear_padding (&b); > +#if __BITINT_MAXWIDTH__ >= 115 > + __builtin_clear_padding (&c); > +#endif > +#if __BITINT_MAXWIDTH__ >= 192 > + __builtin_clear_padding (&d); > +#endif > +#if __BITINT_MAXWIDTH__ >= 575 > + __builtin_clear_padding (&e); > +#endif > +} > > Jakub > > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)