unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: "Mattias Engdegård" <mattiase@acm.org>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: __builtin_assume warnings
Date: Tue, 18 Aug 2020 15:53:54 -0700	[thread overview]
Message-ID: <25e394e9-0e6e-7794-3e90-5fbab3951678@cs.ucla.edu> (raw)
In-Reply-To: <B70AD2D5-29F5-43CC-ABFC-8943FC7DB4CB@acm.org>

On 8/18/20 12:11 AM, Mattias Engdegård wrote:

> Wouldn't -Wno-assume, either locally (clang pragmas around __builtin_assume) or globally (configure?) be more effective?

No, it's the other way around at least for me: having 'assume' use Clang's 
__builtin_assume makes 'assume' slower. Without __builtin_assume, 'assume' falls 
back on __builtin_unreachable, and Clang generates better code for 
__builtin_unreachable than it does __builtin_assume. For the following code:

int x;
static int f (void) { return x; }
int g (void) { __builtin_assume (!f ()); return f (); }
int h (void) { if (f ()) __builtin_unreachable (); return f (); }

clang -O2 generates suboptimal machine code for g (the generated code loads from 
'x') and better machine code for h (the generated code returns 0 without loading 
from 'x'). This is clang version 9.0.1 (Fedora 9.0.1-2.fc31) on 
x86_64-unknown-linux-gnu.

Perhaps someday the Clang folks will get their act together in this department, 
but in the meantime __builtin_unreachable is a perfectly adequate substitute.



  reply	other threads:[~2020-08-18 22:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-12  9:38 __builtin_assume warnings Mattias Engdegård
2020-08-15  2:32 ` Paul Eggert
2020-08-16  8:23   ` Mattias Engdegård
2020-08-17 14:05     ` Mattias Engdegård
2020-08-17 22:11       ` Paul Eggert
2020-08-18  7:11         ` Mattias Engdegård
2020-08-18 22:53           ` Paul Eggert [this message]
2020-08-19  8:01             ` Mattias Engdegård

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=25e394e9-0e6e-7794-3e90-5fbab3951678@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=mattiase@acm.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.
Code repositories for project(s) associated with this public inbox

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

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).