From: Richard Biener Date: Mon, 26 Nov 2018 14:16:01 +0000 (+0000) Subject: re PR tree-optimization/87645 (gcc hangs up on vr_values::vrp_visit_assignment_or_call) X-Git-Tag: releases/gcc-7.4.0~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed567c8b5d0696d434d01716af23673310d73db1;p=thirdparty%2Fgcc.git re PR tree-optimization/87645 (gcc hangs up on vr_values::vrp_visit_assignment_or_call) 2018-10-19 Richard Biener PR middle-end/87645 Backport from mainline 2018-07-12 Richard Biener * gimple-match-head.c (gimple_resimplify1): Apply recursion limit. (gimple_resimplify2): Likewise. (gimple_resimplify3): Likewise. (gimple_resimplify4): Likewise. * gcc.dg/torture/pr87645.c: New testcase. From-SVN: r266461 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 77d3a77c399b..68091e8c5848 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2018-10-19 Richard Biener + + PR middle-end/87645 + Backport from mainline + 2018-07-12 Richard Biener + + * gimple-match-head.c (gimple_resimplify1): Apply recursion + limit. + (gimple_resimplify2): Likewise. + (gimple_resimplify3): Likewise. + (gimple_resimplify4): Likewise. + 2018-11-26 Richard Biener Backport from mainline diff --git a/gcc/gimple-match-head.c b/gcc/gimple-match-head.c index e7e9839a4b84..5a0d33174fbc 100644 --- a/gcc/gimple-match-head.c +++ b/gcc/gimple-match-head.c @@ -99,17 +99,34 @@ gimple_resimplify1 (gimple_seq *seq, } } + /* Limit recursion, there are cases like PR80887 and others, for + example when value-numbering presents us with unfolded expressions + that we are really not prepared to handle without eventual + oscillation like ((_50 + 0) + 8) where _50 gets mapped to _50 + itself as available expression. */ + static unsigned depth; + if (depth > 10) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "Aborting expression simplification due to " + "deep recursion\n"); + return false; + } + + ++depth; code_helper res_code2; tree res_ops2[3] = {}; if (gimple_simplify (&res_code2, res_ops2, seq, valueize, *res_code, type, res_ops[0])) { + --depth; *res_code = res_code2; res_ops[0] = res_ops2[0]; res_ops[1] = res_ops2[1]; res_ops[2] = res_ops2[2]; return true; } + --depth; return false; } @@ -159,17 +176,30 @@ gimple_resimplify2 (gimple_seq *seq, canonicalized = true; } + /* Limit recursion, see gimple_resimplify1. */ + static unsigned depth; + if (depth > 10) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "Aborting expression simplification due to " + "deep recursion\n"); + return false; + } + + ++depth; code_helper res_code2; tree res_ops2[3] = {}; if (gimple_simplify (&res_code2, res_ops2, seq, valueize, *res_code, type, res_ops[0], res_ops[1])) { + --depth; *res_code = res_code2; res_ops[0] = res_ops2[0]; res_ops[1] = res_ops2[1]; res_ops[2] = res_ops2[2]; return true; } + --depth; return canonicalized; } @@ -218,18 +248,31 @@ gimple_resimplify3 (gimple_seq *seq, canonicalized = true; } + /* Limit recursion, see gimple_resimplify1. */ + static unsigned depth; + if (depth > 10) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "Aborting expression simplification due to " + "deep recursion\n"); + return false; + } + + ++depth; code_helper res_code2; tree res_ops2[3] = {}; if (gimple_simplify (&res_code2, res_ops2, seq, valueize, *res_code, type, res_ops[0], res_ops[1], res_ops[2])) { + --depth; *res_code = res_code2; res_ops[0] = res_ops2[0]; res_ops[1] = res_ops2[1]; res_ops[2] = res_ops2[2]; return true; } + --depth; return canonicalized; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c260750ffe4d..1c365d2fd7eb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2018-10-19 Richard Biener + + PR middle-end/87645 + Backport from mainline + 2018-07-12 Richard Biener + + * gcc.dg/torture/pr87645.c: New testcase. + 2018-11-26 Richard Biener Backport from mainline diff --git a/gcc/testsuite/gcc.dg/torture/pr87645.c b/gcc/testsuite/gcc.dg/torture/pr87645.c new file mode 100644 index 000000000000..5360e3800800 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr87645.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ + +typedef unsigned a[8]; +a b, g; +int c, d, e, f; +int h() { + unsigned i = 2; + for (; i < 8; i++) + b[i] = 0; + for (; f;) { + d = 1; + for (; d < 14; d += 3) { + e = 0; + for (; e < 8; e++) { + i = 2; + for (; i < 8; i++) + b[i] = 5 - (c - g[e] + b[i]); + } + } + } +}