public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Aldy Hernandez <aldyh@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
	Andrew MacLeod <amacleod@redhat.com>
Subject: Re: [patch] new API for value_range
Date: Wed, 10 Oct 2018 11:17:00 -0000	[thread overview]
Message-ID: <CAFiYyc2=o2OiVRnxKj=yTsz397DXYzvfrQOmYb9xk_mOd5grfQ@mail.gmail.com> (raw)
In-Reply-To: <a7ea8660-ec2c-6f1b-63aa-ac5865e65470@redhat.com>

On Tue, Oct 9, 2018 at 6:23 PM Aldy Hernandez <aldyh@redhat.com> wrote:
>
> I'm assuming the silence on the RFC means nobody is viscerally opposed
> to it, so here goes the actual implementation ;-).
>
>         FWI: https://gcc.gnu.org/ml/gcc-patches/2018-10/msg00157.html
>
> My aim is no change to the current functionality, but there are some
> things that changed slightly (with no appreciable change in
> bootstrapability or tests).
>
> 1.  Primarily, we were building value_ranges by modifying them in-flight
> with no regards to the validity of the resulting range.  By enforcing
> the API, I noticed we periodically built VR_VARYING / VR_UNDEFINED, but
> left the equivalence bits uncleared.  This comment in the original
> header file indicates that this is invalid behavior:
>
>    /* Set of SSA names whose value ranges are equivalent to this one.
>       This set is only valid when TYPE is VR_RANGE or VR_ANTI_RANGE.  */
>
> The API now enforces this upon construction.
>
> 2. I also saw us setting min/max when VARYING or UNDEFINED was set.
> This is invalid.  Although these values were being ignored, the API now
> enforces this.
>
> 3. I saw one case in set_value_range_with_overflow() were we were
> building an invalid range with swapped ranges, where we were silently
> depending on somebody further up the call chain to swap them for us.
> I've fixed this at creation.
>
> 4. There is one assert in ipcp_vr_lattice which I hope to remove, but
> left as proof that the original VR_UNDEFINED set was not necessary, as
> it is now done by default on an empty constructor:
>
> -  void init () { m_vr.type = VR_UNDEFINED; }
> +  void init () { gcc_assert (m_vr.undefined_p ()); }
>
> One last note.  The file tree-vrp.c already has a cripple API of sorts
> in the form of functions (set_value_range_to_varying, etc).  I have
> tried to keep those functions available, by calling the API under the
> covers, but would be okay in removing them altogether as a follow-up.
>
> Please refer to the RFC wrt the min/max/vrtype accessors, as well as the
> new tree type field.
>
> I am quoting the class declaration below to make it easy to review at a
> high level.
>
> Tested on x86-64 Linux.  All languages, including Ada and Go.
>
> OK for trunk?

Reviewing in patch order.

> Aldy
>
> class GTY((for_user)) value_range
> {
>   public:
>    value_range ();
>    value_range (tree type);
>    value_range (value_range_type, tree type, tree, tree, bitmap = NULL);
>    bool operator== (const value_range &) const;
>    bool operator!= (const value_range &) const;
>    void intersect (const value_range *);
>    void union_ (const value_range *);

with trailing underscore?  seriously?

>    /* Like operator== but ignore equivalence bitmap.  */
>    bool ignore_equivs_equal_p (const value_range &) const;
>    /* Like a operator= but update equivalence bitmap efficiently.  */
>    void copy_with_equiv_update (const value_range *);
>
>    /* Types of value ranges.  */
>    bool undefined_p () const;
>    bool varying_p () const;
>    bool symbolic_p () const;
>    bool numeric_p () const;
>    void set_undefined (tree = NULL);
>    void set_varying (tree = NULL);

I'd appreciate comments on those predicates, esp. as you
replace positive tests by negative ones like in

   /* If we found any usable VR, set the VR to ssa_name and create a
      PUSH old value in the stack with the old VR.  */
-  if (vr.type == VR_RANGE || vr.type == VR_ANTI_RANGE)
+  if (!vr.undefined_p () && !vr.varying_p ())
     {

I'd also spell numeric_p as constant_p or drop it alltogether
since !symbolic_p should imply it given varying_p and undefined_p
are just some special-cases of "numeric_p" (full and empty range).

That said, for the time being I'd use non_symbolic_range_or_anti_range_p
instead of numeric_p () (seeing that you maybe want to hide the fact
that we have anti-ranges?)

-  value_range vr = VR_INITIALIZER;
+  value_range vr (TREE_TYPE (name));

so you basically forgo with the fact that empty ranges are universal?
I don't like it too much that we have to invent a type here.  Why enforce this
and not allow/force type == NULL_TREE for empty ranges?

One could argue VARYING is also universal to some extent and useful
only with context, so similar argument applies to your change forcing
a type for set_value_range_to_varying.

-      value_range vr = VR_INITIALIZER;
+      value_range vr;

oh, so you do have a default constructor.

>
>    /* Equivalence bitmap methods.  */
>    bitmap equiv () const;
>    void set_equiv (bitmap);

Err, I think we've settled on _not_ wrapping all member accesses
with get/set methods, didn't we?  I personally dislike that very much.

>    void equiv_free ();
>    void equiv_copy (const value_range *);
>    void equiv_clear ();
>    void equiv_and (const value_range *);
>    void equiv_ior (const value_range *);

Likewise I find this useless abstraction.  It's even questionable
if _free/_clear/_copy are good APIs here.  This should be all
hidden in intersect/union which I do not find in the API at all...

>
>    /* Misc methods.  */
>    tree type () const;

type() and vrtype() is confusing - value_type() and range_kind() maybe?

>    bool null_p () const;
>    bool may_contain_p (tree) const;
>    tree singleton () const;

No documentation? :/   Why null_p but singleton (instead of singleton_p)?

>    void set_and_canonicalize (enum value_range_type, tree, tree, tree,
> bitmap);

Why's that necessary if you enforce sanity?

>    void dump () const;
>
>    /* Temporary accessors that should eventually be removed.  */
>    enum value_range_type vrtype () const;
>    tree min () const;
>    tree max () const;
>
>   private:
>    void set (value_range_type, tree type, tree, tree, bitmap);
>    void check ();
>    bool equal_p (const value_range &, bool ignore_equivs) const;
>
>    enum value_range_type m_vrtype;
>   public:
>    /* These should be private, but GTY is a piece of crap.  */
>    tree m_min;
>    tree m_max;
>    tree m_type;

m_type is redundant (see above).

>    /* Set of SSA names whose value ranges are equivalent to this one.
>       This set is only valid when TYPE is VR_RANGE or VR_ANTI_RANGE.  */
>    bitmap m_equiv;
> };



>

  reply	other threads:[~2018-10-10 10:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-09 17:04 Aldy Hernandez
2018-10-10 11:17 ` Richard Biener [this message]
2018-10-11  9:47   ` Aldy Hernandez
2018-10-11 10:12     ` Richard Biener
2018-10-11 18:33       ` Aldy Hernandez
2018-10-17 10:17         ` PING: Fwd: " Aldy Hernandez
2018-10-17 12:06         ` Richard Biener
2018-10-17 15:46           ` Aldy Hernandez
2018-10-21  8:51             ` H.J. Lu
2018-10-21 17:48               ` Aldy Hernandez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFiYyc2=o2OiVRnxKj=yTsz397DXYzvfrQOmYb9xk_mOd5grfQ@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).