From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 30E19385801A; Mon, 17 Oct 2022 13:28:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30E19385801A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666013290; bh=LUc3/jp1wwed+hBb0zJyxN13f9UK33PNrZzlKpJyn90=; h=From:To:Subject:Date:From; b=P6XBryzP89L+TNbGhZsRfryi8SHaM9JcOcwb8QMheRPUs2w+L7N/SlMbJfhOjMVZI uGQ9VzT2sGmVjROmverru48xStiFV0KRLDgJE2EE76FDQdaUTasCfdWi++30NaY/tm HkDJhAJro0BRGbBqStrDCtKDGZHFbYUfky8puH3s= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10318] tree-optimization/106934 - avoid BIT_FIELD_REF of bitfields X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: d4bcab0b622cf8f2b6aadd982155c7e2d37d5887 X-Git-Newrev: 2bb2560ae196df515cfea9161a27ee86a1594777 Message-Id: <20221017132810.30E19385801A@sourceware.org> Date: Mon, 17 Oct 2022 13:28:10 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2bb2560ae196df515cfea9161a27ee86a1594777 commit r11-10318-g2bb2560ae196df515cfea9161a27ee86a1594777 Author: Richard Biener Date: Wed Sep 14 09:00:35 2022 +0200 tree-optimization/106934 - avoid BIT_FIELD_REF of bitfields 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. PR tree-optimization/106934 * tree-ssa.c (non_rewritable_mem_ref_base): Avoid BIT_FIELD_REFs of bitfields. (maybe_rewrite_mem_ref_base): Likewise. * gfortran.dg/pr106934.f90: New testcase. (cherry picked from commit 05f5c42cb42c5088187d44cc45a5f671d19ad8c5) Diff: --- gcc/testsuite/gfortran.dg/pr106934.f90 | 7 +++++++ gcc/tree-ssa.c | 6 ++++++ 2 files changed, 13 insertions(+) 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.c b/gcc/tree-ssa.c index 28a7f4f02c9..41959ca03f8 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -1416,6 +1416,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) { @@ -1488,6 +1490,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;