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 1DC683858015 for ; Wed, 14 Sep 2022 09:57:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1DC683858015 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 imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 135F25CD46 for ; Wed, 14 Sep 2022 09:57:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1663149425; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=ujqb87VoQXAiPU1EZU+4xzuvxckYE3ijdyDGyeUDqOY=; b=aI2bH90XgclmliFe+reKWDcHvO3sMdHyucBdg9R/lx5idDOXVEZIdhFPoiBo4awV7akGE+ A47NhGINVa/xyOivBo+aLUcKIGkbg5dWaVPf59UTLpCEcq9EDWJJB44DDa1yf37/0cU3XX hVSRwmrNZutDSaLBbe0N7D4s0x4UlZk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1663149425; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=ujqb87VoQXAiPU1EZU+4xzuvxckYE3ijdyDGyeUDqOY=; b=2x3FfSBv2v0e4uX8X2FQw8RYEy1ZNSSCnfU0KxL1nTDScOpUn6laBh/1Mpi5aACvYLDWVI 6U3/wSpxTpYCaVDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 00384134B3 for ; Wed, 14 Sep 2022 09:57:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IplxOnClIWOcOgAAMHmgww (envelope-from ) for ; Wed, 14 Sep 2022 09:57:04 +0000 Date: Wed, 14 Sep 2022 11:57:04 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/106934 - avoid BIT_FIELD_REF of bitfields MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20220914095705.00384134B3@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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: The following avoids creating BIT_FIELD_REF of bitfields in update-address-taken. The patch doesn't implement punning to a full precision integer type but leaves a comment according to that. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/106934 * tree-ssa.cc (non_rewritable_mem_ref_base): Avoid BIT_FIELD_REFs of bitfields. (maybe_rewrite_mem_ref_base): Likewise. * gfortran.dg/pr106934.f90: New testcase. --- gcc/testsuite/gfortran.dg/pr106934.f90 | 7 +++++++ gcc/tree-ssa.cc | 6 ++++++ 2 files changed, 13 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr106934.f90 diff --git a/gcc/testsuite/gfortran.dg/pr106934.f90 b/gcc/testsuite/gfortran.dg/pr106934.f90 new file mode 100644 index 00000000000..ac58a3e82e3 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr106934.f90 @@ -0,0 +1,7 @@ +! { dg-do compile } +! { dg-options "-O" } +subroutine s + logical(1) :: a = .true. + logical(2) :: b + a = transfer(b, a) +end diff --git a/gcc/tree-ssa.cc b/gcc/tree-ssa.cc index 6507348e793..1a93ffdbd64 100644 --- a/gcc/tree-ssa.cc +++ b/gcc/tree-ssa.cc @@ -1459,6 +1459,8 @@ maybe_rewrite_mem_ref_base (tree *tp, bitmap suitable_for_renaming) && (! INTEGRAL_TYPE_P (TREE_TYPE (*tp)) || (wi::to_offset (TYPE_SIZE (TREE_TYPE (*tp))) == TYPE_PRECISION (TREE_TYPE (*tp)))) + && (! INTEGRAL_TYPE_P (TREE_TYPE (sym)) + || type_has_mode_precision_p (TREE_TYPE (sym))) && wi::umod_trunc (wi::to_offset (TYPE_SIZE (TREE_TYPE (*tp))), BITS_PER_UNIT) == 0) { @@ -1531,6 +1533,10 @@ non_rewritable_mem_ref_base (tree ref) && (! INTEGRAL_TYPE_P (TREE_TYPE (base)) || (wi::to_offset (TYPE_SIZE (TREE_TYPE (base))) == TYPE_PRECISION (TREE_TYPE (base)))) + /* ??? Likewise for extracts from bitfields, we'd have + to pun the base object to a size precision mode first. */ + && (! INTEGRAL_TYPE_P (TREE_TYPE (decl)) + || type_has_mode_precision_p (TREE_TYPE (decl))) && wi::umod_trunc (wi::to_offset (TYPE_SIZE (TREE_TYPE (base))), BITS_PER_UNIT) == 0) return NULL_TREE; -- 2.35.3