linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: James Y Knight <jyknight@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Matthias Kaehlcke <mka@chromium.org>,
	Arnd Bergmann <arnd@arndb.de>, Ingo Molnar <mingo@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	Chandler Carruth <chandlerc@google.com>,
	Stephen Hines <srhines@google.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Kees Cook <keescook@google.com>,
	Guenter Roeck <groeck@chromium.org>,
	Greg Hackmann <ghackmann@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [GIT PULL] x86/build changes for v4.17
Date: Thu, 5 Apr 2018 14:13:29 -0700	[thread overview]
Message-ID: <CA+55aFz3PUE1mSM+yFeb55ca3EZAYHHqTyHjktiW1FVfK-tP9A@mail.gmail.com> (raw)
In-Reply-To: <CAA2zVHrF+teb3SwigH_sDqkWfKDg4itq4TkefYXUXw2RF9+4qw@mail.gmail.com>

On Thu, Apr 5, 2018 at 1:51 PM, James Y Knight <jyknight@google.com> wrote:
>
> I had actually meant that the __builtin_constant_p **itself** had to be a
> constant expression, not that its *argument* must be an I-C-E for
> __builtin_constant_p to return true.

I actually really wish that were true, and that it would always be
considered an ICE.

But it's not, as you also found out.

This exact problem is why we had to come up with that crazy
alternative test for an actual integer constant expression.

> Which means that __builtin_constant_p(v) was _not_ evaluated as an integer
> constant expression by GCC. Instead, it was left as an expression. And, the
> stack frame being only 24 bytes indicates that the __bcp eventually
> evaluated to true.

Yeah.

The best of all worlds would be that __builtin_constant_p() would
itself always evaluate as an integer constant expression, but the
expression inside of it could be expanded as if it was not.

I realize that that can be very inconvenient for a compiler, since the
two are basically done at different points in the evaluation, but it's
the nicest semantics for the user.

But since gcc doesn't actually provide those semantics, clearly clang
doesn't have to either.

I claim that it *could* be done right, though, if you happened to care
about giving the best possible quality end result to the user.

Instead of doing the integer constant expression testing early (before
inlining etc), you do it later, but you carry along a bit in the
expression that says "was this expression actually _syntactically_ an
I-C-E?"

And btw, I hate how stupid gcc is about "constant size arrays but acts
as a VLA because it wasn't an integer-constant-expression size"
things.

Your code generation example really is a sad sad example of it. A good
optimizer should have generated the same code even if the stupid array
again syntactically was VLA, because it damn well isn't in reality.

So if you get really excited about this, and decide that clang can do
much better than gcc, I can only salute you!

             Linus

  reply	other threads:[~2018-04-05 21:13 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-02  9:50 [GIT PULL] x86/build changes for v4.17 Ingo Molnar
2018-04-02 21:44 ` Linus Torvalds
2018-04-02 22:38   ` Matthias Kaehlcke
2018-04-03  1:26     ` Matthias Kaehlcke
2018-04-03  8:59   ` Peter Zijlstra
2018-04-03  9:51     ` Ingo Molnar
2018-04-03 12:09       ` Peter Zijlstra
2018-04-03 18:06       ` Matthias Kaehlcke
2018-04-03 21:58         ` Nick Desaulniers
2018-04-04  9:19           ` Peter Zijlstra
2018-04-04  9:38           ` Greg KH
2018-04-04 16:49             ` Nick Desaulniers
2018-04-04 17:13               ` Linus Torvalds
2018-04-04 17:46                 ` Nick Desaulniers
2018-04-04 23:10                 ` Nick Desaulniers
2018-04-04 16:53             ` Nick Desaulniers
2018-04-04 16:59               ` Greg KH
2018-04-04 19:26                 ` James Y Knight
2018-04-04 19:42                   ` Linus Torvalds
2018-04-04 22:21                     ` James Y Knight
2018-04-04 22:29                       ` Linus Torvalds
2018-04-05  7:08                       ` Peter Zijlstra
2018-04-05 16:21                         ` James Y Knight
2018-04-04 19:32               ` Josh Poimboeuf
2018-06-07 19:23                 ` Nick Desaulniers
2018-06-07 20:11                   ` Greg KH
2018-04-04  9:30         ` Peter Zijlstra
2018-04-04 19:17           ` Matthias Kaehlcke
2018-04-04 20:33             ` Arnd Bergmann
2018-04-04 20:58               ` Matthias Kaehlcke
2018-04-04 21:11                 ` Arnd Bergmann
2018-04-04 21:46                   ` Matthias Kaehlcke
2018-04-04 21:59                     ` Linus Torvalds
2018-04-04 22:17                       ` Matthias Kaehlcke
2018-04-04 22:39                         ` Linus Torvalds
2018-04-04 23:31                           ` Matthias Kaehlcke
2018-04-05  0:05                             ` Linus Torvalds
2018-04-05  0:20                               ` Kees Cook
2018-04-05  7:24                               ` Peter Zijlstra
2018-04-05  8:04                                 ` Ingo Molnar
2018-04-05  8:24                                   ` Peter Zijlstra
2018-04-05 16:43                                 ` Linus Torvalds
2018-04-05  7:20                             ` Peter Zijlstra
2018-04-05 17:46                               ` James Y Knight
2018-04-05 18:06                                 ` Linus Torvalds
2018-04-05 20:51                                   ` James Y Knight
2018-04-05 21:13                                     ` Linus Torvalds [this message]
2018-04-05 22:51                                       ` James Y Knight
2018-04-06  2:02                                         ` Linus Torvalds
2018-04-05 17:47                               ` James Y Knight
2018-04-04 23:04             ` Nick Desaulniers
2018-04-03 17:36     ` Linus Torvalds

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=CA+55aFz3PUE1mSM+yFeb55ca3EZAYHHqTyHjktiW1FVfK-tP9A@mail.gmail.com \
    --to=torvalds@linux-foundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=chandlerc@google.com \
    --cc=ghackmann@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=groeck@chromium.org \
    --cc=jyknight@google.com \
    --cc=keescook@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mka@chromium.org \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=srhines@google.com \
    --cc=tglx@linutronix.de \
    /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 NNTP newsgroup(s).