From: Richard Biener Date: Tue, 24 Jan 2017 08:06:29 +0000 (+0000) Subject: Backport PRs 77436, 77450, 77605, 77855, 78047, 78185, 78333 X-Git-Tag: releases/gcc-5.5.0~564 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a01eaca1188a80c6a5f949922755f5aa15ac6e5;p=thirdparty%2Fgcc.git Backport PRs 77436, 77450, 77605, 77855, 78047, 78185, 78333 2017-01-24 Richard Biener Backport from mainline 2016-10-06 Richard Biener PR tree-optimization/77855 * tree-ssa-pre.c (prune_clobbered_mems): Queue exprs to remove instead of removing the current item while iterating over the set which is not safe. * gcc.dg/torture/pr77855.c: New testcase. 2016-09-01 Richard Biener PR middle-end/77436 * tree-chrec.c (tree_fold_binomial): Use widest_int, properly check whether the result fits the desired result type. * gcc.dg/torture/pr77436.c: New testcase. 2016-09-06 Richard Biener PR c/77450 c-family/ * c-common.c (c_common_mark_addressable_vec): Handle COMPOUND_LITERAL_EXPR. * c-c++-common/vector-subscript-7.c: Adjust. * gcc.dg/pr77450.c: New testcase. 2016-09-19 Richard Biener PR middle-end/77605 * tree-data-ref.c (analyze_subscript_affine_affine): Use the proper niter to bound the loops. * gcc.dg/torture/pr77605.c: New testcase. 2016-11-02 Richard Biener PR tree-optimization/78047 * tree-ssa-structalias.c (push_fields_onto_fieldstack): Initialize fake field at offset zero conservatively regarding to may_have_pointers. 2016-11-02 Richard Biener PR middle-end/78185 * loop-invariant.c (find_invariant_insn): Never hoist trapping or faulting instructions. * tree-ssa-loop-im.c: Include tree-ssa-loop-niter.h. (fill_always_executed_in_1): Honor infinite child loops. * gcc.dg/pr78185.c: New testcase. 2016-11-16 Richard Biener PR middle-end/78333 * gimplify.c (gimplify_function_tree): Do not instrument GNU extern inline functions. * gcc.dg/pr78333.c: New testcase. From-SVN: r244853 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 048884f452b1..a132be1c9b8c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,45 @@ +2017-01-24 Richard Biener + + Backport from mainline + 2016-10-06 Richard Biener + + PR tree-optimization/77855 + * tree-ssa-pre.c (prune_clobbered_mems): Queue exprs to remove + instead of removing the current item while iterating over the set + which is not safe. + + 2016-09-01 Richard Biener + + PR middle-end/77436 + * tree-chrec.c (tree_fold_binomial): Use widest_int, properly + check whether the result fits the desired result type. + + 2016-09-19 Richard Biener + + PR middle-end/77605 + * tree-data-ref.c (analyze_subscript_affine_affine): Use the + proper niter to bound the loops. + + 2016-11-02 Richard Biener + + PR tree-optimization/78047 + * tree-ssa-structalias.c (push_fields_onto_fieldstack): Initialize + fake field at offset zero conservatively regarding to may_have_pointers. + + 2016-11-02 Richard Biener + + PR middle-end/78185 + * loop-invariant.c (find_invariant_insn): Never hoist trapping or + faulting instructions. + * tree-ssa-loop-im.c: Include tree-ssa-loop-niter.h. + (fill_always_executed_in_1): Honor infinite child loops. + + 2016-11-16 Richard Biener + + PR middle-end/78333 + * gimplify.c (gimplify_function_tree): Do not instrument + GNU extern inline functions. + 2017-01-23 Martin Liska Backport from mainline diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 2dce6058d6f9..5052e572a722 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,12 @@ +2017-01-24 Richard Biener + + Backport from mainline + 2016-09-06 Richard Biener + + PR c/77450 + * c-common.c (c_common_mark_addressable_vec): Handle + COMPOUND_LITERAL_EXPR. + 2017-01-10 Martin Liska Backport from mainline diff --git a/gcc/gimplify.c b/gcc/gimplify.c index c571c66775a4..b7aa11d67fcd 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -9428,6 +9428,10 @@ gimplify_function_tree (tree fndecl) /* ??? Add some way to ignore exceptions for this TFE. */ if (flag_instrument_function_entry_exit && !DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl) + /* Do not instrument extern inline functions. */ + && !(DECL_DECLARED_INLINE_P (fndecl) + && DECL_EXTERNAL (fndecl) + && DECL_DISREGARD_INLINE_LIMITS (fndecl)) && !flag_instrument_functions_exclude_p (fndecl)) { tree x; diff --git a/gcc/loop-invariant.c b/gcc/loop-invariant.c index f79b497ea7f7..d2564684319b 100644 --- a/gcc/loop-invariant.c +++ b/gcc/loop-invariant.c @@ -624,13 +624,17 @@ find_exits (struct loop *loop, basic_block *body, FOR_EACH_EDGE (e, ei, body[i]->succs) { - if (flow_bb_inside_loop_p (loop, e->dest)) - continue; - - bitmap_set_bit (may_exit, i); - bitmap_set_bit (has_exit, i); - outermost_exit = find_common_loop (outermost_exit, - e->dest->loop_father); + if (! flow_bb_inside_loop_p (loop, e->dest)) + { + bitmap_set_bit (may_exit, i); + bitmap_set_bit (has_exit, i); + outermost_exit = find_common_loop (outermost_exit, + e->dest->loop_father); + } + /* If we enter a subloop that might never terminate treat + it like a possible exit. */ + if (flow_loop_nested_p (loop, e->dest->loop_father)) + bitmap_set_bit (may_exit, i); } continue; } @@ -913,7 +917,7 @@ pre_check_invariant_p (bool simple, rtx dest) unless the program ends due to a function call. */ static void -find_invariant_insn (rtx_insn *insn, bool always_reached, bool always_executed) +find_invariant_insn (rtx_insn *insn, bool, bool always_executed) { df_ref ref; struct def *def; @@ -947,8 +951,8 @@ find_invariant_insn (rtx_insn *insn, bool always_reached, bool always_executed) if (can_throw_internal (insn)) return; - /* We cannot make trapping insn executed, unless it was executed before. */ - if (may_trap_or_fault_p (PATTERN (insn)) && !always_reached) + /* We cannot make trapping insn executed. */ + if (may_trap_or_fault_p (PATTERN (insn))) return; depends_on = BITMAP_ALLOC (NULL); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c663aef22aa3..25255d437c5e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,36 @@ +2017-01-24 Richard Biener + + Backport from mainline + 2016-10-06 Richard Biener + + PR tree-optimization/77855 + * gcc.dg/torture/pr77855.c: New testcase. + + 2016-09-01 Richard Biener + + PR middle-end/77436 + * gcc.dg/torture/pr77436.c: New testcase. + + 2016-09-06 Richard Biener + + PR c/77450 + * gcc.dg/pr77450.c: New testcase. + + 2016-09-19 Richard Biener + + PR middle-end/77605 + * gcc.dg/torture/pr77605.c: New testcase. + + 2016-11-02 Richard Biener + + PR middle-end/78185 + * gcc.dg/pr78185.c: New testcase. + + 2016-11-16 Richard Biener + + PR middle-end/78333 + * gcc.dg/pr78333.c: New testcase. + 2017-01-23 Martin Liska Backport from mainline diff --git a/gcc/testsuite/gcc.dg/pr77450.c b/gcc/testsuite/gcc.dg/pr77450.c new file mode 100644 index 000000000000..7c19e86ca029 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr77450.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-std=gnu90" } */ + +typedef int V __attribute__((vector_size(4))); + +void +foo(void) +{ + (V){ 0 }[0] = 0; +} diff --git a/gcc/testsuite/gcc.dg/pr78185.c b/gcc/testsuite/gcc.dg/pr78185.c new file mode 100644 index 000000000000..405f7489dae0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr78185.c @@ -0,0 +1,28 @@ +/* { dg-do run { target *-*-linux* *-*-gnu* } } */ +/* { dg-options "-O" } */ + +#include +#include +#include + +static char var1 = 0L; +static char *var2 = &var1; + +void do_exit (int i) +{ + exit (0); +} + +int main(void) +{ + struct sigaction s; + sigemptyset (&s.sa_mask); + s.sa_handler = do_exit; + s.sa_flags = 0; + sigaction (SIGALRM, &s, NULL); + alarm (1); + /* The following loop is infinite, the division by zero should not + be hoisted out of it. */ + for (; (var1 == 0 ? 0 : (100 / var1)) == *var2; ); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pr78333.c b/gcc/testsuite/gcc.dg/pr78333.c new file mode 100644 index 000000000000..ca037e55f82c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr78333.c @@ -0,0 +1,22 @@ +/* { dg-do link } */ +/* { dg-options "-finstrument-functions" } */ + +/* Add empty implementations of __cyg_profile_func_enter() and + __cyg_profile_func_exit() to avoid problems on non-glibc + systems. */ +void __attribute__((no_instrument_function)) +__cyg_profile_func_enter(void *this_fn, void *call_site) +{ +} + +void __attribute__((no_instrument_function)) +__cyg_profile_func_exit(void *this_fn, void *call_site) +{ +} + +extern inline __attribute__((gnu_inline, always_inline)) int foo () { } +int main() +{ + foo (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr77436.c b/gcc/testsuite/gcc.dg/torture/pr77436.c new file mode 100644 index 000000000000..513867db7cee --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr77436.c @@ -0,0 +1,11 @@ +/* { dg-do run } */ + +int main() +{ + unsigned short sum = 0; + for (short x = -(__SHRT_MAX__ -1); x <= (__SHRT_MAX__ -1); x++) + sum += x; + if (sum != 0) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr77605.c b/gcc/testsuite/gcc.dg/torture/pr77605.c new file mode 100644 index 000000000000..3f1a26bc8d57 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr77605.c @@ -0,0 +1,15 @@ +/* { dg-do run } */ + +int a, b, c[2][8]; + +int main () +{ + for (a = 0; a < 8; a++) + for (b = 0; b < 2; b++) + c[b][a] = c[b][b + 6] ^ 1; + + if (c[0][7] != 0) + __builtin_abort (); + + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr77855.c b/gcc/testsuite/gcc.dg/torture/pr77855.c new file mode 100644 index 000000000000..bec5af320134 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr77855.c @@ -0,0 +1,48 @@ +/* { dg-do run } */ + +int a, b = 1, c, e, f, g, k, m, n, o; +char d, h, i, j, l; +char res[2]; + +void __attribute__ ((noinline,noclone)) fn2 () +{ + d = 2; +} + +void fn3 () +{ + for (;;) + { + for (; b; b--) + { + fn2 (); + if (e) + j = 1; + if (f) + L1: + k = j | (a & l); + for (;;) + { + __builtin_snprintf (res, 2, "%d\n", d); + if (d) + break; + for (; o; o--) + for (; n;) + for (; m; m++) + ; + goto L1; + } + } + g = h; + c = i; + break; + } +} + +int main () +{ + fn3 (); + if (res[0] != '2') + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-chrec.c b/gcc/tree-chrec.c index 1d7bc47192ab..b4a8d821c565 100644 --- a/gcc/tree-chrec.c +++ b/gcc/tree-chrec.c @@ -502,7 +502,6 @@ tree_fold_binomial (tree type, tree n, unsigned int k) { bool overflow; unsigned int i; - tree res; /* Handle the most frequent cases. */ if (k == 0) @@ -510,18 +509,20 @@ tree_fold_binomial (tree type, tree n, unsigned int k) if (k == 1) return fold_convert (type, n); + widest_int num = wi::to_widest (n); + /* Check that k <= n. */ - if (wi::ltu_p (n, k)) + if (wi::ltu_p (num, k)) return NULL_TREE; /* Denominator = 2. */ - wide_int denom = wi::two (TYPE_PRECISION (TREE_TYPE (n))); + widest_int denom = 2; /* Index = Numerator-1. */ - wide_int idx = wi::sub (n, 1); + widest_int idx = num - 1; /* Numerator = Numerator*Index = n*(n-1). */ - wide_int num = wi::smul (n, idx, &overflow); + num = wi::smul (num, idx, &overflow); if (overflow) return NULL_TREE; @@ -540,9 +541,10 @@ tree_fold_binomial (tree type, tree n, unsigned int k) } /* Result = Numerator / Denominator. */ - wide_int di_res = wi::udiv_trunc (num, denom); - res = wide_int_to_tree (type, di_res); - return int_fits_type_p (res, type) ? res : NULL_TREE; + num = wi::udiv_trunc (num, denom); + if (! wi::fits_to_tree_p (num, type)) + return NULL_TREE; + return wide_int_to_tree (type, num); } /* Helper function. Use the Newton's interpolating formula for diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c index 410fd53a277f..dc80d60870f5 100644 --- a/gcc/tree-data-ref.c +++ b/gcc/tree-data-ref.c @@ -2717,13 +2717,13 @@ analyze_subscript_affine_affine (tree chrec_a, if (niter > 0) { - HOST_WIDE_INT tau2 = MIN (FLOOR_DIV (niter - i0, i1), - FLOOR_DIV (niter - j0, j1)); + HOST_WIDE_INT tau2 = MIN (FLOOR_DIV (niter_a - i0, i1), + FLOOR_DIV (niter_b - j0, j1)); HOST_WIDE_INT last_conflict = tau2 - (x1 - i0)/i1; /* If the overlap occurs outside of the bounds of the loop, there is no dependence. */ - if (x1 >= niter || y1 >= niter) + if (x1 >= niter_a || y1 >= niter_b) { *overlaps_a = conflict_fn_no_dependence (); *overlaps_b = conflict_fn_no_dependence (); diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c index 16bc1ab31ef3..dc7b5fd3dd37 100644 --- a/gcc/tree-ssa-loop-im.c +++ b/gcc/tree-ssa-loop-im.c @@ -70,6 +70,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-ssa-propagate.h" #include "trans-mem.h" #include "gimple-fold.h" +#include "tree-ssa-loop-niter.h" /* TODO: Support for predicated code motion. I.e. @@ -2406,8 +2407,16 @@ fill_always_executed_in_1 (struct loop *loop, sbitmap contains_call) break; FOR_EACH_EDGE (e, ei, bb->succs) - if (!flow_bb_inside_loop_p (loop, e->dest)) - break; + { + /* If there is an exit from this BB. */ + if (!flow_bb_inside_loop_p (loop, e->dest)) + break; + /* Or we enter a possibly non-finite loop. */ + if (flow_loop_nested_p (bb->loop_father, + e->dest->loop_father) + && ! finite_loop_p (e->dest->loop_father)) + break; + } if (e) break; diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c index c5c06ca4b14d..459d8e3cf5f0 100644 --- a/gcc/tree-ssa-pre.c +++ b/gcc/tree-ssa-pre.c @@ -2077,9 +2077,17 @@ prune_clobbered_mems (bitmap_set_t set, basic_block block) { bitmap_iterator bi; unsigned i; + pre_expr to_remove = NULL; FOR_EACH_EXPR_ID_IN_SET (set, i, bi) { + /* Remove queued expr. */ + if (to_remove) + { + bitmap_remove_from_set (set, to_remove); + to_remove = NULL; + } + pre_expr expr = expression_for_id (i); if (expr->kind == REFERENCE) { @@ -2093,7 +2101,7 @@ prune_clobbered_mems (bitmap_set_t set, basic_block block) block, gimple_bb (def_stmt))) || (gimple_bb (def_stmt) == block && value_dies_in_block_x (expr, block)))) - bitmap_remove_from_set (set, expr); + to_remove = expr; } } else if (expr->kind == NARY) @@ -2105,9 +2113,13 @@ prune_clobbered_mems (bitmap_set_t set, basic_block block) as the available expression might be after the exit point. */ if (BB_MAY_NOTRETURN (block) && vn_nary_may_trap (nary)) - bitmap_remove_from_set (set, expr); + to_remove = expr; } } + + /* Remove queued expr. */ + if (to_remove) + bitmap_remove_from_set (set, to_remove); } static sbitmap has_abnormal_preds; diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index c12128a923b0..bf1b989d8373 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -5371,7 +5371,7 @@ push_fields_onto_fieldstack (tree type, vec *fieldstack, if (!pair && offset + foff != 0) { - fieldoff_s e = {0, offset + foff, false, false, false, false}; + fieldoff_s e = {0, offset + foff, false, false, true, false}; pair = fieldstack->safe_push (e); }