[Sync] Sync patches from openeuler/gcc.

This commit is contained in:
郑晨卉 2023-12-23 17:19:36 +08:00
parent 63f041247e
commit 2fcfd4d48f
5 changed files with 379 additions and 1 deletions

168
0177-Fix-sqlite-build.patch Normal file
View File

@ -0,0 +1,168 @@
From 71a992aca88f63ec1afb1608619b82a857d8e297 Mon Sep 17 00:00:00 2001
From: Diachkov Ilia <diachkov.ilia1@huawei-partners.com>
Date: Fri, 22 Dec 2023 10:11:24 +0800
Subject: [PATCH 1/4] Fix sqlite build
---
gcc/ipa-prefetch.c | 71 ++++++++++++++++++++++++++--------------------
gcc/ipa-sra.c | 7 +++++
2 files changed, 47 insertions(+), 31 deletions(-)
diff --git a/gcc/ipa-prefetch.c b/gcc/ipa-prefetch.c
index d8bb9a251..371702ad8 100644
--- a/gcc/ipa-prefetch.c
+++ b/gcc/ipa-prefetch.c
@@ -1092,6 +1092,15 @@ analyse_loops ()
memref_t *mr = it->first, *mr2 = it->second;
if (mr2 == NULL || !(*fmrs_map)[fn]->count (mr))
continue;
+ /* For now optimize only MRs that mem is MEM_REF.
+ TODO: support other MR types. */
+ if (TREE_CODE (mr->mem) != MEM_REF)
+ {
+ if (dump_file)
+ fprintf (dump_file, "Skip MR %d: unsupported tree code = %s\n",
+ mr->mr_id, get_tree_code_name (TREE_CODE (mr->mem)));
+ continue;
+ }
if (!optimize_mrs_map->count (fn))
(*optimize_mrs_map)[fn] = new memref_set;
(*optimize_mrs_map)[fn]->insert (mr);
@@ -1104,7 +1113,7 @@ analyse_loops ()
it != (*optimize_mrs_map)[fn]->end (); it++)
{
memref_t *mr = *it, *mr2 = (*mr_candidate_map)[mr];
- fprintf (dump_file, "MRs %d,%d with incremental offset ",
+ fprintf (dump_file, "MRs %d, %d with incremental offset ",
mr->mr_id, mr2->mr_id);
print_generic_expr (dump_file, mr2->offset);
fprintf (dump_file, "\n");
@@ -1437,6 +1446,27 @@ remap_gimple_op_r (tree *tp, int *walk_subtrees, void *data)
return NULL_TREE;
}
+/* Copy stmt and remap its operands. */
+
+static gimple *
+gimple_copy_and_remap (gimple *stmt)
+{
+ gimple *copy = gimple_copy (stmt);
+ gcc_checking_assert (!is_gimple_debug (copy));
+
+ /* Remap all the operands in COPY. */
+ struct walk_stmt_info wi;
+ memset (&wi, 0, sizeof (wi));
+ wi.info = copy;
+ walk_gimple_op (copy, remap_gimple_op_r, &wi);
+ if (dump_file)
+ {
+ fprintf (dump_file, "Stmt copy after remap:\n");
+ print_gimple_stmt (dump_file, copy, 0);
+ }
+ return copy;
+}
+
static void
create_cgraph_edge (cgraph_node *n, gimple *stmt)
{
@@ -1585,7 +1615,6 @@ optimize_function (cgraph_node *n, function *fn)
/* Create other new vars. Insert new stmts. */
struct walk_stmt_info wi;
stmt_set processed_stmts;
- memref_tree_map mr_new_trees;
for (memref_set::const_iterator it = used_mrs.begin ();
it != used_mrs.end (); it++)
{
@@ -1606,23 +1635,10 @@ optimize_function (cgraph_node *n, function *fn)
}
/* Create a new copy of STMT and duplicate STMT's virtual
operands. */
- gimple *copy = gimple_copy (mr->stmts[i]);
- gcc_checking_assert (!is_gimple_debug (copy));
-
- /* Remap all the operands in COPY. */
- memset (&wi, 0, sizeof (wi));
- last_stmt = copy;
- wi.info = copy;
- walk_gimple_op (copy, remap_gimple_op_r, &wi);
- if (dump_file)
- {
- fprintf (dump_file, "Stmt %d after remap:\n",i);
- print_gimple_stmt (dump_file, copy, 0);
- }
- gimple_seq_add_stmt (&stmts, copy);
+ last_stmt = gimple_copy_and_remap (mr->stmts[i]);
+ gimple_seq_add_stmt (&stmts, last_stmt);
}
gcc_assert (last_stmt);
- mr_new_trees[mr] = gimple_assign_lhs (last_stmt);
if (dump_file)
{
fprintf (dump_file, "MR (%d) new mem: ", mr->mr_id);
@@ -1664,23 +1680,11 @@ optimize_function (cgraph_node *n, function *fn)
continue;
processed_stmts.insert (mr->stmts[i]);
- gimple *copy = gimple_copy (mr->stmts[i]);
- gcc_checking_assert (!is_gimple_debug (copy));
-
- /* Remap all the operands in COPY. */
- memset (&wi, 0, sizeof (wi));
- wi.info = copy;
- walk_gimple_op (copy, remap_gimple_op_r, &wi);
- if (dump_file)
- {
- fprintf (dump_file, "Stmt %d after remap:\n",i);
- print_gimple_stmt (dump_file, copy, 0);
- }
+ gimple *copy = gimple_copy_and_remap (mr->stmts[i]);
gimple_seq_add_stmt (&stmts, copy);
}
gimple *last_stmt = mr->stmts[0];
gcc_assert (last_stmt);
- mr_new_trees[mr] = gimple_assign_lhs (last_stmt);
tree write_p = mr->is_store ? integer_one_node : integer_zero_node;
tree addr = get_mem_ref_address_ssa_name (mr->mem, NULL_TREE);
if (decl_map->count (addr))
@@ -1689,6 +1693,11 @@ optimize_function (cgraph_node *n, function *fn)
3, addr, write_p, local);
pcalls.safe_push (last_stmt);
gimple_seq_add_stmt (&stmts, last_stmt);
+ if (dump_file)
+ {
+ fprintf (dump_file, "Insert %d prefetch stmt:\n", j);
+ print_gimple_stmt (dump_file, last_stmt, 0);
+ }
}
gsi_insert_seq_after (&gsi, stmts, GSI_NEW_STMT);
@@ -1827,7 +1836,7 @@ pass_ipa_prefetch::gate (function *)
/* Don't bother doing anything if the program has errors. */
&& !seen_error ()
&& flag_lto_partition == LTO_PARTITION_ONE
- /* Only enable struct optimizations in lto or whole_program. */
+ /* Only enable prefetch optimizations in lto or whole_program. */
&& (in_lto_p || flag_whole_program));
}
diff --git a/gcc/ipa-sra.c b/gcc/ipa-sra.c
index d7019ec42..ee927bf6a 100644
--- a/gcc/ipa-sra.c
+++ b/gcc/ipa-sra.c
@@ -3448,6 +3448,13 @@ param_splitting_across_edge (cgraph_edge *cs)
gcc_checking_assert (from_ifs && from_ifs->m_parameters);
isra_call_summary *csum = call_sums->get (cs);
+ /* TODO: implement better support for call edges inserted after summary
+ collection but before sra wpa invocation. */
+ if (!csum)
+ {
+ csum = call_sums->get_create (cs);
+ csum->m_return_ignored = true;
+ }
gcc_checking_assert (csum);
unsigned args_count = csum->m_arg_flow.length ();
isra_func_summary *to_ifs = func_sums->get (callee);
--
2.33.0

