]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/106934 - avoid BIT_FIELD_REF of bitfields
authorRichard Biener <rguenther@suse.de>
Wed, 14 Sep 2022 07:00:35 +0000 (09:00 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 26 Jan 2023 13:05:09 +0000 (14:05 +0100)
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)

gcc/testsuite/gfortran.dg/pr106934.f90 [new file with mode: 0644]
gcc/tree-ssa.c

diff --git a/gcc/testsuite/gfortran.dg/pr106934.f90 b/gcc/testsuite/gfortran.dg/pr106934.f90
new file mode 100644 (file)
index 0000000..ac58a3e
--- /dev/null
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! { dg-options "-O" }
+subroutine s
+   logical(1) :: a = .true.
+   logical(2) :: b
+   a = transfer(b, a)
+end
index 4f4ab2b8992ae4bb258c763bb2a5442ea074d93b..e15cc54567a9530275ff336b9ab3c0cd88811ae4 100644 (file)
@@ -1409,6 +1409,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)
        {
@@ -1481,6 +1483,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;