public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/111916 - SRA of BIT_FIELD_REF of constant pool entries
Date: Mon, 23 Oct 2023 13:32:29 +0000 (UTC)	[thread overview]
Message-ID: <20231023133229.9E-OA_Ro9QcKecMwXLyN4-SM3Hqvr8bo9XLxD3Oscs0@z> (raw)

The following adjusts a leftover BIT_FIELD_REF special-casing to only
cover the cases general code doesn't handle.

Boostrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/111916
	* tree-sra.cc (sra_modify_assign): Do not lower all
	BIT_FIELD_REF reads that are sra_handled_bf_read_p.

	* gcc.dg/torture/pr111916.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr111916.c | 16 ++++++++++++++++
 gcc/tree-sra.cc                         |  3 ++-
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr111916.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr111916.c b/gcc/testsuite/gcc.dg/torture/pr111916.c
new file mode 100644
index 00000000000..2873045aaa4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr111916.c
@@ -0,0 +1,16 @@
+/* { dg-do run } */
+
+#pragma pack(1)
+struct A {
+  int b : 4;
+  int c : 11;
+  int d : 2;
+  int e : 5;
+} f;
+int main()
+{
+  struct A g = {1, 1, 1, 1};
+  while (!g.b)
+    f = g;
+  return 0;
+}
diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc
index f8dff8b27d7..b985dee6964 100644
--- a/gcc/tree-sra.cc
+++ b/gcc/tree-sra.cc
@@ -4275,7 +4275,8 @@ sra_modify_assign (gimple *stmt, gimple_stmt_iterator *gsi)
 
   if (TREE_CODE (rhs) == REALPART_EXPR || TREE_CODE (lhs) == REALPART_EXPR
       || TREE_CODE (rhs) == IMAGPART_EXPR || TREE_CODE (lhs) == IMAGPART_EXPR
-      || TREE_CODE (rhs) == BIT_FIELD_REF || TREE_CODE (lhs) == BIT_FIELD_REF)
+      || (TREE_CODE (rhs) == BIT_FIELD_REF && !sra_handled_bf_read_p (rhs))
+      || TREE_CODE (lhs) == BIT_FIELD_REF)
     {
       modify_this_stmt = sra_modify_expr (gimple_assign_rhs1_ptr (stmt),
 					  gsi, false);
-- 
2.35.3

                 reply	other threads:[~2023-10-23 13:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231023133229.9E-OA_Ro9QcKecMwXLyN4-SM3Hqvr8bo9XLxD3Oscs0@z \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).