diff mbox series

Convert ipa_jump_func to use ipa_vr instead of a value_range.

Message ID 20230522185622.537454-1-aldyh@redhat.com
State New
Headers show
Series Convert ipa_jump_func to use ipa_vr instead of a value_range. | expand

Commit Message

Aldy Hernandez May 22, 2023, 6:56 p.m. UTC
This patch converts the ipa_jump_func code to use the type agnostic
ipa_vr suitable for GC instead of value_range which is integer specific.

I've disabled the range cacheing to simplify the patch for review, but
it is handled in the next patch in the series.

OK?

gcc/ChangeLog:

	* ipa-cp.cc (ipa_vr_operation_and_type_effects): New.
	* ipa-prop.cc (ipa_get_value_range): Adjust for ipa_vr.
	(ipa_set_jfunc_vr): Take a range.
	(ipa_compute_jump_functions_for_edge): Pass range to
	ipa_set_jfunc_vr.
	(ipa_write_jump_function): Call streamer write helper.
	(ipa_read_jump_function): Call streamer read helper.
	* ipa-prop.h (class ipa_vr): Change m_vr to an ipa_vr.
---
 gcc/ipa-cp.cc   | 15 +++++++++++
 gcc/ipa-prop.cc | 70 ++++++++++++++++++-------------------------------
 gcc/ipa-prop.h  |  5 +++-
 3 files changed, 44 insertions(+), 46 deletions(-)

Comments

Aldy Hernandez June 14, 2023, 12:09 p.m. UTC | #1
PING

