-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[libc++][atomic_ref] Use __atomic_fetch_{add,sub} builtins on floating-points whenever possible #135685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…g-points whenever possible Fix llvm#135109 Clang is able to emit an `atomicrmw` instruction from the `__atomic_fetch_add` and `__atomic_fetch_sub` builtins on floating-point types.
libcxx/include/__atomic/atomic_ref.h
Outdated
@@ -322,20 +322,28 @@ struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> { | |||
atomic_ref& operator=(const atomic_ref&) = delete; | |||
|
|||
_LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __arg, memory_order __order = memory_order_seq_cst) const noexcept { | |||
# ifdef _LIBCPP_COMPILER_CLANG_BASED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need this fp80 workaround for #68602?
llvm-project/libcxx/include/__atomic/atomic.h
Lines 340 to 357 in d0c973a
_LIBCPP_HIDE_FROM_ABI static constexpr bool __has_rmw_builtin() { | |
# ifndef _LIBCPP_COMPILER_CLANG_BASED | |
return false; | |
# else | |
// The builtin __cxx_atomic_fetch_add errors during compilation for | |
// long double on platforms with fp80 format. | |
// For more details, see | |
// lib/Sema/SemaChecking.cpp function IsAllowedValueType | |
// LLVM Parser does not allow atomicrmw with x86_fp80 type. | |
// if (ValType->isSpecificBuiltinType(BuiltinType::LongDouble) && | |
// &Context.getTargetInfo().getLongDoubleFormat() == | |
// &llvm::APFloat::x87DoubleExtended()) | |
// For more info | |
// https://github.com/llvm/llvm-project/issues/68602 | |
// https://reviews.llvm.org/D53965 | |
return !__is_fp80_long_double(); | |
# endif | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make atomic_ref and atomic share the similar logic (or just share the implantation) for these rmw operations. The reason why atomic has special branch for fp80 long double is that , the clang builtin that emit the llvm ir, has serious bug that affects all types whose data size is not power of 2. ( I think I have a patch but I never got a chance to finalise the tests. )
Fix #135109
Clang is able to emit an
atomicrmw
instruction from the__atomic_fetch_add
and__atomic_fetch_sub
builtins on floating-point types.