Backport to GCC5
Hello. There's a series of patches that I installed to GCC6 and majority of there are also related to GCC 5 branch. I'm going to install the patches. Martin >From 9cbe2ada95218219ca1de6e5d9c839509f8cd6ab Mon Sep 17 00:00:00 2001 From: marxin Date: Tue, 28 Mar 2017 09:01:57 + Subject: [PATCH 01/12] Backport r246525 gcc/ChangeLog: 2017-03-28 Martin Liska PR ipa/80104 * cgraphunit.c (cgraph_node::expand_thunk): Mark argument of a thunk call as DECL_GIMPLE_REG_P when vector or complex type. gcc/testsuite/ChangeLog: 2017-03-28 Martin Liska PR ipa/80104 * gcc.dg/ipa/pr80104.c: New test. --- gcc/cgraphunit.c | 4 gcc/testsuite/gcc.dg/ipa/pr80104.c | 15 +++ 2 files changed, 19 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr80104.c diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index d4db126cbd5..5f0b06ebec0 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -1673,6 +1673,10 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk) for (; i < nargs; i++, arg = DECL_CHAIN (arg)) { tree tmp = arg; + if (VECTOR_TYPE_P (TREE_TYPE (arg)) + || TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE) + DECL_GIMPLE_REG_P (arg) = 1; + if (!is_gimple_val (arg)) { tmp = create_tmp_reg (TYPE_MAIN_VARIANT diff --git a/gcc/testsuite/gcc.dg/ipa/pr80104.c b/gcc/testsuite/gcc.dg/ipa/pr80104.c new file mode 100644 index 000..7e75c9907e7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr80104.c @@ -0,0 +1,15 @@ +/* PR ipa/80104 */ +/* { dg-do compile } */ +/* { dg-options "-fipa-icf" } */ + +float +a (_Complex float b) +{ + return *&b; +} + +float +c (_Complex float b) +{ + return (&b)[0]; +} -- 2.12.2 >From 097cdfb997ec6059947cab918197d9462897191e Mon Sep 17 00:00:00 2001 From: marxin Date: Tue, 28 Mar 2017 11:37:22 + Subject: [PATCH 02/12] Backport r246530 gcc/ChangeLog: 2017-03-28 Richard Biener PR ipa/80205 * tree-inline.c (copy_phis_for_bb): Do not create PHI node without arguments, generate default definition of a SSA name. gcc/testsuite/ChangeLog: 2017-03-28 Martin Liska PR ipa/80205 * g++.dg/ipa/pr80205.C: New test. --- gcc/testsuite/g++.dg/ipa/pr80205.C | 34 ++ gcc/tree-inline.c | 94 -- 2 files changed, 84 insertions(+), 44 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ipa/pr80205.C diff --git a/gcc/testsuite/g++.dg/ipa/pr80205.C b/gcc/testsuite/g++.dg/ipa/pr80205.C new file mode 100644 index 000..460bdcb02ca --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/pr80205.C @@ -0,0 +1,34 @@ +// PR ipa/80205 +// { dg-options "-fnon-call-exceptions --param early-inlining-insns=100 -O2" } + +class a +{ +public: + virtual ~a (); +}; +class b +{ +public: + template b (c); + ~b () { delete d; } + void + operator= (b e) + { +b (e).f (*this); + } + void + f (b &e) + { +a g; +d = e.d; +e.d = &g; + } + a *d; +}; +void +h () +{ + b i = int(); + void j (); + i = j; +} diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index e8c066015f5..60f79336cd7 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -2347,53 +2347,59 @@ copy_phis_for_bb (basic_block bb, copy_body_data *id) { walk_tree (&new_res, copy_tree_body_r, id, NULL); new_phi = create_phi_node (new_res, new_bb); - FOR_EACH_EDGE (new_edge, ei, new_bb->preds) + if (EDGE_COUNT (new_bb->preds) == 0) { - edge old_edge = find_edge ((basic_block) new_edge->src->aux, bb); - tree arg; - tree new_arg; - edge_iterator ei2; - location_t locus; - - /* When doing partial cloning, we allow PHIs on the entry block - as long as all the arguments are the same. Find any input - edge to see argument to copy. */ - if (!old_edge) - FOR_EACH_EDGE (old_edge, ei2, bb->preds) - if (!old_edge->src->aux) - break; + /* Technically we'd want a SSA_DEFAULT_DEF here... */ + SSA_NAME_DEF_STMT (new_res) = gimple_build_nop (); + } + else + FOR_EACH_EDGE (new_edge, ei, new_bb->preds) + { + edge old_edge = find_edge ((basic_block) new_edge->src->aux, bb); + tree arg; + tree new_arg; + edge_iterator ei2; + location_t locus; + + /* When doing partial cloning, we allow PHIs on the entry block + as long as all the arguments are the same. Find any input + edge to see argument to copy. */ + if (!old_edge) + FOR_EACH_EDGE (old_edge, ei2, bb->preds) + if (!old_edge->src->aux) + break; - arg = PHI_ARG_DEF_FROM_EDGE (phi, old_edge); - new_arg = arg; - walk_tree (&new_arg, copy_tree_body_r, id, NULL); - gcc_assert (new_arg); - /* With return slot optimization we can end up with - non-gimple (foo *)&this->m, fix that here. */ - if (TREE_CODE (new_arg) != SSA_NAME - && TREE_CODE (new_arg) != FUNCTION_DECL - && !is_gimple_val (new_arg)) - { - gimple_seq stmts = NULL;
Backport to GCC5 (part 2)
And there's a single patch that I'll install after bootstrap and regression tests. Martin >From cc7922d08b8b5234758e31e2d91557fd7f6cac9b Mon Sep 17 00:00:00 2001 From: marxin Date: Wed, 22 Feb 2017 09:45:42 + Subject: [PATCH] Backport r245647 gcc/ChangeLog: 2017-02-22 Martin Liska PR lto/79587 * data-streamer-in.c (streamer_read_gcov_count): Remove assert. * data-streamer-out.c (streamer_write_gcov_count_stream): Likewise. * value-prof.c (stream_out_histogram_value): Make assert more precise based on type of counter. gcc/testsuite/ChangeLog: 2017-02-22 Martin Liska PR lto/79587 * gcc.dg/tree-prof/pr79587.c: New test. --- gcc/data-streamer-in.c | 1 - gcc/data-streamer-out.c | 1 - gcc/testsuite/gcc.dg/tree-prof/pr79587.c | 26 ++ gcc/value-prof.c | 12 +++- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-prof/pr79587.c diff --git a/gcc/data-streamer-in.c b/gcc/data-streamer-in.c index 424d52295fa..fec20ea59c4 100644 --- a/gcc/data-streamer-in.c +++ b/gcc/data-streamer-in.c @@ -206,6 +206,5 @@ gcov_type streamer_read_gcov_count (struct lto_input_block *ib) { gcov_type ret = streamer_read_hwi (ib); - gcc_assert (ret >= 0); return ret; } diff --git a/gcc/data-streamer-out.c b/gcc/data-streamer-out.c index caee0c6a464..ac2c1d64bcd 100644 --- a/gcc/data-streamer-out.c +++ b/gcc/data-streamer-out.c @@ -363,7 +363,6 @@ streamer_write_hwi_stream (struct lto_output_stream *obs, HOST_WIDE_INT work) void streamer_write_gcov_count_stream (struct lto_output_stream *obs, gcov_type work) { - gcc_assert (work >= 0); gcc_assert ((HOST_WIDE_INT) work == work); streamer_write_hwi_stream (obs, work); } diff --git a/gcc/testsuite/gcc.dg/tree-prof/pr79587.c b/gcc/testsuite/gcc.dg/tree-prof/pr79587.c new file mode 100644 index 000..517e0819919 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-prof/pr79587.c @@ -0,0 +1,26 @@ +/* { dg-require-effective-target lto } */ +/* { dg-options "-O2 -flto" } */ + +unsigned long global = -12345; + +unsigned long +__attribute__((noinline)) +test(unsigned long v, unsigned long v2) +{ + unsigned long x = v % v2; + + return x; +} + +int main(int argc, char **argv) +{ + unsigned long r = 0; + + for (int i = 0; i < 100; i++) +r += test(argc, global); + + if (r != 100) +__builtin_abort (); + + return 0; +} diff --git a/gcc/value-prof.c b/gcc/value-prof.c index b16bce8746a..9d04ee2d6bd 100644 --- a/gcc/value-prof.c +++ b/gcc/value-prof.c @@ -431,7 +431,17 @@ stream_out_histogram_value (struct output_block *ob, histogram_value hist) break; } for (i = 0; i < hist->n_counters; i++) -streamer_write_gcov_count (ob, hist->hvalue.counters[i]); +{ + /* When user uses an unsigned type with a big value, constant converted + to gcov_type (a signed type) can be negative. */ + gcov_type value = hist->hvalue.counters[i]; + if (hist->type == HIST_TYPE_SINGLE_VALUE && i == 0) + ; + else + gcc_assert (value >= 0); + + streamer_write_gcov_count (ob, value); +} if (hist->hvalue.next) stream_out_histogram_value (ob, hist->hvalue.next); } -- 2.12.0
Backport to GCC5
Hello. This is very same series as the one for GCC6. Only exception is toplev.c, which is squashed just to a single patch. And a multi-versioning patch is omitted. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. I'm going to install the series. Martin >From 62b6cbefcf9eba678d77aa6e979b3f0c6a3f6b79 Mon Sep 17 00:00:00 2001 From: marxin Date: Fri, 17 Feb 2017 14:47:08 + Subject: [PATCH 01/15] Backport r245532 gcc/ChangeLog: 2017-02-17 Martin Liska PR rtl-optimization/79577 * params.def (selsched-max-sched-times): Increase minimum to 1. --- gcc/params.def | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/params.def b/gcc/params.def index 48b39a25041..33d637675ab 100644 --- a/gcc/params.def +++ b/gcc/params.def @@ -656,7 +656,7 @@ DEFPARAM(PARAM_SELSCHED_MAX_LOOKAHEAD, DEFPARAM(PARAM_SELSCHED_MAX_SCHED_TIMES, "selsched-max-sched-times", "Maximum number of times that an insn could be scheduled", - 2, 0, 0) + 2, 1, 0) DEFPARAM(PARAM_SELSCHED_INSNS_TO_RENAME, "selsched-insns-to-rename", -- 2.12.0 >From 3005209ed0529e7cefed1fdb27c76e9c6c001a9d Mon Sep 17 00:00:00 2001 From: marxin Date: Fri, 17 Feb 2017 14:46:14 + Subject: [PATCH 02/15] Backport r245531 gcc/ChangeLog: 2017-02-17 Martin Liska PR rtl-optimization/79574 * gcse.c (want_to_gcse_p): Prevent integer overflow. gcc/testsuite/ChangeLog: 2017-02-17 Martin Liska PR rtl-optimization/79574 * gcc.dg/pr79574.c: New test. --- gcc/gcse.c | 5 +++-- gcc/testsuite/gcc.dg/pr79574.c | 10 ++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr79574.c diff --git a/gcc/gcse.c b/gcc/gcse.c index 0f6d456ab39..c6bea33c6d2 100644 --- a/gcc/gcse.c +++ b/gcc/gcse.c @@ -824,7 +824,7 @@ want_to_gcse_p (rtx x, int *max_distance_ptr) /* PRE doesn't implement max_distance restriction. */ { int cost; - int max_distance; + HOST_WIDE_INT max_distance; gcc_assert (!optimize_function_for_speed_p (cfun) && optimize_function_for_size_p (cfun)); @@ -832,7 +832,8 @@ want_to_gcse_p (rtx x, int *max_distance_ptr) if (cost < COSTS_N_INSNS (GCSE_UNRESTRICTED_COST)) { - max_distance = (GCSE_COST_DISTANCE_RATIO * cost) / 10; + max_distance + = ((HOST_WIDE_INT)GCSE_COST_DISTANCE_RATIO * cost) / 10; if (max_distance == 0) return 0; diff --git a/gcc/testsuite/gcc.dg/pr79574.c b/gcc/testsuite/gcc.dg/pr79574.c new file mode 100644 index 000..1b666e20d21 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr79574.c @@ -0,0 +1,10 @@ +/* PR rtl-optimization/79574 */ +/* { dg-do compile } */ +/* { dg-options "-Os --param gcse-cost-distance-ratio=2147483647" } */ + +void a (void) +{ + volatile int b; + for (;; b) +; +} -- 2.12.0 >From 895302c15bcfefca67a3c9f6a9802112ca1b2b12 Mon Sep 17 00:00:00 2001 From: marxin Date: Fri, 3 Mar 2017 11:53:14 + Subject: [PATCH 03/15] Backport r245868 gcc/ChangeLog: 2017-03-03 Martin Liska PR rtl-optimization/79574 * gcse.c (struct gcse_expr): Use HOST_WIDE_INT instead of int. (hash_scan_set): Likewise. (dump_hash_table): Likewise. (hoist_code): Likewise. gcc/testsuite/ChangeLog: 2017-03-03 Martin Liska PR rtl-optimization/79574 * gcc.dg/pr79574-2.c: New test. --- gcc/gcse.c | 29 + gcc/testsuite/gcc.dg/pr79574-2.c | 33 + 2 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr79574-2.c diff --git a/gcc/gcse.c b/gcc/gcse.c index c6bea33c6d2..394620d64f6 100644 --- a/gcc/gcse.c +++ b/gcc/gcse.c @@ -311,7 +311,7 @@ struct gcse_expr to keep register pressure under control. A value of "0" removes restrictions on how far the expression can travel. */ - int max_distance; + HOST_WIDE_INT max_distance; }; /* Occurrence of an expression. @@ -486,12 +486,12 @@ static void hash_scan_insn (rtx_insn *, struct gcse_hash_table_d *); static void hash_scan_set (rtx, rtx_insn *, struct gcse_hash_table_d *); static void hash_scan_clobber (rtx, rtx_insn *, struct gcse_hash_table_d *); static void hash_scan_call (rtx, rtx_insn *, struct gcse_hash_table_d *); -static int want_to_gcse_p (rtx, int *); +static int want_to_gcse_p (rtx, HOST_WIDE_INT *); static int oprs_unchanged_p (const_rtx, const rtx_insn *, int); static int oprs_anticipatable_p (const_rtx, const rtx_insn *); static int oprs_available_p (const_rtx, const rtx_insn *); static void insert_expr_in_table (rtx, machine_mode, rtx_insn *, int, int, - int, struct gcse_hash_table_d *); + HOST_WIDE_INT, struct gcse_hash_table_d *); static unsigned int hash_expr (const_rtx, machine_mode, int *, int); static void record_last_reg_set_info (rtx, int); static void record_last_mem_set_info (rtx_insn *); @@ -521,8 +521,10 @@ static void alloc_code_hoist_mem (int, int); static void free