From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.3 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 5477F1F66E for ; Sat, 22 Aug 2020 23:01:51 +0000 (UTC) Received: from localhost ([::1]:33506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k9cWE-00039L-8J for normalperson@yhbt.net; Sat, 22 Aug 2020 19:01:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33326) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9cWB-00038z-7g for bug-gnulib@gnu.org; Sat, 22 Aug 2020 19:01:47 -0400 Received: from mo4-p00-ob.smtp.rzone.de ([85.215.255.23]:15874) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9cW8-0004Z9-SP for bug-gnulib@gnu.org; Sat, 22 Aug 2020 19:01:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1598137302; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=9fS2f0/kJgsem4nn5dc+E57CfDNpqyKa+bRJuGKt8Pg=; b=oVZ5hmZMvcvRXmlkmJ9PxjzFt4qKPppepqtDqEFKEv0mj4I2NH5ME0h8F5hgpO0wwl YgrC93no73R0tVnV5jYNmTBRQY/euCUaxMIL77xO28eZtYeOkGzjUL41gGLjadeGMg0A 9KW9z5/ymXb9PhuASZ6nQJD9R9Ltc3+2H3FmZJmmG028Y1tXNlJlUT93J8sFC8OiKfki awx3wtjasRK/X/3TeyOZbD0BQ56BGvBOxrvFeeOql4rSm97AFjiRWKjOJyNLw7jvpAZX pP7XzAR4twXLYUB9PcUMVWcFwGfH6anfLei2u7HA/oPt/NuJrzvZ+FC8sMPcuNZ2UwsZ T+Yg== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOHqfyyPs=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 46.10.7 DYNA|AUTH) with ESMTPSA id z05f0fw7MN1fEDA (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Sun, 23 Aug 2020 01:01:41 +0200 (CEST) From: Bruno Haible To: Paul Eggert Subject: Re: Clang __builtin_assume Date: Sun, 23 Aug 2020 01:01:40 +0200 Message-ID: <8048804.nLtAeEzrYs@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-186-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <4d87cd4d-f02c-761c-216e-65157754d039@cs.ucla.edu> References: <5e607e6f-ee3a-41bc-67eb-cdc0571d00d0@cs.ucla.edu> <4290937.bpigslQC6F@omega> <4d87cd4d-f02c-761c-216e-65157754d039@cs.ucla.edu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Received-SPF: none client-ip=85.215.255.23; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/22 19:01:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bug-gnulib@gnu.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" > This is OK, but please also mention in the comment that __builtin_assume= =20 > generates better code for Clang 8 than __builtin_unreachable does, as tha= t's the=20 > only reason to put up with all this mess. Done, as follows: 2020-08-22 Bruno Haible verify: Do use __builtin_assume on clang. * lib/verify.h (assume): Use clang=E2=80=99s __builtin_assume, with a temp= orary variable in a statement expression. diff --git a/lib/verify.h b/lib/verify.h index d485a02..04bb2df 100644 =2D-- a/lib/verify.h +++ b/lib/verify.h @@ -246,6 +246,13 @@ template =20 /* @assert.h omit start@ */ =20 +#if defined __has_builtin +/* = */ +# define _GL_HAS_BUILTIN_ASSUME __has_builtin (__builtin_assume) +#else +# define _GL_HAS_BUILTIN_ASSUME 0 +#endif + #if 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <=3D __GNUC_PATCHLEVEL__)) # define _GL_HAS_BUILTIN_TRAP 1 #elif defined __has_builtin @@ -305,14 +312,21 @@ template =20 Although assuming R can help a compiler generate better code or diagnostics, performance can suffer if R uses hard-to-optimize =2D features such as function calls not inlined by the compiler. =2D =2D Avoid Clang=E2=80=99s __builtin_assume, as clang 9.0.1 -Wassume can =2D generate a bogus diagnostic "the argument to '__builtin_assume' has =2D side effects that will be discarded" even when the argument has no =2D side effects. */ =2D =2D#if _GL_HAS_BUILTIN_UNREACHABLE + features such as function calls not inlined by the compiler. */ + +/* Use __builtin_assume in preference to __builtin_unreachable, because + in clang versions 8.0.x and older, the definition based on + __builtin_assume has an effect on optimizations, whereas the definition + based on __builtin_unreachable does not. (GCC so far has only + __builtin_unreachable.) */ +#if _GL_HAS_BUILTIN_ASSUME +/* Use a temporary variable, to avoid a clang warning + "the argument to '__builtin_assume' has side effects that will be disca= rded" + if R contains invocations of functions not marked as 'const'. */ +# define assume(R) \ + ((void) ({ __typeof__ (R) _gl_verify_temp =3D (R); \ + __builtin_assume (_gl_verify_temp); })) +#elif _GL_HAS_BUILTIN_UNREACHABLE # define assume(R) ((R) ? (void) 0 : __builtin_unreachable ()) #elif 1200 <=3D _MSC_VER # define assume(R) __assume (R)