[PATCH] D55427: [libcxx] Use specialized helper for __bit_reference count
Adhemerval Zanella via Phabricator
reviews at reviews.llvm.org
Fri Dec 7 05:08:48 PST 2018
zatrazz created this revision.
zatrazz added reviewers: EricWF, mclow.lists.
Herald added subscribers: libcxx-commits, ldionne.
This patch aims to help clang with better information so it can inline
__bit_reference count function usage, for both std::vector<bool> and
bitset. Current clang inliner can not infer that the passed typed
will be used only to select the optimized variant, it evaluates the
type argument and type check as a load plus compare (although later
optimization phases correctly optimized this out).
Repository:
rCXX libc++
https://reviews.llvm.org/D55427
Files:
include/__bit_reference
Index: include/__bit_reference
===================================================================
--- include/__bit_reference
+++ include/__bit_reference
@@ -303,13 +303,33 @@
}
template <class _Cp, bool _IsConst, class _Tp>
+struct __count_helper
+{
+ typename __bit_iterator<_Cp, _IsConst>::difference_type
+ static inline _LIBCPP_INLINE_VISIBILITY
+ __count(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
+ {
+ return __count_bool_false(__first, __n);
+ }
+};
+
+template <class _Cp, bool _IsConst>
+struct __count_helper<_Cp, _IsConst, bool>
+{
+ typename __bit_iterator<_Cp, _IsConst>::difference_type
+ static inline _LIBCPP_INLINE_VISIBILITY
+ __count(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
+ {
+ return __count_bool_true(__first, __n);
+ }
+};
+
+template <class _Cp, bool _IsConst, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename __bit_iterator<_Cp, _IsConst>::difference_type
-count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
+count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp&)
{
- if (static_cast<bool>(__value_))
- return __count_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
- return __count_bool_false(__first, static_cast<typename _Cp::size_type>(__last - __first));
+ return __count_helper<_Cp, _IsConst, _Tp>::__count(__first, static_cast<typename _Cp::size_type>(__last - __first));
}
// fill_n
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55427.177185.patch
Type: text/x-patch
Size: 1569 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20181207/8eac555e/attachment.bin>
More information about the libcxx-commits
mailing list