diff --git a/0055-Fix-some-bugs-in-semi-relayout.patch b/0055-Fix-some-bugs-in-semi-relayout.patch new file mode 100644 index 0000000000000000000000000000000000000000..442d550fee53b61642ec1e7fb86c1f4a33b0aa8b --- /dev/null +++ b/0055-Fix-some-bugs-in-semi-relayout.patch @@ -0,0 +1,102 @@ +From 29897454132482945bed91911c8f655bda5c6ca2 Mon Sep 17 00:00:00 2001 +From: benniaobufeijiushiji +Date: Mon, 18 Jul 2022 16:15:40 +0800 +Subject: [PATCH 1/2] [Bugfix] Fix some bugs in semi-relayout 1. do not + relayout a struct with only one field after DFE. 2. skip semi-relayout for + malloc + +--- + gcc/ipa-struct-reorg/ipa-struct-reorg.c | 26 ++++++++++++++++++++----- + 1 file changed, 21 insertions(+), 5 deletions(-) + +diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.c b/gcc/ipa-struct-reorg/ipa-struct-reorg.c +index ade1ed1a9..8470d2a8f 100644 +--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.c ++++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.c +@@ -923,8 +923,10 @@ srtype::calculate_bucket_size () + unsigned bit_sum = 0; + unsigned relayout_offset = 0; + unsigned curr_part_num = 0; // TODO: for spec17, fix when release ++ unsigned field_num = 0; + for (tree f = TYPE_FIELDS (newtype[0]); f; f = DECL_CHAIN (f)) + { ++ field_num++; + unsigned size = TYPE_PRECISION (TREE_TYPE (f)); + bit_sum += size; + if (++curr_part_num > 2 || bit_sum > 64) +@@ -940,6 +942,9 @@ srtype::calculate_bucket_size () + } + new_field_offsets.put (f, relayout_offset); + } ++ /* Donnot relayout a struct with only one field after DFE. */ ++ if (field_num == 1) ++ return 0; + bucket_parts = ++parts; + return parts * RELAYOUT_PART_SIZE; + } +@@ -1063,6 +1068,8 @@ srtype::create_new_type (void) + if (semi_relayout) + { + bucket_size = calculate_bucket_size (); ++ if (bucket_size == 0) ++ return false; + } + + if (dump_file && (dump_flags & TDF_DETAILS)) +@@ -1465,7 +1472,7 @@ public: + bool should_create = false, bool can_escape = false); + bool wholeaccess (tree expr, tree base, tree accesstype, srtype *t); + +- void check_alloc_num (gimple *stmt, srtype *type); ++ void check_alloc_num (gimple *stmt, srtype *type, bool ptrptr); + void check_definition_assign (srdecl *decl, vec &worklist); + void check_definition_call (srdecl *decl, vec &worklist); + void check_definition (srdecl *decl, vec&); +@@ -4641,7 +4648,7 @@ ipa_struct_reorg::check_type_and_push (tree newdecl, srdecl *decl, + } + + void +-ipa_struct_reorg::check_alloc_num (gimple *stmt, srtype *type) ++ipa_struct_reorg::check_alloc_num (gimple *stmt, srtype *type, bool ptrptr) + { + if ((current_mode == COMPLETE_STRUCT_RELAYOUT + || (current_mode == STRUCT_LAYOUT_OPTIMIZE +@@ -4651,6 +4658,14 @@ ipa_struct_reorg::check_alloc_num (gimple *stmt, srtype *type) + tree arg0 = gimple_call_arg (stmt, 0); + basic_block bb = gimple_bb (stmt); + cgraph_node *node = current_function->node; ++ if (!ptrptr && struct_layout_optimize_level >= SEMI_RELAYOUT ++ && 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. */ ++ type->has_alloc_array = -4; ++ return; ++ } + if (integer_onep (arg0)) + { + /* Actually NOT an array, but may ruin other array. */ +@@ -4791,8 +4806,8 @@ ipa_struct_reorg::check_definition_call (srdecl *decl, vec &worklist) + type->mark_escape (escape_return, stmt); + } + } +- +- check_alloc_num (stmt, type); ++ bool ptrptr = isptrptr (decl->orig_type); ++ check_alloc_num (stmt, type, ptrptr); + return; + } + +@@ -8714,7 +8729,8 @@ ipa_struct_reorg::check_and_prune_struct_for_semi_relayout (void) + continue; + } + if (type->has_alloc_array == 0 || type->has_alloc_array == 1 +- || type->has_alloc_array == -1 || type->has_alloc_array == -3) ++ || type->has_alloc_array == -1 || type->has_alloc_array == -3 ++ || type->has_alloc_array == -4) + { + if (dump_file) + { +-- +2.27.0 + diff --git a/0056-Bugfix-for-transpose-slp.patch b/0056-Bugfix-for-transpose-slp.patch new file mode 100644 index 0000000000000000000000000000000000000000..fb438badb99756394e9a28c8cb1990299f616e96 --- /dev/null +++ b/0056-Bugfix-for-transpose-slp.patch @@ -0,0 +1,46 @@ +From 70bf200fb54a38dab4e45f7ae8cce672d531e684 Mon Sep 17 00:00:00 2001 +From: benniaobufeijiushiji +Date: Mon, 18 Jul 2022 16:26:57 +0800 +Subject: [PATCH 2/2] [Bugfix] Bugfix for transpose slp Add limitationz: only + one dimesion array is supported. + +--- + gcc/tree-vect-slp.c | 15 ++++++++++++++- + 1 file changed, 14 insertions(+), 1 deletion(-) + +diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c +index e85f6c6bc..471316bb0 100644 +--- a/gcc/tree-vect-slp.c ++++ b/gcc/tree-vect-slp.c +@@ -2668,6 +2668,19 @@ check_and_clear_groups (vec current_groups, + } + } + ++/* Make sure that transpose slp vectorization is conducted only if grouped ++ stores are one dimension array ref. */ ++ ++static bool ++is_store_one_dim_array (gimple *stmt) ++{ ++ tree op = gimple_get_lhs (stmt); ++ if (TREE_CODE (op) != ARRAY_REF) ++ return false; ++ return TREE_OPERAND_LENGTH (op) > 0 ++ && TREE_OPERAND_LENGTH (TREE_OPERAND (op, 0)) == 0; ++} ++ + /* Set grouped_stores with similar MEM_REF to the same group and mark their + grp_num. Groups with same grp_num consist the minimum unit to analyze + transpose. Return num of such units. */ +@@ -2713,7 +2726,7 @@ vect_prepare_transpose (bb_vec_info bb_vinfo) + /* Beginning of a new group to analyze whether they are able to consist + a unit to conduct transpose analysis. */ + first_element = NULL; +- if (TREE_CODE (gimple_get_lhs (current_element->stmt)) == ARRAY_REF ++ if (is_store_one_dim_array (current_element->stmt) + && check_filling_reg (current_element) + && record_innermost (innermost_inits, innermost_offsets, + current_element)) +-- +2.27.0 + diff --git a/0057-ArrayWidenCompare-Fixed-the-issue-that-SSA_NAME_VAR-.patch b/0057-ArrayWidenCompare-Fixed-the-issue-that-SSA_NAME_VAR-.patch new file mode 100644 index 0000000000000000000000000000000000000000..4912dad4a6ffebd6929055c0b0801819a7b6c32a --- /dev/null +++ b/0057-ArrayWidenCompare-Fixed-the-issue-that-SSA_NAME_VAR-.patch @@ -0,0 +1,121 @@ +From c7edeebecb4cf000e250116a51fdeea84ea9462f Mon Sep 17 00:00:00 2001 +From: dingguangya +Date: Mon, 11 Jul 2022 20:33:45 +0800 +Subject: [PATCH] [ArrayWidenCompare] Fixed the issue that SSA_NAME_VAR was + applicable before use in some scenarios + +Fix the problem: Make sure that the tree node is SSA_NAME before using SSA_NAME_VAR, +otherwise an error will occur in some scenarios + +diff --git a/gcc/tree-ssa-loop-array-widen-compare.c b/gcc/tree-ssa-loop-array-widen-compare.c +index baa41a655..306438bed 100644 +--- a/gcc/tree-ssa-loop-array-widen-compare.c ++++ b/gcc/tree-ssa-loop-array-widen-compare.c +@@ -309,6 +309,30 @@ fail: + return found; + } + ++/* Returns true if t is SSA_NAME and user variable exists. */ ++ ++static bool ++ssa_name_var_p (tree t) ++{ ++ if (!t || TREE_CODE (t) != SSA_NAME) ++ return false; ++ if (SSA_NAME_VAR (t)) ++ return true; ++ return false; ++} ++ ++/* Returns true if t1 and t2 are SSA_NAME and belong to the same variable. */ ++ ++static bool ++same_ssa_name_var_p (tree t1, tree t2) ++{ ++ if (!ssa_name_var_p (t1) || !ssa_name_var_p (t2)) ++ return false; ++ if (SSA_NAME_VAR (t1) == SSA_NAME_VAR (t2)) ++ return true; ++ return false; ++} ++ + /* Get origin loop induction variable upper bound. */ + + static bool +@@ -326,9 +350,9 @@ get_iv_upper_bound (gimple *stmt) + + gimple *g = SSA_NAME_DEF_STMT (rhs); + +- if (SSA_NAME_VAR (rhs) && TREE_CODE (SSA_NAME_VAR (rhs)) == PARM_DECL ++ if (ssa_name_var_p (rhs) && TREE_CODE (SSA_NAME_VAR (rhs)) == PARM_DECL + && g && gimple_code (g) == GIMPLE_NOP +- && (SSA_NAME_VAR (lhs) && TREE_CODE (SSA_NAME_VAR (lhs)) != PARM_DECL)) ++ && (ssa_name_var_p (lhs) && TREE_CODE (SSA_NAME_VAR (lhs)) != PARM_DECL)) + { + origin_loop.limit = rhs; + } +@@ -356,7 +380,7 @@ check_update_stmt (gimple *stmt) + tree rhs1 = gimple_assign_rhs1 (stmt); + tree rhs2 = gimple_assign_rhs2 (stmt); + if (TREE_CODE (rhs1) == SSA_NAME && TREE_CODE (rhs2) == INTEGER_CST +- && SSA_NAME_VAR (rhs1) == SSA_NAME_VAR (origin_loop.base)) ++ && same_ssa_name_var_p (rhs1, origin_loop.base)) + { + origin_loop.step = tree_to_uhwi (rhs2); + if (origin_loop.step == 1) +@@ -386,11 +410,10 @@ get_iv_base (gimple *stmt) + { + gphi *phi = gsi.phi (); + tree res = gimple_phi_result (phi); +- if (!SSA_NAME_VAR (res) || SSA_NAME_VAR (res) != SSA_NAME_VAR (lhs)) ++ if (!same_ssa_name_var_p (res, lhs)) + continue; + tree base = PHI_ARG_DEF_FROM_EDGE (phi, origin_loop.entry_edge); +- if (!base || !SSA_NAME_VAR (base) +- || SSA_NAME_VAR (base) != SSA_NAME_VAR (lhs)) ++ if (!same_ssa_name_var_p (base, lhs)) + return false; + origin_loop.base = base; + FOR_EACH_EDGE (e, ei, header->preds) +@@ -527,8 +550,7 @@ check_body_pointer_plus (gimple *stmt, tree &tmp_index) + if (g && gimple_assign_rhs_code (g) == NOP_EXPR) + { + tree nop_rhs = gimple_assign_rhs1 (g); +- if (SSA_NAME_VAR (nop_rhs) +- && SSA_NAME_VAR (nop_rhs) == SSA_NAME_VAR (origin_loop.base)) ++ if (same_ssa_name_var_p (nop_rhs, origin_loop.base)) + { + if (!origin_loop.arr1) + { +@@ -603,8 +625,7 @@ record_origin_loop_body (class loop *loop) + else if (gimple_assign_rhs_code (g) == NOP_EXPR) + { + tree rhs = gimple_assign_rhs1 (g); +- if (!SSA_NAME_VAR (rhs) +- || SSA_NAME_VAR (rhs) != SSA_NAME_VAR (origin_loop.base)) ++ if (!same_ssa_name_var_p (rhs, origin_loop.base)) + return false; + stack.safe_push (rhs); + } +@@ -675,8 +696,7 @@ check_exit_bb (class loop *loop) + { + gphi *phi = gsi.phi (); + tree res = gimple_phi_result (phi); +- if (!SSA_NAME_VAR (res) +- || SSA_NAME_VAR (res) != SSA_NAME_VAR (origin_loop.base)) ++ if (!same_ssa_name_var_p (res, origin_loop.base)) + continue; + if (gimple_phi_num_args (phi) == 2) + { +@@ -907,7 +927,7 @@ rewrite_add_phi_arg (basic_block bb) + if (PHI_ARG_DEF_FROM_EDGE (phi, e)) + continue; + tree var = *(defs_map.get (e->src)); +- if (!SSA_NAME_VAR (var) || (SSA_NAME_VAR (var) != SSA_NAME_VAR (res))) ++ if (!same_ssa_name_var_p (var, res)) + continue; + if (virtual_operand_p (var)) + loc = UNKNOWN_LOCATION; +-- +2.33.0.windows.2 + diff --git a/gcc.spec b/gcc.spec index feefe63dfc51570a6eec48bf701aa11d7d85d60e..6d6b92aecd20597a1c85b6c883e3221e02ba4999 100644 --- a/gcc.spec +++ b/gcc.spec @@ -61,7 +61,7 @@ Summary: Various compilers (C, C++, Objective-C, ...) Name: gcc Version: %{gcc_version} -Release: 14 +Release: 15 License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD URL: https://gcc.gnu.org @@ -171,6 +171,9 @@ Patch51: 0051-DFE-fixme.patch Patch52: 0052-SemiRelayout-structure-Semi-Relayout.patch Patch53: 0053-Loop-distribution-and-SLP-Bugfix.patch Patch54: 0054-Semi-relayout-Bugfix.patch +Patch55: 0055-Fix-some-bugs-in-semi-relayout.patch +Patch56: 0056-Bugfix-for-transpose-slp.patch +Patch57: 0057-ArrayWidenCompare-Fixed-the-issue-that-SSA_NAME_VAR-.patch %global gcc_target_platform %{_arch}-linux-gnu @@ -672,7 +675,9 @@ This package includes jemalloc, mathlib and stringlib %patch52 -p1 %patch53 -p1 %patch54 -p1 - +%patch55 -p1 +%patch56 -p1 +%patch57 -p1 %build @@ -2660,6 +2665,12 @@ end %endif %changelog +* Mon Jul 18 2022 benniaobufeijiushiji - 10.3.1-15 +- Type:Bugfix +- ID:NA +- SUG:NA +- DESC:Bugfix for transpose-slp, semi-relayout and array-widen-compare. + * Thu Jul 7 2022 benniaobufeijiushiji - 10.3.1-14 - Type:Bugfix - ID:NA