>From 9a5a83937544e7c127026fcf32030f7dbaa5766c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 27 Jun 2019 14:01:53 -0700 Subject: [PATCH] =?UTF-8?q?verify:=20tweak=20=E2=80=98assume=E2=80=99=20pe?= =?UTF-8?q?rformance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Suggested by Pip Cet (Bug#36370#30). * lib/verify.h (assume): Use __builtin_constant_p to generate better code in recent GCC. --- ChangeLog | 7 +++++++ lib/verify.h | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5ae108e25..7059f4f2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2019-06-27 Paul Eggert + + verify: tweak ‘assume’ performance + Suggested by Pip Cet (Bug#36370#30). + * lib/verify.h (assume): Use __builtin_constant_p to generate + better code in recent GCC. + 2019-06-26 Paul Eggert strverscmp: sync from glibc diff --git a/lib/verify.h b/lib/verify.h index f8e4eff02..9b015c693 100644 --- a/lib/verify.h +++ b/lib/verify.h @@ -263,9 +263,11 @@ template accordingly. R should not have side-effects; it may or may not be evaluated. Behavior is undefined if R is false. */ -#if (__has_builtin (__builtin_unreachable) \ +#if ((__has_builtin (__builtin_constant_p) \ + && __has_builtin (__builtin_unreachable)) \ || 4 < __GNUC__ + (5 <= __GNUC_MINOR__)) -# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ()) +# define assume(R) (!__builtin_constant_p (!(R) == !(R)) || (R) \ + ? (void) 0 : __builtin_unreachable ()) #elif 1200 <= _MSC_VER # define assume(R) __assume (R) #elif ((defined GCC_LINT || defined lint) \ -- 2.21.0