all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@gmail.com>
To: Bruno Haible <bruno@clisp.org>
Cc: 36370@debbugs.gnu.org, Paul Eggert <eggert@cs.ucla.edu>,
	bug-gnulib@gnu.org
Subject: bug#36370: 27.0.50; XFIXNAT called on negative numbers
Date: Fri, 28 Jun 2019 13:51:24 +0000	[thread overview]
Message-ID: <CAOqdjBfS99UpLZ-qLe4=FMXMsr+T3LUvJEsf_gfmF6wwLbqgOw__12120.8733807848$1561734682$gmane$org@mail.gmail.com> (raw)
In-Reply-To: <8979488.cRkkfcT1mV@omega>

On Fri, Jun 28, 2019 at 12:14 PM Bruno Haible <bruno@clisp.org> wrote:
> Pip Cet wrote:
> > This makes it safe to use function expressions in eassume, whether the
> > function is inlined or not.
>
> By "safe" you mean that you want the function call to not be evaluated.

Sorry, sloppy wording there. You're right.

> You are mentioning a limitation:
>
> > eassume(i >= 0 && i < complicated_function ());
> >
> > will not "split" the && expression, so it'll behave differently from
> >
> > eassume(i >= 0);
> > eassume(i < complicated_function ());
>
> And I would mention a regression: When -flto is in use and the expression
> invokes an external potentially-inlined function, the old 'assume' would
> work fine, i.e. do optimizations across compilation-unit boundaries.

Sorry, can't reproduce that here. I'm sure the changes I need to make
are obvious once I've found them, but can you let me know your gcc
version?

> > But even in those cases, this approach is better than the old approach
> > of actually evaluating complicated_function.
>
> I disagree that it is better:

Sorry to be pedantic, but do you disagree that it is better in these
cases, or in general? The latter is a question that I'm trying to find
the answer to, but in these specific cases, it clearly is better.

(Just in the interest of full disclosure, I described the idea in a
different context; I think it's a neat hack, and I'm trying to figure
out whether it has practical applications, but if it doesn't then I
won't feel there's continuing disagreement).

>   1. The new 'assume' is worse when -flto is in use.

Maybe. Even if it is, though, that's a GCC limitation which I consider
likely to be fixable; your estimation of that may vary, of course.

>   2. You recommend to users to split assume(A && B) into assume(A); assume(B);
>      which is unnatural.

I make that recommendation independently of which assume is in use.

In practice, combining a complicated expression with a simple one in
an eassume is almost always not what you want to do. It's way too easy
to do something like

eassume(ptr->field >= 0 && f(ptr));

when what you mean is

eassume(ptr->field >= 0);
eassume(f(ptr));

(As an unusual special case, consider:

{
  printf("%d\n", i & 0x80000000);
  assume(i >= 0 && complicated_function());
}

which would generate different code from

{
  printf("%d\n", i & 0x80000000);
  assume(i >= 0);
  assume(complicated_function());
})

Combining two simple expressions and not getting the right result
appears, at this point, to run into a GCC limitation, but I'm not sure
where.

> > At first, I thought it would be better to have a __builtin_assume
> > expression at the GCC level, but even that would have to have "either
> > evaluate the entire condition expression, or evaluate none of it"
> > semantics.
>
> No. At GCC level, it could have a "make the maximum of inferences - across
> all optimization phases -, but evaluate none of it" semantics.

