代码拉取完成,页面将自动刷新
From 63b3db6e1f3e4aba90d76780fb64f6875c5dd2ab Mon Sep 17 00:00:00 2001
From: huzife <634763349@qq.com>
Date: Wed, 26 Feb 2025 01:24:45 +0800
Subject: [PATCH] Avoid doing sfc with struct_split and compressing dead fields
---
gcc/ipa-struct-reorg/ipa-struct-reorg.cc | 13 ++++++--
.../gcc.dg/struct/sfc-shadow_dead_field.c | 31 ++++++++++++++++++
gcc/testsuite/gcc.dg/struct/sfc_dead_field.c | 32 +++++++++++++++++++
3 files changed, 74 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/struct/sfc-shadow_dead_field.c
create mode 100644 gcc/testsuite/gcc.dg/struct/sfc_dead_field.c
diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.cc b/gcc/ipa-struct-reorg/ipa-struct-reorg.cc
index f2660c952..fcc26d6a4 100644
--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.cc
+++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.cc
@@ -8970,7 +8970,8 @@ void
ipa_struct_reorg::classify_fields (fc_type_info *info)
{
for (auto *srf : info->type->fields)
- info->record_field_class (srf);
+ if (!srf->dead_field_p ())
+ info->record_field_class (srf);
if (dump_file && (dump_flags & TDF_DETAILS))
{
@@ -8997,6 +8998,10 @@ ipa_struct_reorg::find_static_fc_fields (fc_type_info *info)
for (auto *srf : info->type->fields)
{
+ /* Skip dead field. */
+ if (srf->dead_field_p ())
+ continue;
+
/* Avoid compressing non-integer type. */
if (TREE_CODE (srf->fieldtype) != INTEGER_TYPE)
continue;
@@ -10064,7 +10069,8 @@ ipa_struct_reorg::execute (unsigned int opt)
check_and_prune_struct_for_pointer_compression ();
if (opt >= SEMI_RELAYOUT)
check_and_prune_struct_for_semi_relayout ();
- if (flag_ipa_struct_sfc)
+ /* Avoid doing static field compression in STRUCT_SPLIT. */
+ if (opt >= STRUCT_REORDER_FIELDS && flag_ipa_struct_sfc)
check_and_prune_struct_for_field_compression ();
ret = rewrite_functions ();
}
@@ -10148,6 +10154,9 @@ public:
if (level >= STRUCT_REORDER_FIELDS)
ret = ipa_struct_reorg ().execute (level);
+ if (ret & TODO_remove_functions)
+ symtab->remove_unreachable_nodes (dump_file);
+
if (level >= COMPLETE_STRUCT_RELAYOUT)
{
/* Preserved for backward compatibility.
diff --git a/gcc/testsuite/gcc.dg/struct/sfc-shadow_dead_field.c b/gcc/testsuite/gcc.dg/struct/sfc-shadow_dead_field.c
new file mode 100644
index 000000000..dbe8633cc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/struct/sfc-shadow_dead_field.c
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fipa-struct-reorg=3" } */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+struct arc {
+ unsigned long a;
+ unsigned long b;
+};
+typedef struct arc arc_t;
+
+#define MAX 16
+
+int main() {
+ arc_t* arcs = (arc_t*)calloc(MAX, sizeof(arc_t));
+ for (int i = 0; i < MAX; i++) {
+ arcs[i].a = i;
+ arcs[i].b = i;
+ }
+
+ for (int i = 0; i < MAX; i++) {
+ if (arcs[i].b != i)
+ abort ();
+ }
+
+ return 0;
+}
+
+
+/* { dg-final { scan-ipa-dump "\\\[field compress\\\] Fail finding static fc fields" "struct_reorg" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/sfc_dead_field.c b/gcc/testsuite/gcc.dg/struct/sfc_dead_field.c
new file mode 100644
index 000000000..ccd8339ab
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/struct/sfc_dead_field.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fipa-struct-reorg=3" } */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+struct arc {
+ unsigned long a;
+ unsigned long b;
+};
+typedef struct arc arc_t;
+
+#define MAX 16
+
+int main() {
+ arc_t* arcs = (arc_t*)calloc(MAX, sizeof(arc_t));
+ for (int i = 0; i < MAX; i++) {
+ arcs[i].a = 10000;
+ arcs[i].b = 10;
+ }
+
+ for (int i = 0; i < MAX; i++) {
+ if (arcs[i].a != 10000)
+ abort ();
+ }
+
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump "\\\[field compress\\\] Found a static compression field: a, max_value = 10000" "struct_reorg" } } */
+/* { dg-final { scan-ipa-dump "\\\[field compress\\\] Found a static compression field: b" "struct_reorg" { xfail *-*-* } } } */
+/* { dg-final { scan-ipa-dump "size : 2" "struct_reorg" } } */
--
2.33.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。