Ai
23 Star 29 Fork 165

src-openEuler/gcc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0356-Avoid-doing-sfc-with-struct_split-and-compressing-de.patch 4.12 KB
一键复制 编辑 原始数据 按行查看 历史
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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/gcc.git
git@gitee.com:src-openeuler/gcc.git
src-openeuler
gcc
gcc
master

搜索帮助