View File

@ -0,0 +1,52 @@
From b187b3043c5a7aa96e6d1106e4b0f37d14c914a6 Mon Sep 17 00:00:00 2001
From: Diachkov Ilia <diachkov.ilia1@huawei-partners.com>
Date: Fri, 22 Dec 2023 11:39:09 +0800
Subject: [PATCH 2/4] Fix freetype build
---
gcc/ipa-prefetch.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/gcc/ipa-prefetch.c b/gcc/ipa-prefetch.c
index 371702ad8..f91ac3edc 100644
--- a/gcc/ipa-prefetch.c
+++ b/gcc/ipa-prefetch.c
@@ -1522,6 +1522,13 @@ optimize_function (cgraph_node *n, function *fn)
"Skip the case.\n");
return 0;
}
+ if (!tree_fits_shwi_p (inc_mr->step))
+ {
+ if (dump_file)
+ fprintf (dump_file, "Cannot represent incremental MR's step as "
+ "integer. Skip the case.\n");
+ return 0;
+ }
if (dump_file && !used_mrs.empty ())
print_mrs_ids (used_mrs, "Common list of used mrs:\n");
@@ -1607,13 +1614,19 @@ optimize_function (cgraph_node *n, function *fn)
else
inc_code = PLUS_EXPR;
tree step = inc_mr->step;
- unsigned dist_val = tree_to_uhwi (step) * param_ipa_prefetch_distance_factor;
+ HOST_WIDE_INT dist_val = tree_to_shwi (step)
+ * param_ipa_prefetch_distance_factor;
tree dist = build_int_cst (TREE_TYPE (step), dist_val);
tree new_inc_var = gimple_build (&stmts, inc_code, var_type, inc_var, dist);
(*decl_map)[inc_var] = new_inc_var;
+ if (dump_file)
+ {
+ fprintf (dump_file, "New distance value: %ld, new inc var: ", dist_val);
+ print_generic_expr (dump_file, new_inc_var);
+ fprintf (dump_file, "\n");
+ }
/* Create other new vars. Insert new stmts. */
- struct walk_stmt_info wi;
stmt_set processed_stmts;
for (memref_set::const_iterator it = used_mrs.begin ();
it != used_mrs.end (); it++)
--
2.33.0

