https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107561

--- Comment #12 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #10)
> (In reply to Richard Biener from comment #9)
> > Note I think there's still a bug in value_range (irange) here. 
> > get_size_range
> > does
> > 
> >   if (integral)
> >     {
> >       value_range vr;
> > 
> >       query->range_of_expr (vr, exp, stmt);
> > 
> >       if (vr.undefined_p ())
> >         vr.set_varying (TREE_TYPE (exp));
> >       range_type = vr.kind ();
> >       min = wi::to_wide (vr.min ());
> >       max = wi::to_wide (vr.max ());
> > 
> > and we have vr:
> > 
> > (gdb) p vr
> > $13 = {<irange> = {<vrange> = {
> >       _vptr.vrange = 0x3693a30 <vtable for int_range<1u>+16>, 
> >       m_kind = VR_ANTI_RANGE, m_discriminator = VR_IRANGE}, 
> >     m_num_ranges = 1 '\001', m_max_ranges = 1 '\001', 
> >     m_nonzero_mask = <tree 0x0>, m_base = 0x7fffffffc8f0}, m_ranges = {
> >     <integer_cst 0x7ffff68143f0>, <integer_cst 0x7ffff5e82090>}}
> > (gdb) p vr.dump (stderr)
> > [irange] unsigned int [0, 0][8, +INF]$17 = void
> > 
> > but vr.min () produces 1 and vr.max () produces 7, just as if it doesn't
> > interpret VR_ANTI_RANGE transparently here (if that's the intent?!).
> > At least
> > 
> > // Return the highest bound of a range expressed as a tree.
> > 
> > inline tree
> > irange::tree_upper_bound () const
> > 
> > suggests that.  Note that vr.num_pairs () produces 2 (because constant_p ())
> > but vr.m_num_ranges is 1 and tree_upper_bound uses m_num_ranges.
> > 
> > I suppose irange::{min,max,tree_lower_bound,tree_upper_bound} miss "support"
> > for legacy_mode_p here.
> 
> OTOH gimple-array-bounds.cc does
> 
>   const value_range *vr = NULL;
>   if (TREE_CODE (low_sub_org) == SSA_NAME)
>     {                
>       vr = get_value_range (low_sub_org, stmt);
>       if (!vr->undefined_p () && !vr->varying_p ())
>         {
>           low_sub = vr->kind () == VR_RANGE ? vr->max () : vr->min ();
>           up_sub = vr->kind () == VR_RANGE ? vr->min () : vr->max ();
>         }
> 
> so the bug is a documentation bug on min/max/lower/upper bound?!
> 
> I'm policeing other uses of value_range right now.

Haven't looked at this yet, but min/max/lower/upper bound are broken and
inconsistent.  They give different results in legacy and the new irange API. 
This was not by intent, but it crept in :/.  My fault.  I noticed this when
removing the legacy code for next stage1.

Reply via email to