On Mon, May 22, 2023 at 8:56 PM Aldy Hernandez <aldyh@redhat.com> wrote:
>
> This patch converts the ipa_jump_func code to use the type agnostic
> ipa_vr suitable for GC instead of value_range which is integer specific.
>
> I've disabled the range cacheing to simplify the patch for review, but
> it is handled in the next patch in the series.
>
> OK?
>
> gcc/ChangeLog:
>
>         * ipa-cp.cc (ipa_vr_operation_and_type_effects): New.
>         * ipa-prop.cc (ipa_get_value_range): Adjust for ipa_vr.
>         (ipa_set_jfunc_vr): Take a range.
>         (ipa_compute_jump_functions_for_edge): Pass range to
>         ipa_set_jfunc_vr.
>         (ipa_write_jump_function): Call streamer write helper.
>         (ipa_read_jump_function): Call streamer read helper.
>         * ipa-prop.h (class ipa_vr): Change m_vr to an ipa_vr.
> ---
>  gcc/ipa-cp.cc   | 15 +++++++++++
>  gcc/ipa-prop.cc | 70 ++++++++++++++++++-------------------------------
>  gcc/ipa-prop.h  |  5 +++-
>  3 files changed, 44 insertions(+), 46 deletions(-)
>
> diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
> index bdbc2184b5f..03273666ea2 100644
> --- a/gcc/ipa-cp.cc
> +++ b/gcc/ipa-cp.cc
> @@ -1928,6 +1928,21 @@ ipa_vr_operation_and_type_effects (vrange &dst_vr,
>           && !dst_vr.undefined_p ());
>  }
>
> +/* Same as above, but the SRC_VR argument is an IPA_VR which must
> +   first be extracted onto a vrange.  */
> +
> +static bool
> +ipa_vr_operation_and_type_effects (vrange &dst_vr,
> +                                  const ipa_vr &src_vr,
> +                                  enum tree_code operation,
> +                                  tree dst_type, tree src_type)
> +{
> +  Value_Range tmp;
> +  src_vr.get_vrange (tmp);
> +  return ipa_vr_operation_and_type_effects (dst_vr, tmp, operation,
> +                                           dst_type, src_type);
> +}
> +
>  /* Determine range of JFUNC given that INFO describes the caller node or
>     the one it is inlined to, CS is the call graph edge corresponding to JFUNC
>     and PARM_TYPE of the parameter.  */
> diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
> index bbfe0f8aa45..c46a89f1b49 100644
> --- a/gcc/ipa-prop.cc
> +++ b/gcc/ipa-prop.cc
> @@ -2287,9 +2287,10 @@ ipa_set_jfunc_bits (ipa_jump_func *jf, const widest_int &value,
>  /* Return a pointer to a value_range just like *TMP, but either find it in
>     ipa_vr_hash_table or allocate it in GC memory.  TMP->equiv must be NULL.  */
>
> -static value_range *
> -ipa_get_value_range (value_range *tmp)
> +static ipa_vr *
> +ipa_get_value_range (const vrange &tmp)
>  {
> +  /* FIXME: Add hashing support.
>    value_range **slot = ipa_vr_hash_table->find_slot (tmp, INSERT);
>    if (*slot)
>      return *slot;
> @@ -2297,40 +2298,27 @@ ipa_get_value_range (value_range *tmp)
>    value_range *vr = new (ggc_alloc<value_range> ()) value_range;
>    *vr = *tmp;
>    *slot = vr;
> +  */
> +  ipa_vr *vr = new (ggc_alloc<ipa_vr> ()) ipa_vr (tmp);
>
>    return vr;
>  }
>
> -/* Return a pointer to a value range consisting of TYPE, MIN, MAX and an empty
> -   equiv set. Use hash table in order to avoid creating multiple same copies of
> -   value_ranges.  */
> -
> -static value_range *
> -ipa_get_value_range (enum value_range_kind kind, tree min, tree max)
> -{
> -  value_range tmp (TREE_TYPE (min),
> -                  wi::to_wide (min), wi::to_wide (max), kind);
> -  return ipa_get_value_range (&tmp);
> -}
> -
> -/* Assign to JF a pointer to a value_range structure with TYPE, MIN and MAX and
> -   a NULL equiv bitmap.  Use hash table in order to avoid creating multiple
> -   same value_range structures.  */
> +/* Assign to JF a pointer to a value_range just like TMP but either fetch a
> +   copy from ipa_vr_hash_table or allocate a new on in GC memory.  */
>
>  static void
> -ipa_set_jfunc_vr (ipa_jump_func *jf, enum value_range_kind type,
> -                 tree min, tree max)
> +ipa_set_jfunc_vr (ipa_jump_func *jf, const vrange &tmp)
>  {
> -  jf->m_vr = ipa_get_value_range (type, min, max);
> +  jf->m_vr = ipa_get_value_range (tmp);
>  }
>
> -/* Assign to JF a pointer to a value_range just like TMP but either fetch a
> -   copy from ipa_vr_hash_table or allocate a new on in GC memory.  */
> -
>  static void
> -ipa_set_jfunc_vr (ipa_jump_func *jf, value_range *tmp)
> +ipa_set_jfunc_vr (ipa_jump_func *jf, const ipa_vr &vr)
>  {
> -  jf->m_vr = ipa_get_value_range (tmp);
> +  Value_Range tmp;
> +  vr.get_vrange (tmp);
> +  ipa_set_jfunc_vr (jf, tmp);
>  }
>
>  /* Compute jump function for all arguments of callsite CS and insert the
> @@ -2392,8 +2380,8 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
>
>           if (addr_nonzero)
>             {
> -             tree z = build_int_cst (TREE_TYPE (arg), 0);
> -             ipa_set_jfunc_vr (jfunc, VR_ANTI_RANGE, z, z);
> +             vr.set_nonzero (TREE_TYPE (arg));
> +             ipa_set_jfunc_vr (jfunc, vr);
>             }
>           else
>             gcc_assert (!jfunc->m_vr);
> @@ -2412,7 +2400,7 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
>               value_range resvr = vr;
>               range_cast (resvr, param_type);
>               if (!resvr.undefined_p () && !resvr.varying_p ())
> -               ipa_set_jfunc_vr (jfunc, &resvr);
> +               ipa_set_jfunc_vr (jfunc, resvr);
>               else
>                 gcc_assert (!jfunc->m_vr);
>             }
> @@ -4864,16 +4852,12 @@ ipa_write_jump_function (struct output_block *ob,
>        streamer_write_widest_int (ob, jump_func->bits->value);
>        streamer_write_widest_int (ob, jump_func->bits->mask);
>      }
> -  bp_pack_value (&bp, !!jump_func->m_vr, 1);
> -  streamer_write_bitpack (&bp);
>    if (jump_func->m_vr)
> +    jump_func->m_vr->streamer_write (ob);
> +  else
>      {
> -      tree min, max;
> -      value_range_kind kind = get_legacy_range (*jump_func->m_vr, min, max);
> -      streamer_write_enum (ob->main_stream, value_rang_type,
> -                          VR_LAST, kind);
> -      stream_write_tree (ob, min, true);
> -      stream_write_tree (ob, max, true);
> +      bp_pack_value (&bp, false, 1);
> +      streamer_write_bitpack (&bp);
>      }
>  }
>
> @@ -5001,21 +4985,17 @@ ipa_read_jump_function (class lto_input_block *ib,
>        widest_int value = streamer_read_widest_int (ib);
>        widest_int mask = streamer_read_widest_int (ib);
>        if (prevails)
> -        ipa_set_jfunc_bits (jump_func, value, mask);
> +       ipa_set_jfunc_bits (jump_func, value, mask);
>      }
>    else
>      jump_func->bits = NULL;
>
> -  struct bitpack_d vr_bp = streamer_read_bitpack (ib);
> -  bool vr_known = bp_unpack_value (&vr_bp, 1);
> -  if (vr_known)
> +  ipa_vr vr;
> +  vr.streamer_read (ib, data_in);
> +  if (vr.known_p ())
>      {
> -      enum value_range_kind type = streamer_read_enum (ib, value_range_kind,
> -                                                      VR_LAST);
> -      tree min = stream_read_tree (ib, data_in);
> -      tree max = stream_read_tree (ib, data_in);
>        if (prevails)
> -        ipa_set_jfunc_vr (jump_func, type, min, max);
> +       ipa_set_jfunc_vr (jump_func, vr);
>      }
>    else
>      jump_func->m_vr = NULL;
> diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h
> index f87e8a596c1..33fad228913 100644
> --- a/gcc/ipa-prop.h
> +++ b/gcc/ipa-prop.h
> @@ -325,6 +325,9 @@ private:
>    friend void gt_pch_nx (struct ipa_vr &);
>    friend void gt_ggc_mx (struct ipa_vr &);
>    friend void gt_pch_nx (struct ipa_vr *, gt_pointer_operator, void *);
> +  friend void gt_ggc_mx_ipa_vr (void *);
> +  friend void gt_pch_nx_ipa_vr (void*);
> +  friend void gt_pch_p_6ipa_vr(void*, void*, gt_pointer_operator, void*);
>
>    vrange_storage *m_storage;
>    // vrange_storage is typeless, but we need to know what type of
> @@ -351,7 +354,7 @@ struct GTY (()) ipa_jump_func
>    /* Information about value range, containing valid data only when vr_known is
>       true.  The pointed to structure is shared betweed different jump
>       functions.  Use ipa_set_jfunc_vr to set this field.  */
> -  value_range *m_vr;
> +  ipa_vr *m_vr;
>
>    enum jump_func_type type;
>    /* Represents a value of a jump function.  pass_through is used only in jump
> --
> 2.40.1
>
Aldy Hernandez June 22, 2023, 5:49 a.m. UTC | #2
Ping*2

On Wed, Jun 14, 2023, 14:09 Aldy Hernandez <aldyh@redhat.com> wrote:

> PING
>
> On Mon, May 22, 2023 at 8:56 PM Aldy Hernandez <aldyh@redhat.com> wrote:
> >
> > This patch converts the ipa_jump_func code to use the type agnostic
> > ipa_vr suitable for GC instead of value_range which is integer specific.
> >
> > I've disabled the range cacheing to simplify the patch for review, but
> > it is handled in the next patch in the series.
> >
> > OK?
> >
> > gcc/ChangeLog:
> >
> >         * ipa-cp.cc (ipa_vr_operation_and_type_effects): New.
> >         * ipa-prop.cc (ipa_get_value_range): Adjust for ipa_vr.
> >         (ipa_set_jfunc_vr): Take a range.
> >         (ipa_compute_jump_functions_for_edge): Pass range to
> >         ipa_set_jfunc_vr.
> >         (ipa_write_jump_function): Call streamer write helper.
> >         (ipa_read_jump_function): Call streamer read helper.
> >         * ipa-prop.h (class ipa_vr): Change m_vr to an ipa_vr.
> > ---
> >  gcc/ipa-cp.cc   | 15 +++++++++++
> >  gcc/ipa-prop.cc | 70 ++++++++++++++++++-------------------------------
> >  gcc/ipa-prop.h  |  5 +++-
> >  3 files changed, 44 insertions(+), 46 deletions(-)
> >
> > diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
> > index bdbc2184b5f..03273666ea2 100644
> > --- a/gcc/ipa-cp.cc
> > +++ b/gcc/ipa-cp.cc
> > @@ -1928,6 +1928,21 @@ ipa_vr_operation_and_type_effects (vrange &dst_vr,
> >           && !dst_vr.undefined_p ());
> >  }
> >
> > +/* Same as above, but the SRC_VR argument is an IPA_VR which must
> > +   first be extracted onto a vrange.  */
> > +
> > +static bool
> > +ipa_vr_operation_and_type_effects (vrange &dst_vr,
> > +                                  const ipa_vr &src_vr,
> > +                                  enum tree_code operation,
> > +                                  tree dst_type, tree src_type)
> > +{
> > +  Value_Range tmp;
> > +  src_vr.get_vrange (tmp);
> > +  return ipa_vr_operation_and_type_effects (dst_vr, tmp, operation,
> > +                                           dst_type, src_type);
> > +}
> > +
> >  /* Determine range of JFUNC given that INFO describes the caller node or
> >     the one it is inlined to, CS is the call graph edge corresponding to
> JFUNC
> >     and PARM_TYPE of the parameter.  */
> > diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
> > index bbfe0f8aa45..c46a89f1b49 100644
> > --- a/gcc/ipa-prop.cc
> > +++ b/gcc/ipa-prop.cc
> > @@ -2287,9 +2287,10 @@ ipa_set_jfunc_bits (ipa_jump_func *jf, const
> widest_int &value,
> >  /* Return a pointer to a value_range just like *TMP, but either find it
> in
> >     ipa_vr_hash_table or allocate it in GC memory.  TMP->equiv must be
> NULL.  */
> >
> > -static value_range *
> > -ipa_get_value_range (value_range *tmp)
> > +static ipa_vr *
> > +ipa_get_value_range (const vrange &tmp)
> >  {
> > +  /* FIXME: Add hashing support.
> >    value_range **slot = ipa_vr_hash_table->find_slot (tmp, INSERT);
> >    if (*slot)
> >      return *slot;
> > @@ -2297,40 +2298,27 @@ ipa_get_value_range (value_range *tmp)
> >    value_range *vr = new (ggc_alloc<value_range> ()) value_range;
> >    *vr = *tmp;
> >    *slot = vr;
> > +  */
> > +  ipa_vr *vr = new (ggc_alloc<ipa_vr> ()) ipa_vr (tmp);
> >
> >    return vr;
> >  }
> >
> > -/* Return a pointer to a value range consisting of TYPE, MIN, MAX and
> an empty
> > -   equiv set. Use hash table in order to avoid creating multiple same
> copies of
> > -   value_ranges.  */
> > -
> > -static value_range *
> > -ipa_get_value_range (enum value_range_kind kind, tree min, tree max)
> > -{
> > -  value_range tmp (TREE_TYPE (min),
> > -                  wi::to_wide (min), wi::to_wide (max), kind);
> > -  return ipa_get_value_range (&tmp);
> > -}
> > -
> > -/* Assign to JF a pointer to a value_range structure with TYPE, MIN and
> MAX and
> > -   a NULL equiv bitmap.  Use hash table in order to avoid creating
> multiple
> > -   same value_range structures.  */
> > +/* Assign to JF a pointer to a value_range just like TMP but either
> fetch a
> > +   copy from ipa_vr_hash_table or allocate a new on in GC memory.  */
> >
> >  static void
> > -ipa_set_jfunc_vr (ipa_jump_func *jf, enum value_range_kind type,
> > -                 tree min, tree max)
> > +ipa_set_jfunc_vr (ipa_jump_func *jf, const vrange &tmp)
> >  {
> > -  jf->m_vr = ipa_get_value_range (type, min, max);
> > +  jf->m_vr = ipa_get_value_range (tmp);
> >  }
> >
> > -/* Assign to JF a pointer to a value_range just like TMP but either
> fetch a
> > -   copy from ipa_vr_hash_table or allocate a new on in GC memory.  */
> > -
> >  static void
> > -ipa_set_jfunc_vr (ipa_jump_func *jf, value_range *tmp)
> > +ipa_set_jfunc_vr (ipa_jump_func *jf, const ipa_vr &vr)
> >  {
> > -  jf->m_vr = ipa_get_value_range (tmp);
> > +  Value_Range tmp;
> > +  vr.get_vrange (tmp);
> > +  ipa_set_jfunc_vr (jf, tmp);
> >  }
> >
> >  /* Compute jump function for all arguments of callsite CS and insert the
> > @@ -2392,8 +2380,8 @@ ipa_compute_jump_functions_for_edge (struct
> ipa_func_body_info *fbi,
> >
> >           if (addr_nonzero)
> >             {
> > -             tree z = build_int_cst (TREE_TYPE (arg), 0);
> > -             ipa_set_jfunc_vr (jfunc, VR_ANTI_RANGE, z, z);
> > +             vr.set_nonzero (TREE_TYPE (arg));
> > +             ipa_set_jfunc_vr (jfunc, vr);
> >             }
> >           else
> >             gcc_assert (!jfunc->m_vr);
> > @@ -2412,7 +2400,7 @@ ipa_compute_jump_functions_for_edge (struct
> ipa_func_body_info *fbi,
> >               value_range resvr = vr;
> >               range_cast (resvr, param_type);
> >               if (!resvr.undefined_p () && !resvr.varying_p ())
> > -               ipa_set_jfunc_vr (jfunc, &resvr);
> > +               ipa_set_jfunc_vr (jfunc, resvr);
> >               else
> >                 gcc_assert (!jfunc->m_vr);
> >             }
> > @@ -4864,16 +4852,12 @@ ipa_write_jump_function (struct output_block *ob,
> >        streamer_write_widest_int (ob, jump_func->bits->value);
> >        streamer_write_widest_int (ob, jump_func->bits->mask);
> >      }
> > -  bp_pack_value (&bp, !!jump_func->m_vr, 1);
> > -  streamer_write_bitpack (&bp);
> >    if (jump_func->m_vr)
> > +    jump_func->m_vr->streamer_write (ob);
> > +  else
> >      {
> > -      tree min, max;
> > -      value_range_kind kind = get_legacy_range (*jump_func->m_vr, min,
> max);
> > -      streamer_write_enum (ob->main_stream, value_rang_type,
> > -                          VR_LAST, kind);
> > -      stream_write_tree (ob, min, true);
> > -      stream_write_tree (ob, max, true);
> > +      bp_pack_value (&bp, false, 1);
> > +      streamer_write_bitpack (&bp);
> >      }
> >  }
> >
> > @@ -5001,21 +4985,17 @@ ipa_read_jump_function (class lto_input_block
> *ib,
> >        widest_int value = streamer_read_widest_int (ib);
> >        widest_int mask = streamer_read_widest_int (ib);
> >        if (prevails)
> > -        ipa_set_jfunc_bits (jump_func, value, mask);
> > +       ipa_set_jfunc_bits (jump_func, value, mask);
> >      }
> >    else
> >      jump_func->bits = NULL;
> >
> > -  struct bitpack_d vr_bp = streamer_read_bitpack (ib);
> > -  bool vr_known = bp_unpack_value (&vr_bp, 1);
> > -  if (vr_known)
> > +  ipa_vr vr;
> > +  vr.streamer_read (ib, data_in);
> > +  if (vr.known_p ())
> >      {
> > -      enum value_range_kind type = streamer_read_enum (ib,
> value_range_kind,
> > -                                                      VR_LAST);
> > -      tree min = stream_read_tree (ib, data_in);
> > -      tree max = stream_read_tree (ib, data_in);
> >        if (prevails)
> > -        ipa_set_jfunc_vr (jump_func, type, min, max);
> > +       ipa_set_jfunc_vr (jump_func, vr);
> >      }
> >    else
> >      jump_func->m_vr = NULL;
> > diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h
> > index f87e8a596c1..33fad228913 100644
> > --- a/gcc/ipa-prop.h
> > +++ b/gcc/ipa-prop.h
> > @@ -325,6 +325,9 @@ private:
> >    friend void gt_pch_nx (struct ipa_vr &);
> >    friend void gt_ggc_mx (struct ipa_vr &);
> >    friend void gt_pch_nx (struct ipa_vr *, gt_pointer_operator, void *);
> > +  friend void gt_ggc_mx_ipa_vr (void *);
> > +  friend void gt_pch_nx_ipa_vr (void*);
> > +  friend void gt_pch_p_6ipa_vr(void*, void*, gt_pointer_operator,
> void*);
> >
> >    vrange_storage *m_storage;
> >    // vrange_storage is typeless, but we need to know what type of
> > @@ -351,7 +354,7 @@ struct GTY (()) ipa_jump_func
> >    /* Information about value range, containing valid data only when
> vr_known is
> >       true.  The pointed to structure is shared betweed different jump
> >       functions.  Use ipa_set_jfunc_vr to set this field.  */
> > -  value_range *m_vr;
> > +  ipa_vr *m_vr;
> >
> >    enum jump_func_type type;
> >    /* Represents a value of a jump function.  pass_through is used only
> in jump
> > --
> > 2.40.1
> >
>
Martin Jambor June 26, 2023, 4:40 p.m. UTC | #3
Hi,

On Mon, May 22 2023, Aldy Hernandez via Gcc-patches wrote:
> This patch converts the ipa_jump_func code to use the type agnostic
> ipa_vr suitable for GC instead of value_range which is integer specific.
>
> I've disabled the range cacheing to simplify the patch for review, but
> it is handled in the next patch in the series.
>
> OK?
>
> gcc/ChangeLog:
>
> 	* ipa-cp.cc (ipa_vr_operation_and_type_effects): New.
> 	* ipa-prop.cc (ipa_get_value_range): Adjust for ipa_vr.
> 	(ipa_set_jfunc_vr): Take a range.
> 	(ipa_compute_jump_functions_for_edge): Pass range to
> 	ipa_set_jfunc_vr.
> 	(ipa_write_jump_function): Call streamer write helper.
> 	(ipa_read_jump_function): Call streamer read helper.
> 	* ipa-prop.h (class ipa_vr): Change m_vr to an ipa_vr.

OK, thanks and sorry for the waiting, I've been unexpectedly traveling
last week.

Martin

> ---
>  gcc/ipa-cp.cc   | 15 +++++++++++
>  gcc/ipa-prop.cc | 70 ++++++++++++++++++-------------------------------
>  gcc/ipa-prop.h  |  5 +++-
>  3 files changed, 44 insertions(+), 46 deletions(-)
>
[...]
diff mbox series

Patch

diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
index bdbc2184b5f..03273666ea2 100644
--- a/gcc/ipa-cp.cc
+++ b/gcc/ipa-cp.cc
@@ -1928,6 +1928,21 @@  ipa_vr_operation_and_type_effects (vrange &dst_vr,
 	  && !dst_vr.undefined_p ());
 }
 
+/* Same as above, but the SRC_VR argument is an IPA_VR which must
+   first be extracted onto a vrange.  */
+
+static bool
+ipa_vr_operation_and_type_effects (vrange &dst_vr,
+				   const ipa_vr &src_vr,
+				   enum tree_code operation,
+				   tree dst_type, tree src_type)
+{
+  Value_Range tmp;
+  src_vr.get_vrange (tmp);
+  return ipa_vr_operation_and_type_effects (dst_vr, tmp, operation,
+					    dst_type, src_type);
+}
+
 /* Determine range of JFUNC given that INFO describes the caller node or
    the one it is inlined to, CS is the call graph edge corresponding to JFUNC
    and PARM_TYPE of the parameter.  */
diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index bbfe0f8aa45..c46a89f1b49 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -2287,9 +2287,10 @@  ipa_set_jfunc_bits (ipa_jump_func *jf, const widest_int &value,
 /* Return a pointer to a value_range just like *TMP, but either find it in
    ipa_vr_hash_table or allocate it in GC memory.  TMP->equiv must be NULL.  */
 
-static value_range *
-ipa_get_value_range (value_range *tmp)
+static ipa_vr *
+ipa_get_value_range (const vrange &tmp)
 {
+  /* FIXME: Add hashing support.
   value_range **slot = ipa_vr_hash_table->find_slot (tmp, INSERT);
   if (*slot)
     return *slot;
@@ -2297,40 +2298,27 @@  ipa_get_value_range (value_range *tmp)
   value_range *vr = new (ggc_alloc<value_range> ()) value_range;
   *vr = *tmp;
   *slot = vr;
+  */
+  ipa_vr *vr = new (ggc_alloc<ipa_vr> ()) ipa_vr (tmp);
 
   return vr;
 }
 
-/* Return a pointer to a value range consisting of TYPE, MIN, MAX and an empty
-   equiv set. Use hash table in order to avoid creating multiple same copies of
-   value_ranges.  */
-
-static value_range *
-ipa_get_value_range (enum value_range_kind kind, tree min, tree max)
-{
-  value_range tmp (TREE_TYPE (min),
-		   wi::to_wide (min), wi::to_wide (max), kind);
-  return ipa_get_value_range (&tmp);
-}
-
-/* Assign to JF a pointer to a value_range structure with TYPE, MIN and MAX and
-   a NULL equiv bitmap.  Use hash table in order to avoid creating multiple
-   same value_range structures.  */
+/* Assign to JF a pointer to a value_range just like TMP but either fetch a
+   copy from ipa_vr_hash_table or allocate a new on in GC memory.  */
 
 static void
-ipa_set_jfunc_vr (ipa_jump_func *jf, enum value_range_kind type,
-		  tree min, tree max)
+ipa_set_jfunc_vr (ipa_jump_func *jf, const vrange &tmp)
 {
-  jf->m_vr = ipa_get_value_range (type, min, max);
+  jf->m_vr = ipa_get_value_range (tmp);
 }
 
-/* Assign to JF a pointer to a value_range just like TMP but either fetch a
-   copy from ipa_vr_hash_table or allocate a new on in GC memory.  */
-
 static void
-ipa_set_jfunc_vr (ipa_jump_func *jf, value_range *tmp)
+ipa_set_jfunc_vr (ipa_jump_func *jf, const ipa_vr &vr)
 {
-  jf->m_vr = ipa_get_value_range (tmp);
+  Value_Range tmp;
+  vr.get_vrange (tmp);
+  ipa_set_jfunc_vr (jf, tmp);
 }
 
 /* Compute jump function for all arguments of callsite CS and insert the
@@ -2392,8 +2380,8 @@  ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
 
 	  if (addr_nonzero)
 	    {
-	      tree z = build_int_cst (TREE_TYPE (arg), 0);
-	      ipa_set_jfunc_vr (jfunc, VR_ANTI_RANGE, z, z);
+	      vr.set_nonzero (TREE_TYPE (arg));
+	      ipa_set_jfunc_vr (jfunc, vr);
 	    }
 	  else
 	    gcc_assert (!jfunc->m_vr);
@@ -2412,7 +2400,7 @@  ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
 	      value_range resvr = vr;
 	      range_cast (resvr, param_type);
 	      if (!resvr.undefined_p () && !resvr.varying_p ())
-		ipa_set_jfunc_vr (jfunc, &resvr);
+		ipa_set_jfunc_vr (jfunc, resvr);
 	      else
 		gcc_assert (!jfunc->m_vr);
 	    }
@@ -4864,16 +4852,12 @@  ipa_write_jump_function (struct output_block *ob,
       streamer_write_widest_int (ob, jump_func->bits->value);
       streamer_write_widest_int (ob, jump_func->bits->mask);
     }
-  bp_pack_value (&bp, !!jump_func->m_vr, 1);
-  streamer_write_bitpack (&bp);
   if (jump_func->m_vr)
+    jump_func->m_vr->streamer_write (ob);
+  else
     {
-      tree min, max;
-      value_range_kind kind = get_legacy_range (*jump_func->m_vr, min, max);
-      streamer_write_enum (ob->main_stream, value_rang_type,
-			   VR_LAST, kind);
-      stream_write_tree (ob, min, true);
-      stream_write_tree (ob, max, true);
+      bp_pack_value (&bp, false, 1);
+      streamer_write_bitpack (&bp);
     }
 }
 
@@ -5001,21 +4985,17 @@  ipa_read_jump_function (class lto_input_block *ib,
       widest_int value = streamer_read_widest_int (ib);
       widest_int mask = streamer_read_widest_int (ib);
       if (prevails)
-        ipa_set_jfunc_bits (jump_func, value, mask);
+	ipa_set_jfunc_bits (jump_func, value, mask);
     }
   else
     jump_func->bits = NULL;
 
-  struct bitpack_d vr_bp = streamer_read_bitpack (ib);
-  bool vr_known = bp_unpack_value (&vr_bp, 1);
-  if (vr_known)
+  ipa_vr vr;
+  vr.streamer_read (ib, data_in);
+  if (vr.known_p ())
     {
-      enum value_range_kind type = streamer_read_enum (ib, value_range_kind,
-						       VR_LAST);
-      tree min = stream_read_tree (ib, data_in);
-      tree max = stream_read_tree (ib, data_in);
       if (prevails)
-        ipa_set_jfunc_vr (jump_func, type, min, max);
+	ipa_set_jfunc_vr (jump_func, vr);
     }
   else
     jump_func->m_vr = NULL;
diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h
index f87e8a596c1..33fad228913 100644
--- a/gcc/ipa-prop.h
+++ b/gcc/ipa-prop.h
@@ -325,6 +325,9 @@  private:
   friend void gt_pch_nx (struct ipa_vr &);
   friend void gt_ggc_mx (struct ipa_vr &);
   friend void gt_pch_nx (struct ipa_vr *, gt_pointer_operator, void *);
+  friend void gt_ggc_mx_ipa_vr (void *);
+  friend void gt_pch_nx_ipa_vr (void*);
+  friend void gt_pch_p_6ipa_vr(void*, void*, gt_pointer_operator, void*);
 
   vrange_storage *m_storage;
   // vrange_storage is typeless, but we need to know what type of
@@ -351,7 +354,7 @@  struct GTY (()) ipa_jump_func
   /* Information about value range, containing valid data only when vr_known is
      true.  The pointed to structure is shared betweed different jump
      functions.  Use ipa_set_jfunc_vr to set this field.  */
-  value_range *m_vr;
+  ipa_vr *m_vr;
 
   enum jump_func_type type;
   /* Represents a value of a jump function.  pass_through is used only in jump