View File

@ -0,0 +1,29 @@
From 3d1b0da292e383ce2a139c1612ec7e07336bbcd8 Mon Sep 17 00:00:00 2001
From: vchernon <chernonog.vyacheslav@huawei.com>
Date: Fri, 22 Dec 2023 22:05:27 +0800
Subject: [PATCH 3/4] [rtl-ifcvt] refuse to rename def in the last instruction
in BB
---
gcc/ifcvt.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index 3df0f6fdd..025eb6cd1 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -2176,7 +2176,10 @@ noce_rename_regs_in_bb (basic_block test_bb, bitmap rename_regs)
rtx x = SET_DEST (sset);
if (!REG_P (x) || !bitmap_bit_p (rename_regs, REGNO (x)))
continue;
-
+ /* Do not need to rename dest in the last instruction
+ it will be renamed anyway. */
+ if (insn == last_insn)
+ continue;
machine_mode mode = GET_MODE (x);
rtx tmp = gen_reg_rtx (mode);
if (!validate_replace_rtx_part (x, tmp, &SET_DEST (sset), insn))
--
2.33.0

115
0180-Fix-issue-I8QD9H.patch Normal file
View File

@ -0,0 +1,115 @@
From 25f1ebeb88a4eae247f58488cac9da878f188d9f Mon Sep 17 00:00:00 2001
From: Diachkov Ilia <diachkov.ilia1@huawei-partners.com>
Date: Sat, 23 Dec 2023 10:05:10 +0800
Subject: [PATCH 4/4] Fix issue I8QD9H
---
gcc/ipa-prefetch.c | 64 +++++++++++++++++++++++++++-------------------
1 file changed, 37 insertions(+), 27 deletions(-)
diff --git a/gcc/ipa-prefetch.c b/gcc/ipa-prefetch.c
index f91ac3edc..a471b118e 100644
--- a/gcc/ipa-prefetch.c
+++ b/gcc/ipa-prefetch.c
@@ -1467,6 +1467,31 @@ gimple_copy_and_remap (gimple *stmt)
return copy;
}
+/* Copy and remap stmts listed in MR in reverse order to last_idx, skipping
+ processed ones. Insert new stmts to the sequence. */
+
+static gimple *
+gimple_copy_and_remap_memref_stmts (memref_t *mr, gimple_seq &stmts,
+ int last_idx, stmt_set &processed)
+{
+ gimple *last_stmt = NULL;
+ for (int i = mr->stmts.length () - 1; i >= last_idx ; i--)
+ {
+ if (processed.count (mr->stmts[i]))
+ continue;
+ processed.insert (mr->stmts[i]);
+ if (dump_file)
+ {
+ fprintf (dump_file, "Copy stmt %d from used MR (%d):\n",
+ i, mr->mr_id);
+ print_gimple_stmt (dump_file, mr->stmts[i], 0);
+ }
+ last_stmt = gimple_copy_and_remap (mr->stmts[i]);
+ gimple_seq_add_stmt (&stmts, last_stmt);
+ }
+ return last_stmt;
+}
+
static void
create_cgraph_edge (cgraph_node *n, gimple *stmt)
{
@@ -1606,7 +1631,16 @@ optimize_function (cgraph_node *n, function *fn)
decl_map = new tree_map;
gcc_assert (comp_mr->stmts[0] && gimple_assign_single_p (comp_mr->stmts[0]));
tree inc_var = gimple_assign_lhs (comp_mr->stmts[0]);
+ /* If old_var definition dominates the current use, just use it, otherwise
+ evaluate it just before new inc var evaluation. */
gimple_seq stmts = NULL;
+ stmt_set processed_stmts;
+ if (!dominated_by_p (CDI_DOMINATORS, dom_bb, gimple_bb (comp_mr->stmts[0])))
+ {
+ gimple *tmp = gimple_copy_and_remap_memref_stmts (comp_mr, stmts, 0,
+ processed_stmts);
+ inc_var = gimple_assign_lhs (tmp);
+ }
tree var_type = TREE_TYPE (inc_var);
enum tree_code inc_code;
if (TREE_CODE (var_type) == POINTER_TYPE)
@@ -1627,30 +1661,14 @@ optimize_function (cgraph_node *n, function *fn)
}
/* Create other new vars. Insert new stmts. */
- stmt_set processed_stmts;
for (memref_set::const_iterator it = used_mrs.begin ();
it != used_mrs.end (); it++)
{
memref_t *mr = *it;
- gimple *last_stmt = NULL;
if (mr == comp_mr)
continue;
- for (int i = mr->stmts.length () - 1; i >= 0 ; i--)
- {
- if (processed_stmts.count (mr->stmts[i]))
- continue;
- processed_stmts.insert (mr->stmts[i]);
- if (dump_file)
- {
- fprintf (dump_file, "Copy stmt %d from used MR (%d):\n",
- i, mr->mr_id);
- print_gimple_stmt (dump_file, mr->stmts[i], 0);
- }
- /* Create a new copy of STMT and duplicate STMT's virtual
- operands. */
- last_stmt = gimple_copy_and_remap (mr->stmts[i]);
- gimple_seq_add_stmt (&stmts, last_stmt);
- }
+ gimple *last_stmt = gimple_copy_and_remap_memref_stmts (mr, stmts, 0,
+ processed_stmts);
gcc_assert (last_stmt);
if (dump_file)
{
@@ -1687,15 +1705,7 @@ optimize_function (cgraph_node *n, function *fn)
memref_t *mr = vmrs[j];
/* Don't need to copy the last stmt, since we insert prefetch insn
instead of it. */
- for (int i = mr->stmts.length () - 1; i >= 1 ; i--)
- {
- if (processed_stmts.count (mr->stmts[i]))
- continue;
- processed_stmts.insert (mr->stmts[i]);
-
- gimple *copy = gimple_copy_and_remap (mr->stmts[i]);
- gimple_seq_add_stmt (&stmts, copy);
- }
+ gimple_copy_and_remap_memref_stmts (mr, stmts, 1, processed_stmts);
gimple *last_stmt = mr->stmts[0];
gcc_assert (last_stmt);
tree write_p = mr->is_store ? integer_one_node : integer_zero_node;
--
2.33.0

View File

@ -61,7 +61,7 @@
Summary: Various compilers (C, C++, Objective-C, ...)
Name: gcc
Version: %{gcc_version}
Release: 47
Release: 48
License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
URL: https://gcc.gnu.org
@ -284,6 +284,10 @@ Patch173: 0173-IPA-Fix-test-completion-1.c.patch
Patch174: 0174-IPA-Fix-fails-on-checked-build-and-comments-from-rev.patch
Patch175: 0175-split-ldp-stp-Extending-and-refactoring-of-pass_spli.patch
Patch176: 0176-Fix-bugs-in-ICP-src-openEuler-gcc-I8PYBF-I8PYLL.patch
Patch177: 0177-Fix-sqlite-build.patch
Patch178: 0178-Fix-freetype-build.patch
Patch179: 0179-rtl-ifcvt-refuse-to-rename-def-in-the-last-instructi.patch
Patch180: 0180-Fix-issue-I8QD9H.patch
%global gcc_target_platform %{_arch}-linux-gnu
@ -913,6 +917,10 @@ not stable, so plugins must be rebuilt any time GCC is updated.
%patch174 -p1
%patch175 -p1
%patch176 -p1
%patch177 -p1
%patch178 -p1
%patch179 -p1
%patch180 -p1
%build
@ -2937,6 +2945,12 @@ end
%doc rpm.doc/changelogs/libcc1/ChangeLog*
%changelog
* Sat Dec 23 2023 Chenhui Zheng <zhengchenhui1@huawei.com> - 10.3.1-48
- Type:Sync
- ID:NA
- SUG:NA
- DESC: Sync patch from openeuler/gcc
* Fri Dec 22 2023 Feiyang Liu <liufeiyang6@huawei.com> - 10.3.1-47
- Type:Sync
- ID:NA