From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 429563858D38 for ; Sat, 16 Mar 2024 13:56:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 429563858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 429563858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710597408; cv=none; b=qXaJ7rYLWZ6Qt3ptyOJBaAJd13KGLlxg6W9RsYwhrzVpzBIcMizjCIEjtHxs/GsxK81RvdRnCfw4Aikb6TaVJm7W42p1AVE+QRRjnJiZkBOcqnAPGjsMp+orLWwwjtb2FkPzBLlDa27A5cWjFmSkYgKsoQkrAbhvD1bLU33spDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710597408; c=relaxed/simple; bh=d7YohntUXZX2FqhnbIghCMn7InfKHSMpQyBpGZa4Fec=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: Mime-Version:Subject:Date:Message-Id:To; b=rcBhqfaQhaXu+mBN44TXikI2nVBGAP2hCBNrL76V7muV7H8PPcReyOyr2hQ//MIYlyyhXw8ko6SQGlQcJXleydOvKO/5rC+oF02rARxiJGGYpCfgvgXzZzOcxL84fvMpGkam1mY388UKNc9+XGTMkQWha1nHE6424AqllaFiFUA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 157141FC9E; Sat, 16 Mar 2024 13:56:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1710597405; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x6Yf00zDyuF7djbmEgM4IpAgRqHIPX82U8sZgJ8lRQw=; b=LkclK7fFQegv9ym8tI6SOhQNE67zjh7aHHxFjDeoqhMp8V45kKNmnGTrAKjoGgCE5dYcnF 2qX3j74E2YbN3PiC8C7nFb+FLXnZNTngi3sL6BWEYgBstnRz75PzgX6TrfpivhHz3d1IOt 4JmMTXHT7ygk56StDNNeFmKruYBmbGo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1710597405; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x6Yf00zDyuF7djbmEgM4IpAgRqHIPX82U8sZgJ8lRQw=; b=4M33dZ6sj1m+HCBfkkfq17Trx1BDj+rIYQrLBSk29F1id3CP+dgh01lwpV2DmrSFgxSiJV 4UcQWfCpRKXfxuBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1710597405; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x6Yf00zDyuF7djbmEgM4IpAgRqHIPX82U8sZgJ8lRQw=; b=LkclK7fFQegv9ym8tI6SOhQNE67zjh7aHHxFjDeoqhMp8V45kKNmnGTrAKjoGgCE5dYcnF 2qX3j74E2YbN3PiC8C7nFb+FLXnZNTngi3sL6BWEYgBstnRz75PzgX6TrfpivhHz3d1IOt 4JmMTXHT7ygk56StDNNeFmKruYBmbGo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1710597405; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x6Yf00zDyuF7djbmEgM4IpAgRqHIPX82U8sZgJ8lRQw=; b=4M33dZ6sj1m+HCBfkkfq17Trx1BDj+rIYQrLBSk29F1id3CP+dgh01lwpV2DmrSFgxSiJV 4UcQWfCpRKXfxuBw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 05B9C13A66; Sat, 16 Mar 2024 13:56:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id J6pcAR2l9WXUOAAAD6G6ig (envelope-from ); Sat, 16 Mar 2024 13:56:45 +0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Richard Biener Mime-Version: 1.0 (1.0) Subject: Re: [PATCH] bitint: Fix up stores to large/huge _BitInt bitfields [PR114329] Date: Sat, 16 Mar 2024 14:56:30 +0100 Message-Id: References: Cc: gcc-patches@gcc.gnu.org In-Reply-To: To: Jakub Jelinek X-Mailer: iPhone Mail (21E219) X-Spam-Level: Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=LkclK7fF; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=4M33dZ6s X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-1.16 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; BAYES_HAM(-0.15)[68.79%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MV_CASE(0.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; RCPT_COUNT_TWO(0.00)[2]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-Spam-Score: -1.16 X-Rspamd-Queue-Id: 157141FC9E X-Spam-Status: No, score=-5.5 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: > Am 16.03.2024 um 08:11 schrieb Jakub Jelinek : >=20 > =EF=BB=BFHi! >=20 > The verifier requires BIT_FIELD_REFs with INTEGRAL_TYPE_P first operand > to have mode precision. In most cases for the large/huge _BitInt bitfield= > stores the code uses bitfield representatives, which are typically arrays > of chars, but if the bitfield starts at byte boundary on big endian, > the code uses as nlhs in lower_mergeable_store COMPONENT_REF of the > bitfield FIELD_DECL instead, which is fine for the limb accesses, > but when used for the most significant limb can result in invalid > BIT_FIELD_REF because the first operand then has BITINT_TYPE and > usually VOIDmode. >=20 > The following patch adds a helper method for the 4 creatikons of > BIT_FIELD_REF which when needed adds a VIEW_CONVERT_EXPR. >=20 > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Ok Richard=20 > 2024-03-16 Jakub Jelinek >=20 > PR tree-optimization/114329 > * gimple-lower-bitint.cc (struct bitint_large_huge): Declare > build_bit_field_ref method. > (bitint_large_huge::build_bit_field_ref): New method. > (bitint_large_huge::lower_mergeable_stmt): Use it. >=20 > * gcc.dg/bitint-101.c: New test. >=20 > --- gcc/gimple-lower-bitint.cc.jj 2024-03-15 09:16:36.464033118 +0100 > +++ gcc/gimple-lower-bitint.cc 2024-03-15 17:53:30.200276578 +0100 > @@ -427,6 +427,8 @@ struct bitint_large_huge > void insert_before (gimple *); > tree limb_access_type (tree, tree); > tree limb_access (tree, tree, tree, bool); > + tree build_bit_field_ref (tree, tree, unsigned HOST_WIDE_INT, > + unsigned HOST_WIDE_INT); > void if_then (gimple *, profile_probability, edge &, edge &); > void if_then_else (gimple *, profile_probability, edge &, edge &); > void if_then_if_then_else (gimple *g, gimple *, > @@ -659,6 +661,31 @@ bitint_large_huge::limb_access (tree typ > return ret; > } >=20 > +/* Build a BIT_FIELD_REF to access BITSIZE bits with FTYPE type at > + offset BITPOS inside of OBJ. */ > + > +tree > +bitint_large_huge::build_bit_field_ref (tree ftype, tree obj, > + unsigned HOST_WIDE_INT bitsize, > + unsigned HOST_WIDE_INT bitpos) > +{ > + if (INTEGRAL_TYPE_P (TREE_TYPE (obj)) > + && !type_has_mode_precision_p (TREE_TYPE (obj))) > + { > + unsigned HOST_WIDE_INT nelts > + =3D CEIL (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (obj))), limb_prec); > + tree ltype =3D m_limb_type; > + addr_space_t as =3D TYPE_ADDR_SPACE (TREE_TYPE (obj)); > + if (as !=3D TYPE_ADDR_SPACE (ltype)) > + ltype =3D build_qualified_type (ltype, TYPE_QUALS (ltype) > + | ENCODE_QUAL_ADDR_SPACE (as)); > + tree atype =3D build_array_type_nelts (ltype, nelts); > + obj =3D build1 (VIEW_CONVERT_EXPR, atype, obj); > + } > + return build3 (BIT_FIELD_REF, ftype, obj, bitsize_int (bitsize), > + bitsize_int (bitpos)); > +} > + > /* Emit a half diamond, > if (COND) > |\ > @@ -2651,9 +2678,9 @@ bitint_large_huge::lower_mergeable_stmt > } > tree ftype > =3D build_nonstandard_integer_type (limb_prec - bo_bit, 1); > - tree bfr =3D build3 (BIT_FIELD_REF, ftype, unshare_expr (nlhs),= > - bitsize_int (limb_prec - bo_bit), > - bitsize_int (bo_idx * limb_prec + bo_bit)); > + tree bfr =3D build_bit_field_ref (ftype, unshare_expr (nlhs), > + limb_prec - bo_bit, > + bo_idx * limb_prec + bo_bit); > tree t =3D add_cast (ftype, rhs1); > g =3D gimple_build_assign (bfr, t); > insert_before (g); > @@ -2714,12 +2741,11 @@ bitint_large_huge::lower_mergeable_stmt > { > tree ftype > =3D build_nonstandard_integer_type (rprec + bo_bit, 1); > - tree bfr =3D build3 (BIT_FIELD_REF, ftype, > - unshare_expr (nlhs), > - bitsize_int (rprec + bo_bit), > - bitsize_int ((bo_idx > - + tprec / limb_prec) > - * limb_prec)); > + tree bfr > + =3D build_bit_field_ref (ftype, unshare_expr (nlhs), > + rprec + bo_bit, > + (bo_idx + tprec / limb_prec) > + * limb_prec); > tree t =3D add_cast (ftype, rhs1); > g =3D gimple_build_assign (bfr, t); > done =3D true; > @@ -2860,11 +2886,11 @@ bitint_large_huge::lower_mergeable_stmt > { > tree ftype > =3D build_nonstandard_integer_type (rprec + bo_bit, 1); > - tree bfr =3D build3 (BIT_FIELD_REF, ftype, > - unshare_expr (nlhs), > - bitsize_int (rprec + bo_bit), > - bitsize_int ((bo_idx + tprec / limb_prec) > - * limb_prec)); > + tree bfr > + =3D build_bit_field_ref (ftype, unshare_expr (nlhs), > + rprec + bo_bit, > + (bo_idx + tprec / limb_prec) > + * limb_prec); > tree t =3D add_cast (ftype, rhs1); > g =3D gimple_build_assign (bfr, t); > done =3D true; > @@ -2909,10 +2935,10 @@ bitint_large_huge::lower_mergeable_stmt > unsigned int tprec =3D TYPE_PRECISION (type); > unsigned int rprec =3D tprec % limb_prec; > tree ftype =3D build_nonstandard_integer_type (rprec + bo_bit, 1); > - tree bfr =3D build3 (BIT_FIELD_REF, ftype, unshare_expr (nlhs), > - bitsize_int (rprec + bo_bit), > - bitsize_int ((bo_idx + tprec / limb_prec) > - * limb_prec)); > + tree bfr =3D build_bit_field_ref (ftype, unshare_expr (nlhs), > + rprec + bo_bit, > + (bo_idx + tprec / limb_prec) > + * limb_prec); > rhs1 =3D bf_cur; > if (bf_cur !=3D ext) > { > --- gcc/testsuite/gcc.dg/bitint-101.c.jj 2024-03-15 18:59:01.386413294 += 0100 > +++ gcc/testsuite/gcc.dg/bitint-101.c 2024-03-15 18:58:14.063059994 +01= 00 > @@ -0,0 +1,17 @@ > +/* PR tree-optimization/114329 */ > +/* { dg-do compile { target bitint } } */ > +/* { dg-options "-std=3Dc23" } */ > + > +#if __BITINT_MAXWIDTH__ >=3D 129 > +#define N 129 > +#else > +#define N 63 > +#endif > + > +struct S { _BitInt(N) b : N; } s; > + > +void > +foo (void) > +{ > + s.b ^=3D 42; > +} >=20 > Jakub >=20