Message ID | Zl8Z40fy9WIWVsAA@tucnak |
---|---|
State | New |
Headers | show |
Series | ranger: Improve CLZ fold_range [PR115337] | expand |
OK by me... Andrew On 6/4/24 09:42, Jakub Jelinek wrote: > Hi! > > cfn_ctz::fold_range includes special cases for the case where .CTZ has > two arguments and so is well defined at zero, and the second argument is > equal to prec or -1, but cfn_clz::fold_range does that only for the prec > case. -1 is fairly common as well though, because the <stdbit.h> builtins > do use it now, so I think it is worth special casing that. > If we don't know anything about the argument, the difference for > .CLZ (arg, -1) is that previously the result was varying, now it will be > [-1, prec-1]. If we knew arg can't be zero, it used to be optimized before > as well into e.g. [0, prec-1] or similar. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2024-06-04 Jakub Jelinek <jakub@redhat.com> > > PR tree-optimization/115337 > * gimple-range-op.cc (cfn_clz::fold_range): For > m_gimple_call_internal_p handle as a special case also second argument > of -1 next to prec. > > --- gcc/gimple-range-op.cc.jj 2024-05-21 10:19:34.736524824 +0200 > +++ gcc/gimple-range-op.cc 2024-06-04 11:53:35.190005093 +0200 > @@ -941,8 +941,10 @@ cfn_clz::fold_range (irange &r, tree typ > int maxi = prec - 1; > if (m_gimple_call_internal_p) > { > - // Only handle the single common value. > - if (rh.lower_bound () == prec) > + // Handle only the two common values. > + if (rh.lower_bound () == -1) > + mini = -1; > + else if (rh.lower_bound () == prec) > maxi = prec; > else > // Magic value to give up, unless we can prove arg is non-zero. > @@ -953,7 +955,7 @@ cfn_clz::fold_range (irange &r, tree typ > if (wi::gt_p (lh.lower_bound (), 0, TYPE_SIGN (lh.type ()))) > { > maxi = prec - 1 - wi::floor_log2 (lh.lower_bound ()); > - if (mini == -2) > + if (mini < 0) > mini = 0; > } > else if (!range_includes_zero_p (lh)) > @@ -969,11 +971,11 @@ cfn_clz::fold_range (irange &r, tree typ > if (max == 0) > { > // If CLZ_DEFINED_VALUE_AT_ZERO is 2 with VALUE of prec, > - // return [prec, prec], otherwise ignore the range. > - if (maxi == prec) > - mini = prec; > + // return [prec, prec] or [-1, -1], otherwise ignore the range. > + if (maxi == prec || mini == -1) > + mini = maxi; > } > - else > + else if (mini >= 0) > mini = newmini; > > if (mini == -2) > > Jakub >
--- gcc/gimple-range-op.cc.jj 2024-05-21 10:19:34.736524824 +0200 +++ gcc/gimple-range-op.cc 2024-06-04 11:53:35.190005093 +0200 @@ -941,8 +941,10 @@ cfn_clz::fold_range (irange &r, tree typ int maxi = prec - 1; if (m_gimple_call_internal_p) { - // Only handle the single common value. - if (rh.lower_bound () == prec) + // Handle only the two common values. + if (rh.lower_bound () == -1) + mini = -1; + else if (rh.lower_bound () == prec) maxi = prec; else // Magic value to give up, unless we can prove arg is non-zero. @@ -953,7 +955,7 @@ cfn_clz::fold_range (irange &r, tree typ if (wi::gt_p (lh.lower_bound (), 0, TYPE_SIGN (lh.type ()))) { maxi = prec - 1 - wi::floor_log2 (lh.lower_bound ()); - if (mini == -2) + if (mini < 0) mini = 0; } else if (!range_includes_zero_p (lh)) @@ -969,11 +971,11 @@ cfn_clz::fold_range (irange &r, tree typ if (max == 0) { // If CLZ_DEFINED_VALUE_AT_ZERO is 2 with VALUE of prec, - // return [prec, prec], otherwise ignore the range. - if (maxi == prec) - mini = prec; + // return [prec, prec] or [-1, -1], otherwise ignore the range. + if (maxi == prec || mini == -1) + mini = maxi; } - else + else if (mini >= 0) mini = newmini; if (mini == -2)