From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E4F923858C50 for ; Thu, 9 Feb 2023 09:57:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E4F923858C50 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675936669; h=from:from:reply-to:reply-to:subject:subject: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=mmSv7hL73gGqeJ/9154XW0rFlicqXCVWOjy/JRqU+2w=; b=L4qb6kLYV/tdb5iqDDwbCrzKaAUZ+0zrxeY2HrVrzEYtJ/tYwT5VtyF9M7Qg7U4+ixTT0M 3eyL+hKCAKkJIksPqr3FsqKdtp+A/p6qVXooLwzhgKMUBlrf3plDdw8rv5tKFmk+Bll3uf IoFbKoFvZvoZ39QEm6Lm8+lNOsnvGV8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-15-Yw1YuyyKN1eM6OmpD3zMrA-1; Thu, 09 Feb 2023 04:57:46 -0500 X-MC-Unique: Yw1YuyyKN1eM6OmpD3zMrA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E585E101B44E; Thu, 9 Feb 2023 09:57:45 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A13A218EC1; Thu, 9 Feb 2023 09:57:45 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3199vgqS1922468 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 9 Feb 2023 10:57:43 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3199vgUr1922467; Thu, 9 Feb 2023 10:57:42 +0100 Date: Thu, 9 Feb 2023 10:57:41 +0100 From: Jakub Jelinek To: Richard Biener Cc: Andrew Pinski , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] When simplifing BFR of an insert, require a mode precision integral type (PR108688) Message-ID: Reply-To: Jakub Jelinek References: <20230208211419.1583473-1-apinski@marvell.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,WEIRD_PORT 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 Thu, Feb 09, 2023 at 09:16:17AM +0100, Richard Biener via Gcc-patches wrote: > On Wed, Feb 8, 2023 at 10:15 PM Andrew Pinski via Gcc-patches > wrote: > > > > The same problem as PR 88739 has crept in but > > this time in match.pd when simplifying bit_field_ref of > > an bit_insert. That is we are generating a BIT_FIELD_REF > > of a non-mode-precision integral type. > > > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. > > Hmm. Can we handle the case of the extraction exactly covering the > insertion separately then and simplify to plain @1? I was suggesting that in the PR. Here it is as an incremental patch on top of Andrew's patch. Ok for trunk if it passes bootstrap/regtest? On the newly added testcase the ifcvt-folding difference without/with the incremental patch is: --- pr108688.c.171t.ifcvt_ 2023-02-09 10:47:30.169916845 +0100 +++ pr108688.c.171t.ifcvt 2023-02-09 10:48:44.942793453 +0100 @@ -25,6 +25,8 @@ Number of blocks in CFG: 11 Number of blocks to update: 5 ( 45%) +Applying pattern match.pd:7487, gimple-match.cc:243200 +Applying pattern match.pd:3987, gimple-match.cc:75423 Matching expression match.pd:1677, gimple-match.cc:209 Applying pattern match.pd:1733, gimple-match.cc:109481 Matching expression match.pd:2393, gimple-match.cc:852 @@ -70,7 +72,6 @@ void foo () signed char _29; _30; unsigned int ivtmp_33; - _ifc__35; unsigned char _ifc__37; unsigned char _ifc__38; unsigned char _ifc__39; @@ -91,8 +92,7 @@ void foo () _2 = () a.0_1; _ifc__38 = u.D.2741; _ifc__39 = BIT_INSERT_EXPR <_ifc__38, _2, 0 (7 bits)>; - _ifc__35 = BIT_FIELD_REF <_ifc__39, 7, 0>; - _4 = (signed char) _ifc__35; + _4 = (signed char) _2; b.1_5 = b; _6 = (signed char) b.1_5; _7 = _4 ^ _6; 2023-02-09 Jakub Jelinek PR tree-optimization/108688 * match.pd (bit_field_ref [bit_insert]): Simplify BIT_FIELD_REF of BIT_INSERT_EXPR extracting exactly all inserted bits even when without mode precision. Formatting fixes. * gcc.c-torture/compile/pr108688-1.c: Add PR number as comment. * gcc.dg/pr108688.c: New test. --- gcc/match.pd.jj 2023-02-09 09:42:53.782418805 +0100 +++ gcc/match.pd 2023-02-09 10:48:06.859365613 +0100 @@ -7475,13 +7475,16 @@ (define_operator_list SYNC_FETCH_AND_AND } (switch (if ((!INTEGRAL_TYPE_P (TREE_TYPE (@1)) - || type_has_mode_precision_p (TREE_TYPE (@1))) - && wi::leu_p (wi::to_wide (@ipos), wi::to_wide (@rpos)) + || type_has_mode_precision_p (TREE_TYPE (@1))) + && wi::leu_p (wi::to_wide (@ipos), wi::to_wide (@rpos)) && wi::leu_p (wi::to_wide (@rpos) + wi::to_wide (@rsize), wi::to_wide (@ipos) + isize)) (BIT_FIELD_REF @1 @rsize { wide_int_to_tree (bitsizetype, - wi::to_wide (@rpos) + wi::to_wide (@rpos) - wi::to_wide (@ipos)); })) + (if (wi::eq_p (wi::to_wide (@ipos), wi::to_wide (@rpos)) + && compare_tree_int (@rsize, isize) == 0) + (convert @1)) (if (wi::geu_p (wi::to_wide (@ipos), wi::to_wide (@rpos) + wi::to_wide (@rsize)) || wi::geu_p (wi::to_wide (@rpos), --- gcc/testsuite/gcc.c-torture/compile/pr108688-1.c.jj 2023-02-09 09:42:53.782418805 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr108688-1.c 2023-02-09 10:34:18.339817796 +0100 @@ -1,4 +1,4 @@ - +/* PR tree-optimization/108688 */ union U { signed int d : 7; signed int e : 2; } u; int a, b; @@ -12,4 +12,3 @@ foo (void) u.e ^= b; } } - --- gcc/testsuite/gcc.dg/pr108688.c.jj 2023-02-09 10:50:27.468253110 +0100 +++ gcc/testsuite/gcc.dg/pr108688.c 2023-02-09 10:50:16.383419646 +0100 @@ -0,0 +1,16 @@ +/* PR tree-optimization/108688 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-pre -fno-tree-fre -fno-tree-dominator-opts -fno-tree-loop-im -fno-code-hoisting" } */ + +union U { signed int d : 7; signed int e : 2; } u; +int a, b; + +void +foo (void) +{ + for (int i = 0; i < 64; i++) + { + u.d = a; + u.d ^= b; + } +} Jakub