From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Stephen J. Turnbull" Newsgroups: gmane.emacs.devel Subject: Re: [Emacs-diffs] trunk r114593: * lisp.h (eassert): Don't use 'assume'. Date: Fri, 11 Oct 2013 19:27:50 +0900 Message-ID: <87a9ighzkp.fsf@uwakimon.sk.tsukuba.ac.jp> References: <52576305.9000703@dancol.org> <52579C68.1040904@cs.ucla.edu> <83iox4pa0w.fsf@gnu.org> <5257AB8C.40309@dancol.org> <83eh7sp6v0.fsf@gnu.org> <5257B489.2050609@dancol.org> <87eh7si3ny.fsf@uwakimon.sk.tsukuba.ac.jp> <5257C083.5010909@dancol.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 X-Trace: ger.gmane.org 1381487303 12007 80.91.229.3 (11 Oct 2013 10:28:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 11 Oct 2013 10:28:23 +0000 (UTC) Cc: Eli Zaretskii , eggert@cs.ucla.edu, emacs-devel@gnu.org To: Daniel Colascione Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Oct 11 12:28:23 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VUZxE-0007iL-Oe for ged-emacs-devel@m.gmane.org; Fri, 11 Oct 2013 12:28:20 +0200 Original-Received: from localhost ([::1]:53430 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUZxE-0001gf-0a for ged-emacs-devel@m.gmane.org; Fri, 11 Oct 2013 06:28:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57251) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUZx3-0001fm-KR for emacs-devel@gnu.org; Fri, 11 Oct 2013 06:28:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VUZww-0007Lw-Ad for emacs-devel@gnu.org; Fri, 11 Oct 2013 06:28:09 -0400 Original-Received: from mgmt1.sk.tsukuba.ac.jp ([130.158.97.223]:52159) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUZwn-0007K2-Df; Fri, 11 Oct 2013 06:27:53 -0400 Original-Received: from uwakimon.sk.tsukuba.ac.jp (uwakimon.sk.tsukuba.ac.jp [130.158.99.156]) by mgmt1.sk.tsukuba.ac.jp (Postfix) with ESMTP id 815553FA0A14; Fri, 11 Oct 2013 19:27:50 +0900 (JST) Original-Received: by uwakimon.sk.tsukuba.ac.jp (Postfix, from userid 1000) id 78FDD129E2C; Fri, 11 Oct 2013 19:27:50 +0900 (JST) In-Reply-To: <5257C083.5010909@dancol.org> X-Mailer: VM undefined under 21.5 (beta34) "kale" 182d01410b8d XEmacs Lucid (x86_64-unknown-linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 130.158.97.223 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:164085 Archived-At: Daniel Colascione writes: > On 10/11/13 1:59 AM, Stephen J. Turnbull wrote: > > apparently optimizers are sufficiently stupid as to compile worse > > code when assume is present (at least that's what Paul seemed to > > claim). > > I don't think that's actually the case. We implement assume using GCC's > __builtin_unreachable: > if (!(assumed_condition)) { __builtin_unreachable(); }. > If assumed_condition has side effects, then normal semantics > requires that the compiler emit code to implement [them]. Ah, OK, it's not the optimizer that's stupid, it's just GCC. What else is new, eh?[1] However, I have to agree with Eli.[2] One writes "assert(width>0)" when one is about to write "aspect_ratio = height/width", and doesn't want to write if (width > 0) aspect_ratio = height/width; else beep_loudly_to_annoy_user(); /* or other error recovery */ One would hope that a optimizing compiler given assume(width > 0); /* Look Ma, all plusses! */ if (width > 0) aspect_ratio = height/width; else beep_loudly_to_annoy_user(); /* or other error recovery */ would produce the same machine code as just aspect_ratio = height/width; but look! we've already done that optimization. It just comes naturally. I've seen a lot of handwaving, but if there's a case where assume helps the compiler produce better code in Emacs, I've yet to see it presented. Footnotes: [1] I'm sure they have their reasons. Whatever they are, they sure weren't invented by Emacs hackers. [2] Note that it's not necessarily a question of valid use cases that the programmer didn't imagine. There may be a bug elsewhere in the program that manifests here, or even in the compiler.