]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/111916 - SRA of BIT_FIELD_REF of constant pool entries
authorRichard Biener <rguenther@suse.de>
Mon, 23 Oct 2023 12:08:41 +0000 (14:08 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 23 Oct 2023 13:30:02 +0000 (15:30 +0200)
The following adjusts a leftover BIT_FIELD_REF special-casing to only
cover the cases general code doesn't handle.

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 [new file with mode: 0644]
gcc/tree-sra.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr111916.c b/gcc/testsuite/gcc.dg/torture/pr111916.c
new file mode 100644 (file)
index 0000000..2873045
--- /dev/null
@@ -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;
+}
index f8dff8b27d76737a65fffc86b284bff131da6563..b985dee6964d89d757488b336e63c5357d3bf77f 100644 (file)
@@ -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);