diff --git a/0365-Struct-reorg-Re-enable-malloc-support-below-ptr_comp.patch b/0365-Struct-reorg-Re-enable-malloc-support-below-ptr_comp.patch new file mode 100644 index 0000000000000000000000000000000000000000..dee1eb291cce52bfc849fd76961f295c7ffea880 --- /dev/null +++ b/0365-Struct-reorg-Re-enable-malloc-support-below-ptr_comp.patch @@ -0,0 +1,139 @@ +From e8b6cb5692c56a64507a5593533437663c88147d Mon Sep 17 00:00:00 2001 +From: liyancheng <412998149@qq.com> +Date: Fri, 14 Mar 2025 15:06:14 +0800 +Subject: [PATCH] [Struct-reorg] Re-enable malloc support below ptr_compression + +Since we found that completely disabling malloc support casued +some expected scenarious to not be optimized properly, we have +reopend malloc support below the pointer compression opt level. +--- + gcc/ipa-struct-reorg/ipa-struct-reorg.cc | 8 +++-- + gcc/testsuite/gcc.dg/struct/dfe_ptr_ptr.c | 2 +- + .../gcc.dg/struct/rf_create_fields_bug.c | 2 +- + gcc/testsuite/gcc.dg/struct/rf_ptr_ptr.c | 2 +- + .../gcc.dg/struct/rf_rewrite_cond_more_cmp.c | 4 +-- + .../gcc.dg/struct/sfc-shadow_malloc.c | 29 +++++++++++++++++++ + 6 files changed, 39 insertions(+), 8 deletions(-) + create mode 100644 gcc/testsuite/gcc.dg/struct/sfc-shadow_malloc.c + +diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.cc b/gcc/ipa-struct-reorg/ipa-struct-reorg.cc +index bf88c02fd..b8a5f029c 100644 +--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.cc ++++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.cc +@@ -4042,6 +4042,7 @@ ipa_struct_reorg::handled_allocation_stmt (gimple *stmt) + { + if ((current_layout_opt_level & STRUCT_REORDER_FIELDS) + && (gimple_call_builtin_p (stmt, BUILT_IN_REALLOC) ++ || gimple_call_builtin_p (stmt, BUILT_IN_MALLOC) + || gimple_call_builtin_p (stmt, BUILT_IN_CALLOC))) + return true; + if ((current_layout_opt_level == COMPLETE_STRUCT_RELAYOUT +@@ -4850,12 +4851,13 @@ ipa_struct_reorg::check_alloc_num (gimple *stmt, srtype *type, bool ptrptr) + tree arg0 = gimple_call_arg (stmt, 0); + basic_block bb = gimple_bb (stmt); + cgraph_node *node = current_function->node; +- if (!ptrptr && current_layout_opt_level >= SEMI_RELAYOUT ++ if (!ptrptr && current_layout_opt_level >= POINTER_COMPRESSION_SAFE + && gimple_call_builtin_p (stmt, BUILT_IN_MALLOC)) + { + /* Malloc is commonly used for allocations of +- a single struct and semi-relayout will waste +- a mess of memory, so we skip it. */ ++ a single struct, it is no meaning to do pointer ++ compression, and semi-relayout will waste a mess ++ of memory, so we skip it. */ + type->has_alloc_array = -4; + return; + } +diff --git a/gcc/testsuite/gcc.dg/struct/dfe_ptr_ptr.c b/gcc/testsuite/gcc.dg/struct/dfe_ptr_ptr.c +index 3cb473663..b91efe10f 100644 +--- a/gcc/testsuite/gcc.dg/struct/dfe_ptr_ptr.c ++++ b/gcc/testsuite/gcc.dg/struct/dfe_ptr_ptr.c +@@ -47,7 +47,7 @@ arc_t **ap = NULL; + int + main () + { +- ap = (arc_t**) calloc(MAX, sizeof(arc_t*)); ++ ap = (arc_t**) malloc(MAX * sizeof(arc_t*)); + (*ap)[0].id = 300; + return 0; + } +diff --git a/gcc/testsuite/gcc.dg/struct/rf_create_fields_bug.c b/gcc/testsuite/gcc.dg/struct/rf_create_fields_bug.c +index 91ba80891..17ca1c7e1 100644 +--- a/gcc/testsuite/gcc.dg/struct/rf_create_fields_bug.c ++++ b/gcc/testsuite/gcc.dg/struct/rf_create_fields_bug.c +@@ -74,7 +74,7 @@ main() + { + abort (); + } +- ap = (arc_t**) calloc(MAX, sizeof(arc_t*)); ++ ap = (arc_t**) malloc(MAX * sizeof(arc_t*)); + (*ap)[0].id = 300; + return 0; + } +diff --git a/gcc/testsuite/gcc.dg/struct/rf_ptr_ptr.c b/gcc/testsuite/gcc.dg/struct/rf_ptr_ptr.c +index 9d396e39a..f38d94861 100644 +--- a/gcc/testsuite/gcc.dg/struct/rf_ptr_ptr.c ++++ b/gcc/testsuite/gcc.dg/struct/rf_ptr_ptr.c +@@ -47,7 +47,7 @@ arc_t **ap = NULL; + int + main () + { +- ap = (arc_t**) calloc(MAX, sizeof(arc_t*)); ++ ap = (arc_t**) malloc(MAX * sizeof(arc_t*)); + (*ap)[0].id = 300; + return 0; + } +diff --git a/gcc/testsuite/gcc.dg/struct/rf_rewrite_cond_more_cmp.c b/gcc/testsuite/gcc.dg/struct/rf_rewrite_cond_more_cmp.c +index ca8333601..46dd55bbd 100644 +--- a/gcc/testsuite/gcc.dg/struct/rf_rewrite_cond_more_cmp.c ++++ b/gcc/testsuite/gcc.dg/struct/rf_rewrite_cond_more_cmp.c +@@ -44,8 +44,8 @@ struct arc + int + main() + { +- arc_p **ap = (arc_p**) calloc(1, sizeof(arc_p*)); +- arc_p **arcs_pointer_sorted = (arc_p**) calloc(1, sizeof(arc_p*)); ++ arc_p **ap = (arc_p**) malloc(1 * sizeof(arc_p*)); ++ arc_p **arcs_pointer_sorted = (arc_p**) malloc(1 * sizeof(arc_p*)); + arcs_pointer_sorted[0] = (arc_p*) calloc (1, sizeof(arc_p)); + + if (arcs_pointer_sorted >= ap) +diff --git a/gcc/testsuite/gcc.dg/struct/sfc-shadow_malloc.c b/gcc/testsuite/gcc.dg/struct/sfc-shadow_malloc.c +new file mode 100644 +index 000000000..92112df20 +--- /dev/null ++++ b/gcc/testsuite/gcc.dg/struct/sfc-shadow_malloc.c +@@ -0,0 +1,29 @@ ++/* { dg-do compile } */ ++ ++#include ++#include ++ ++struct arc { ++ unsigned long a; ++ unsigned long b; ++}; ++typedef struct arc arc_t; ++ ++#define MAX 16 ++ ++int main() { ++ arc_t* arcs = (arc_t*)malloc(MAX * sizeof(arc_t)); ++ for (int i = 0; i < MAX; i++) { ++ arcs[i].a = 0; ++ } ++ ++ for (int i = 0; i < MAX; i++) { ++ arcs[i].a = i; ++ arcs[i].b = i; ++ } ++ printf("%d, %d\n", arcs[10].a, arcs[10].b); ++ ++ return 0; ++} ++ ++/* { dg-final { scan-ipa-dump "\\\[field compress\\\] Fail finding shadow field" "struct_reorg" } } */ +-- +2.33.0 + diff --git a/gcc.spec b/gcc.spec index cde2d7738bf49387a480da30d134cde8ff3a613c..ad532d4634fa2160a0c3f45de1bad4114533bc8e 100644 --- a/gcc.spec +++ b/gcc.spec @@ -2,7 +2,7 @@ %global gcc_major 12 # Note, gcc_release must be integer, if you want to add suffixes to # %%{release}, append them after %%{gcc_release} on Release: line. -%global gcc_release 80 +%global gcc_release 81 %global _unpackaged_files_terminate_build 0 %global _performance_build 1 @@ -470,6 +470,7 @@ Patch361: 0361-tracer-static-Fix-divide-by-zero-error.patch Patch362: 0362-fix-prefetch-case-failed.patch Patch363: 0363-llc-feature-bugfix.patch Patch364: 0364-fix-llc-feature-case-failed.patch +Patch365: 0365-Struct-reorg-Re-enable-malloc-support-below-ptr_comp.patch # Part 1001-1999 %ifarch sw_64 @@ -1620,6 +1621,7 @@ not stable, so plugins must be rebuilt any time GCC is updated. %patch -P362 -p1 %patch -P363 -p1 %patch -P364 -p1 +%patch -P365 -p1 %ifarch sw_64 %patch -P1001 -p1 @@ -4257,6 +4259,10 @@ end %doc rpm.doc/changelogs/libcc1/ChangeLog* %changelog +* Wed Mar 19 2025 liyancheng <412998149@qq.com> - 12.3.1-81 +- Type:Bugfix +- DESC: Re-enable malloc support below ptr_compression + * Sat Mar 15 2025 chenhong - 12.3.1-80 - Type:Bugfix - ID:NA