From: Richard Biener Date: Tue, 26 Mar 2019 11:18:26 +0000 (+0000) Subject: backport: [multiple changes] X-Git-Tag: releases/gcc-7.5.0~516 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b53faa7a5123cea6a5d97395a109e6387fc9f1b8;p=thirdparty%2Fgcc.git backport: [multiple changes] 2019-03-26 Richard Biener Backport from mainline 2019-01-08 Richard Biener PR tree-optimization/86554 * tree-ssa-sccvn.c (visit_nary_op): When value-numbering to expressions with different overflow behavior make sure there's an available expression on the path. * gcc.dg/torture/pr86554-1.c: New testcase. * gcc.dg/torture/pr86554-2.c: Likewise. 2018-11-20 Richard Biener PR tree-optimization/88105 * tree-ssa-dom.c (pass_dominator::execute): Do not walk backedges. * gcc.dg/gomp/pr88105.c: New testcase. 2018-03-08 Richard Biener PR middle-end/84552 * tree-scalar-evolution.c: Include tree-into-ssa.h. (follow_copies_to_constant): Do not follow SSA names registered for update. * gcc.dg/graphite/pr84552.c: New testcase. From-SVN: r269939 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 238bdbd25116..58cd084a47d9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,26 @@ +2019-03-26 Richard Biener + + Backport from mainline + 2019-01-08 Richard Biener + + PR tree-optimization/86554 + * tree-ssa-sccvn.c (visit_nary_op): When value-numbering to + expressions with different overflow behavior make sure there's an + available expression on the path. + + 2018-11-20 Richard Biener + + PR tree-optimization/88105 + * tree-ssa-dom.c (pass_dominator::execute): Do not walk + backedges. + + 2018-03-08 Richard Biener + + PR middle-end/84552 + * tree-scalar-evolution.c: Include tree-into-ssa.h. + (follow_copies_to_constant): Do not follow SSA names registered + for update. + 2019-03-21 Bill Schmidt * config/rs6000/rs6000.c (rs6000_analyze_swaps): Rebuild diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4ca1066d91a9..242c721bc982 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,22 @@ +2019-03-26 Richard Biener + + Backport from mainline + 2019-01-08 Richard Biener + + PR tree-optimization/86554 + * gcc.dg/torture/pr86554-1.c: New testcase. + * gcc.dg/torture/pr86554-2.c: Likewise. + + 2018-11-20 Richard Biener + + PR tree-optimization/88105 + * gcc.dg/gomp/pr88105.c: New testcase. + + 2018-03-08 Richard Biener + + PR middle-end/84552 + * gcc.dg/graphite/pr84552.c: New testcase. + 2019-03-25 Janus Weil PR fortran/71861 diff --git a/gcc/testsuite/gcc.dg/gomp/pr88105.c b/gcc/testsuite/gcc.dg/gomp/pr88105.c new file mode 100644 index 000000000000..9680fdd19f67 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gomp/pr88105.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-fopenmp -O -fexceptions -fnon-call-exceptions -fno-tree-fre" } */ + +int +s0 (void) +{ + int g6, oh = 0; + int *a6 = &g6; + + (void) a6; + +#pragma omp parallel for + for (g6 = 0; g6 < 1; ++g6) + { + int zk; + + for (zk = 0; zk < 1; ++zk) + { + oh += zk / (zk + 1); + + for (;;) + { + } + } + + a6 = &zk; + } + + return oh; +} diff --git a/gcc/testsuite/gcc.dg/graphite/pr84552.c b/gcc/testsuite/gcc.dg/graphite/pr84552.c new file mode 100644 index 000000000000..15cbb0848f4b --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/pr84552.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -floop-nest-optimize -fno-tree-copy-prop -fno-tree-fre -fno-tree-loop-ivcanon" } */ + +int cx; + +int +e6 (int pj, int xe) +{ + for (cx = 0; cx < 2; ++cx) + while (xe < 1) + { + for (cx = 0; cx < 2; ++cx) + pj *= 2; + + if (cx != 0) + goto o3; + + ++xe; + } + +o3: + return pj; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr86554-1.c b/gcc/testsuite/gcc.dg/torture/pr86554-1.c new file mode 100644 index 000000000000..64f851e896ec --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr86554-1.c @@ -0,0 +1,35 @@ +/* { dg-do run } */ + +struct foo +{ + unsigned x; +}; +typedef struct foo foo; + +static inline int zot(foo *f) +{ + int ret; + + if (f->x > 0x7FFFFFFF) + ret = (int)(f->x - 0x7FFFFFFF); + else + ret = (int)f->x - 0x7FFFFFFF; + return ret; +} + +void __attribute__((noinline,noclone)) bar(foo *f) +{ + int ret = zot(f); + volatile int x = ret; + if (ret < 1) + __builtin_abort (); +} + +int main() +{ + foo f; + f.x = 0x800003f8; + + bar(&f); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr86554-2.c b/gcc/testsuite/gcc.dg/torture/pr86554-2.c new file mode 100644 index 000000000000..9e57a9ca7250 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr86554-2.c @@ -0,0 +1,49 @@ +/* { dg-do run } */ +/* { dg-require-effective-target int32plus } */ + +struct s { __INT64_TYPE__ e; }; + +static void f (struct s *ps) +{ + volatile __INT64_TYPE__ m = 9223372036854775807; + const char *str = "11E"; + int r; + __INT64_TYPE__ sum; + + ps->e = 0; + + for (;;) + { + if (*str++ != '1') + break; + ps->e ++; + } + + r = 1; + sum = m; + + if (sum >= 0 && ps->e >= 0) + { + __UINT64_TYPE__ uc; + uc = (__UINT64_TYPE__) sum + (__UINT64_TYPE__) ps->e; + if (uc > 9223372036854775807) + r = 2; + else + sum = 17; + } + else + sum = sum + ps->e; + + if (sum != 9223372036854775807) + __builtin_abort (); + if (r != 2) + __builtin_abort (); + ps->e = sum; +} + +int main (void) +{ + struct s s; + f (&s); + return 0; +} diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c index cbd17e8644fe..790050a20c9b 100644 --- a/gcc/tree-scalar-evolution.c +++ b/gcc/tree-scalar-evolution.c @@ -280,6 +280,7 @@ along with GCC; see the file COPYING3. If not see #include "params.h" #include "tree-ssa-propagate.h" #include "gimple-fold.h" +#include "tree-into-ssa.h" static tree analyze_scalar_evolution_1 (struct loop *, tree, tree); static tree analyze_scalar_evolution_for_address_of (struct loop *loop, @@ -1532,7 +1533,10 @@ static tree follow_copies_to_constant (tree var) { tree res = var; - while (TREE_CODE (res) == SSA_NAME) + while (TREE_CODE (res) == SSA_NAME + /* We face not updated SSA form in multiple places and this walk + may end up in sibling loops so we have to guard it. */ + && !name_registered_for_update_p (res)) { gimple *def = SSA_NAME_DEF_STMT (res); if (gphi *phi = dyn_cast (def)) diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index 22ac57e1f75a..10e4ec705a65 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -531,7 +531,8 @@ pass_dominator::execute (function *fun) if (bb == NULL) continue; while (single_succ_p (bb) - && (single_succ_edge (bb)->flags & EDGE_EH) == 0) + && (single_succ_edge (bb)->flags + & (EDGE_EH|EDGE_DFS_BACK)) == 0) bb = single_succ (bb); if (bb == EXIT_BLOCK_PTR_FOR_FN (fun)) continue; diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 8e7052f950ec..c93f1f261959 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -3572,7 +3572,17 @@ visit_nary_op (tree lhs, gassign *stmt) ops[0] = vn_nary_op_lookup_pieces (2, gimple_assign_rhs_code (def), type, ops, NULL); /* We have wider operation available. */ - if (ops[0]) + if (ops[0] + /* If the leader is a wrapping operation we can + insert it for code hoisting w/o introducing + undefined overflow. If it is not it has to + be available. See PR86554. */ + && (TYPE_OVERFLOW_WRAPS (TREE_TYPE (ops[0])) + || TREE_CODE (ops[0]) != SSA_NAME + || SSA_NAME_IS_DEFAULT_DEF (ops[0]) + || dominated_by_p_w_unex + (gimple_bb (stmt), + gimple_bb (SSA_NAME_DEF_STMT (ops[0]))))) { unsigned lhs_prec = TYPE_PRECISION (type); unsigned rhs_prec = TYPE_PRECISION (TREE_TYPE (rhs1));