On Mon, Dec 05, 2022 at 10:54:41AM +0100, Aldy Hernandez wrote: > > Do you mind if I try that incrementally and only if it doesn't make the > > code too large/too unreadable? > > Sure. And don't feel obligated to implement it either. range-ops is a > never ending pit of possible optimizations. We found that out quite early > in the design. > > If you don't get to it, could you at least add a comment?
So like this for multiplication op1/2_range if it passes bootstrap/regtest? For division I'll need to go to a drawing board... 2022-12-05 Jakub Jelinek <ja...@redhat.com> * range-op-float.cc (zero_to_max_range): New function. (foperator_plus::op1_range): If lhs can't be INF nor NAN, op1 can't be INF. --- gcc/range-op-float.cc.jj 2022-12-05 11:17:34.900573272 +0100 +++ gcc/range-op-float.cc 2022-12-05 12:32:30.286753929 +0100 @@ -2004,6 +2004,29 @@ zero_to_inf_range (REAL_VALUE_TYPE &lb, } } +// Set [lb, ub] to [-MAX, -0], [-MAX, +MAX] or [+0, +MAX] depending on +// signbit_known. +static void +zero_to_max_range (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, tree type, + int signbit_known) +{ + if (signbit_known > 0) + { + lb = dconst0; + ub = real_max_representable (type); + } + else if (signbit_known < 0) + { + lb = real_min_representable (type); + ub = real_value_negate (&dconst0); + } + else + { + lb = real_min_representable (type); + ub = real_max_representable (type); + } +} + class foperator_plus : public range_operator_float { using range_operator_float::op1_range; @@ -2159,7 +2182,14 @@ public: // and perhaps if it can be NAN or not. REAL_VALUE_TYPE lb, ub; int signbit_known = signbit_known_p (lhs_lb, lhs_ub, op2_lb, op2_ub); - zero_to_inf_range (lb, ub, signbit_known); + // If lhs can't be +-INF nor NAN, then op1 can't be +-INF - + // +-INF * anything is either +-INF or NAN (if op2 is +-0 or NAN). + if (!real_isinf (&lhs_lb) + && !real_isinf (&lhs_ub) + && !lhs.maybe_isnan ()) + zero_to_max_range (lb, ub, type, signbit_known); + else + zero_to_inf_range (lb, ub, signbit_known); r.set (type, lb, ub); } // Otherwise, if op2 is a singleton INF and lhs doesn't include INF, Jakub