There's no contradiction there: I'm saying that the programmer is
allowed to assume that the expression passed to assume either has been
evaluated, or hasn't been, with no in-between interpretations allowed
to the compiler. That means assume (A && B) isn't equivalent, in
general, to assume (A); assume (B); My suspicion is that the latter is
almost always what is intended.





  parent reply	other threads:[~2019-06-28 13:51 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-25  5:36 bug#36370: 27.0.50; XFIXNAT called on negative numbers Pip Cet
2019-06-27  1:10 ` Paul Eggert
2019-06-27  6:16   ` Pip Cet
2019-06-27  8:28     ` Paul Eggert
2019-06-27 13:17       ` Pip Cet
2019-06-27 13:37         ` Eli Zaretskii
2019-06-27 19:38         ` Paul Eggert
2019-06-27 19:56           ` Pip Cet
2019-06-27 21:13             ` Paul Eggert
     [not found]             ` <5284eb58-3560-da42-d1d1-3bdb930eae49@cs.ucla.edu>
2019-06-27 21:37               ` Pip Cet
2019-06-27 23:45               ` Bruno Haible
     [not found]               ` <2715311.ceefYqj39C@omega>
2019-06-28  0:04                 ` Paul Eggert
2019-06-28 11:06                 ` Pip Cet
2019-06-28 12:14                   ` Bruno Haible
     [not found]                   ` <8979488.cRkkfcT1mV@omega>
2019-06-28 12:29                     ` Bruno Haible
2019-06-28 13:51                     ` Pip Cet [this message]
     [not found]                     ` <CAOqdjBfS99UpLZ-qLe4=FMXMsr+T3LUvJEsf_gfmF6wwLbqgOw@mail.gmail.com>
2019-06-28 17:46                       ` Paul Eggert
2019-06-28 19:11                       ` Bruno Haible
     [not found]                       ` <a293f2fe-99b3-3776-f27b-35e3a93d1d34@cs.ucla.edu>
2019-06-28 19:15                         ` Pip Cet
2019-06-28 19:56                           ` Bruno Haible
2019-06-28 21:08                             ` Pip Cet
2019-06-29  5:41                           ` Paul Eggert
     [not found]                           ` <87168b28-192b-6666-e9b6-9cdc2ed3917a@cs.ucla.edu>
2019-06-29  6:48                             ` Pip Cet
     [not found]                             ` <CAOqdjBfcNbXFw3Fb0wgRR10PNbkJQ+88ObE9KEghLSb-ptdrbA@mail.gmail.com>
2019-06-29 17:31                               ` Paul Eggert
     [not found]                               ` <791ae316-3a6f-605a-0da5-874fe3d224c5@cs.ucla.edu>
2019-06-30  9:21                                 ` Pip Cet
     [not found]                       ` <11002295.LrvMqknVDZ@omega>
2019-06-28 21:07                         ` Pip Cet
2019-06-28 23:30                           ` Bruno Haible
     [not found]                           ` <2067160.1HRgjLhtDS@omega>
2019-06-29  5:40                             ` Paul Eggert
2019-06-29  5:44                             ` Pip Cet
     [not found]                             ` <CAOqdjBcNA4mDiwsd_jbeePGMdUwPvkFCNdgtZvmiQnYmJNR3pA@mail.gmail.com>
2019-06-29 10:31                               ` Bruno Haible
     [not found]                               ` <2515002.Q0mBYvUW8C@omega>
2019-06-29 17:11                                 ` Paul Eggert
     [not found]                                 ` <99bacb9f-1192-1315-85d7-5ab4924dfef8@cs.ucla.edu>
2019-06-29 17:48                                   ` Bruno Haible
2019-06-30 15:30                                 ` Pip Cet
     [not found]                                 ` <CAOqdjBeiMno7nGKwk7SSZQob+CTyG39KRTM9EEebq7NQavLR-Q@mail.gmail.com>
2019-06-30 15:45                                   ` Bruno Haible
2019-07-02 23:39                                     ` Paul Eggert
2019-07-01  1:46                                   ` Richard Stallman

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='CAOqdjBfS99UpLZ-qLe4=FMXMsr+T3LUvJEsf_gfmF6wwLbqgOw__12120.8733807848$1561734682$gmane$org@mail.gmail.com' \
    --to=pipcet@gmail.com \
    --cc=36370@debbugs.gnu.org \
    --cc=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=eggert@cs.ucla.edu \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.