From b584648df169bb9c8b67b24b4504b0fea82b093d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 10 Feb 2015 22:19:51 -0800 Subject: Use Clang 3.6's __builtin_assume in Q_ASSUME It's more efficient than the current implementation. Example: int f(int i) { Q_ASSUME(i < 8); return i < 8; } Before: cmpl $8, %edi setl %al movzbl %al, %eax retq After: movl $1, %eax retq Change-Id: I1a800c709d3543699131ffff13c1c50713a8da2c Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Marc Mutz --- src/corelib/global/qcompilerdetection.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/corelib/global') diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 8ef8b79902..ba87bb5cc9 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -173,7 +173,11 @@ # else # define Q_CC_CLANG ((__clang_major__ * 100) + __clang_minor__) # endif -# define Q_ASSUME_IMPL(expr) if (expr){} else __builtin_unreachable() +# if __has_builtin(__builtin_assume) +# define Q_ASSUME_IMPL(expr) __builtin_assume(expr) +# else +# define Q_ASSUME_IMPL(expr) if (expr){} else __builtin_unreachable() +# endif # define Q_UNREACHABLE_IMPL() __builtin_unreachable() # if !defined(__has_extension) # /* Compatibility with older Clang versions */ -- cgit v1.2.3