From 71b72132011a47a4b39950d95718f18d1218978c Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Mon, 10 Jan 2022 13:33:44 -0500 Subject: [PATCH] Prevent exponential range calculations. Produce a summary result for any operation involving too many subranges. PR tree-optimization/103821 * range-op.cc (range_operator::fold_range): Only do precise ranges when there are not too many subranges. --- gcc/range-op.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 1af42eb..a4f6e9e 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -209,10 +209,12 @@ range_operator::fold_range (irange &r, tree type, unsigned num_rh = rh.num_pairs (); // If both ranges are single pairs, fold directly into the result range. - if (num_lh == 1 && num_rh == 1) + // If the number of subranges grows too high, produce a summary result as the + // loop becomes exponential with little benefit. See PR 103821. + if ((num_lh == 1 && num_rh == 1) || num_lh * num_rh > 12) { - wi_fold_in_parts (r, type, lh.lower_bound (0), lh.upper_bound (0), - rh.lower_bound (0), rh.upper_bound (0)); + wi_fold_in_parts (r, type, lh.lower_bound (), lh.upper_bound (), + rh.lower_bound (), rh.upper_bound ()); op1_op2_relation_effect (r, type, lh, rh, rel); return true; } -- 2.7.4