aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-sccvn.c
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2017-06-19 15:01:13 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2017-06-19 15:01:13 +0000
commit343ae898b17490d15c98f711ffcb04c88cca9235 (patch)
treeef6963983505b5fc27f730d9f530a778279acca3 /gcc/tree-ssa-sccvn.c
parent9787269815559a63fbbda58b35137f832a612984 (diff)
downloadgcc-343ae898b17490d15c98f711ffcb04c88cca9235.zip
gcc-343ae898b17490d15c98f711ffcb04c88cca9235.tar.gz
gcc-343ae898b17490d15c98f711ffcb04c88cca9235.tar.bz2
re PR bootstrap/80887 (gnat bootstrap fails at s-regpat.o: raised STORAGE_ERROR : stack overflow or erroneous memory access)
2017-06-19 Richard Biener <rguenther@suse.de> PR tree-optimization/80887 c/ * gimple-parser.c (c_parser_gimple_postfix_expression): Handle negated _Literals to parse _Literal (int) -1. * tree-ssa-sccvn.c (mprts_hook_cnt): New global. (vn_lookup_simplify_result): Allow only mprts_hook_cnt succesful simplified lookups, then reset mprts_hook. (vn_nary_build_or_lookup_1): Set mprts_hook_cnt to 9 before simplifying. (try_to_simplify): Likewise. * gcc.dg/tree-ssa/pr80887.c: New testcase. From-SVN: r249373
Diffstat (limited to 'gcc/tree-ssa-sccvn.c')
-rw-r--r--gcc/tree-ssa-sccvn.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index 419da47..324cd73 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -1639,6 +1639,7 @@ vn_reference_lookup_or_insert_for_pieces (tree vuse,
}
static vn_nary_op_t vn_nary_op_insert_stmt (gimple *stmt, tree result);
+static unsigned mprts_hook_cnt;
/* Hook for maybe_push_res_to_seq, lookup the expression in the VN tables. */
@@ -1648,8 +1649,22 @@ vn_lookup_simplify_result (code_helper rcode, tree type, tree *ops)
if (!rcode.is_tree_code ())
return NULL_TREE;
vn_nary_op_t vnresult = NULL;
- return vn_nary_op_lookup_pieces (TREE_CODE_LENGTH ((tree_code) rcode),
- (tree_code) rcode, type, ops, &vnresult);
+ tree res = vn_nary_op_lookup_pieces (TREE_CODE_LENGTH ((tree_code) rcode),
+ (tree_code) rcode, type, ops, &vnresult);
+ /* We can end up endlessly recursing simplifications if the lookup above
+ presents us with a def-use chain that mirrors the original simplification.
+ See PR80887 for an example. Limit successful lookup artificially
+ to 10 times if we are called as mprts_hook. */
+ if (res
+ && mprts_hook
+ && --mprts_hook_cnt == 0)
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, "Resetting mprts_hook after too many "
+ "invocations.\n");
+ mprts_hook = NULL;
+ }
+ return res;
}
/* Return a value-number for RCODE OPS... either by looking up an existing
@@ -1666,6 +1681,7 @@ vn_nary_build_or_lookup_1 (code_helper rcode, tree type, tree *ops,
So first simplify and lookup this expression to see if it
is already available. */
mprts_hook = vn_lookup_simplify_result;
+ mprts_hook_cnt = 9;
bool res = false;
switch (TREE_CODE_LENGTH ((tree_code) rcode))
{
@@ -3896,6 +3912,7 @@ try_to_simplify (gassign *stmt)
/* First try constant folding based on our current lattice. */
mprts_hook = vn_lookup_simplify_result;
+ mprts_hook_cnt = 9;
tem = gimple_fold_stmt_to_constant_1 (stmt, vn_valueize, vn_valueize);
mprts_hook = NULL;
if (tem