===================================================================
@@ -1648,7 +1648,6 @@ vn_reference_lookup_or_insert_for_pieces
}
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. */
@@ -1672,13 +1671,8 @@ vn_lookup_simplify_result (gimple_match_
vn_nary_op_t vnresult = NULL;
tree res = vn_nary_op_lookup_pieces (length, (tree_code) res_op->code,
res_op->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)
+ && mprts_hook)
{
if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, "Resetting mprts_hook after too many "
@@ -1701,7 +1695,6 @@ vn_nary_build_or_lookup_1 (gimple_match_
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) res_op->code))
{
@@ -4051,7 +4044,6 @@ 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
===================================================================
@@ -97,13 +97,30 @@ gimple_resimplify1 (gimple_seq *seq, gim
}
}
+ /* 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_FOLDING))
+ fprintf (dump_file, "Aborting expression simplification due to "
+ "deep recursion\n");
+ return false;
+ }
+
+ ++depth;
gimple_match_op res_op2 (*res_op);
if (gimple_simplify (&res_op2, seq, valueize,
res_op->code, res_op->type, res_op->ops[0]))
{
+ --depth;
*res_op = res_op2;
return true;
}
+ --depth;
return false;
}
@@ -151,14 +168,27 @@ gimple_resimplify2 (gimple_seq *seq, gim
canonicalized = true;
}
+ /* Limit recursion, see gimple_resimplify1. */
+ static unsigned depth;
+ if (depth > 10)
+ {
+ if (dump_file && (dump_flags & TDF_FOLDING))
+ fprintf (dump_file, "Aborting expression simplification due to "
+ "deep recursion\n");
+ return false;
+ }
+
+ ++depth;
gimple_match_op res_op2 (*res_op);
if (gimple_simplify (&res_op2, seq, valueize,
res_op->code, res_op->type,
res_op->ops[0], res_op->ops[1]))
{
+ --depth;
*res_op = res_op2;
return true;
}
+ --depth;
return canonicalized;
}
@@ -205,14 +235,27 @@ gimple_resimplify3 (gimple_seq *seq, gim
canonicalized = true;
}
+ /* Limit recursion, see gimple_resimplify1. */
+ static unsigned depth;
+ if (depth > 10)
+ {
+ if (dump_file && (dump_flags & TDF_FOLDING))
+ fprintf (dump_file, "Aborting expression simplification due to "
+ "deep recursion\n");
+ return false;
+ }
+
+ ++depth;
gimple_match_op res_op2 (*res_op);
if (gimple_simplify (&res_op2, seq, valueize,
res_op->code, res_op->type,
res_op->ops[0], res_op->ops[1], res_op->ops[2]))
{
+ --depth;
*res_op = res_op2;
return true;
}
+ --depth;
return canonicalized;
}
@@ -229,15 +272,28 @@ gimple_resimplify4 (gimple_seq *seq, gim
{
/* No constant folding is defined for four-operand functions. */
+ /* Limit recursion, see gimple_resimplify1. */
+ static unsigned depth;
+ if (depth > 10)
+ {
+ if (dump_file && (dump_flags & TDF_FOLDING))
+ fprintf (dump_file, "Aborting expression simplification due to "
+ "deep recursion\n");
+ return false;
+ }
+
+ ++depth;
gimple_match_op res_op2 (*res_op);
if (gimple_simplify (&res_op2, seq, valueize,
res_op->code, res_op->type,
res_op->ops[0], res_op->ops[1], res_op->ops[2],
res_op->ops[3]))
{
+ --depth;
*res_op = res_op2;
return true;
}
+ --depth;
return false;
}