From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id EB1FD3858CDA for ; Mon, 26 Sep 2022 08:05:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EB1FD3858CDA 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-out1.suse.de (Postfix) with ESMTP id BFE72220B9; Mon, 26 Sep 2022 08:05:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664179530; 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=UQBzF2/NWjmUx1O2yY4hYYlilJoXgJZxbcainHL6WIM=; b=avS3WQS4vN3fgFm/Cg7uLjt6rCk7XpZ1X1Qy3wqw0deU2IceWMNriKSGM9ILIkHJhM0Xy1 hle6rvJelVcSmp2LcoaPI1XvMElNuOl37u+KvVKJUa3Ohd4rJe22hkkjwzrmm1c/R2OCIF dhevXIqYBYgF2j/4dRJ5uIMudJcMIig= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664179530; 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=UQBzF2/NWjmUx1O2yY4hYYlilJoXgJZxbcainHL6WIM=; b=vmphjE9aRC5PG385v1viuOyJImM6pdcMdRtIEvqUOuWgOKFMRRA4Oyp5Ao2RQTNExsIaEE gSymXUHIQSBU6YAw== 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 B7B322C14B; Mon, 26 Sep 2022 08:05:30 +0000 (UTC) Date: Mon, 26 Sep 2022 08:05:30 +0000 (UTC) From: Richard Biener To: Tamar Christina cc: Andrew Pinski , "gcc-patches@gcc.gnu.org" , nd Subject: RE: [PATCH 1/2]middle-end Fold BIT_FIELD_REF and Shifts into BIT_FIELD_REFs alone 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=-11.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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 Mon, 26 Sep 2022, Tamar Christina wrote: > > -----Original Message----- > > From: Andrew Pinski > > Sent: Saturday, September 24, 2022 8:57 PM > > To: Tamar Christina > > Cc: gcc-patches@gcc.gnu.org; nd ; rguenther@suse.de > > Subject: Re: [PATCH 1/2]middle-end Fold BIT_FIELD_REF and Shifts into > > BIT_FIELD_REFs alone > > > > On Fri, Sep 23, 2022 at 4:43 AM Tamar Christina via Gcc-patches > patches@gcc.gnu.org> wrote: > > > > > > Hi All, > > > > > > This adds a match.pd rule that can fold right shifts and > > > bit_field_refs of integers into just a bit_field_ref by adjusting the > > > offset and the size of the extract and adds an extend to the previous size. > > > > > > Concretely turns: > > > > > > #include > > > > > > unsigned int foor (uint32x4_t x) > > > { > > > return x[1] >> 16; > > > } > > > > > > which used to generate: > > > > > > _1 = BIT_FIELD_REF ; > > > _3 = _1 >> 16; > > > > > > into > > > > > > _4 = BIT_FIELD_REF ; > > > _2 = (unsigned int) _4; > > > > > > I currently limit the rewrite to only doing it if the resulting > > > extract is in a mode the target supports. i.e. it won't rewrite it to > > > extract say 13-bits because I worry that for targets that won't have a > > > bitfield extract instruction this may be a de-optimization. > > > > It is only a de-optimization for the following case: > > * vector extraction > > > > All other cases should be handled correctly in the middle-end when > > expanding to RTL because they need to be handled for bit-fields anyways. > > Plus SIGN_EXTRACT and ZERO_EXTRACT would be used in the integer case > > for the RTL. > > Getting SIGN_EXTRACT/ZERO_EXTRACT early on in the RTL is better than > > waiting until combine really. > > > > Fair enough, I've dropped the constraint. > > > > > > > > > Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu > > > and no issues. > > > > > > Testcase are added in patch 2/2. > > > > > > Ok for master? > > > > > > Thanks, > > > Tamar > > > > > > gcc/ChangeLog: > > > > > > * match.pd: Add bitfield and shift folding. > > > > > > --- inline copy of patch -- > > > diff --git a/gcc/match.pd b/gcc/match.pd index > > > > > 1d407414bee278c64c00d425d9f025c1c58d853d..b225d36dc758f1581502c8d03 > > 761 > > > 544bfd499c01 100644 > > > --- a/gcc/match.pd > > > +++ b/gcc/match.pd > > > @@ -7245,6 +7245,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > > > && ANY_INTEGRAL_TYPE_P (type) && ANY_INTEGRAL_TYPE_P > > (TREE_TYPE(@0))) > > > (IFN_REDUC_PLUS_WIDEN @0))) > > > > > > +/* Canonicalize BIT_FIELD_REFS and shifts to BIT_FIELD_REFS. */ > > > (for > > > +shift (rshift) > > > + op (plus) why have a for when you only iterate over a single operation?! And 'op' seems unused? > > > + (simplify > > > + (shift (BIT_FIELD_REF @0 @1 @2) integer_pow2p@3) > > > + (if (INTEGRAL_TYPE_P (type)) > > > + (with { /* Can't use wide-int here as the precision differs between > > > + @1 and @3. */ > > > + unsigned HOST_WIDE_INT size = tree_to_uhwi (@1); > > > + unsigned HOST_WIDE_INT shiftc = tree_to_uhwi (@3); But you should then test tree_fits_uhwi_p. > > > + unsigned HOST_WIDE_INT newsize = size - shiftc; > > > + tree nsize = wide_int_to_tree (bitsizetype, newsize); > > > + tree ntype > > > + = build_nonstandard_integer_type (newsize, 1); } build_nonstandard_integer_type never fails so I don't see how you "limit" this to extractions fitting a mode. I'm quite sure this breaks with BYTES_BIG_ENDIAN. Please try BIT_FIELD_REF _offsets_ that make the extraction cross byte boundaries. Also I'm missing a testcase? Thanks, Richard. > > Maybe use `build_nonstandard_integer_type (newsize, /* unsignedp = */ > > true);` or better yet `build_nonstandard_integer_type (newsize, > > UNSIGNED);` > > Ah, will do, > Tamar. > > > > > I had started to convert some of the unsignedp into enum signop but I never > > finished or submitted the patch. > > > > Thanks, > > Andrew Pinski > > > > > > > + (if (ntype) > > > + (convert:type (BIT_FIELD_REF:ntype @0 { nsize; } (op @2 > > > + @3)))))))) > > > + > > > (simplify > > > (BIT_FIELD_REF (BIT_FIELD_REF @0 @1 @2) @3 @4) > > > (BIT_FIELD_REF @0 @3 { const_binop (PLUS_EXPR, bitsizetype, @2, @4); > > > })) > > > > > > > > > > > > > > > -- > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)