[libcxx-commits] [libcxx] [libc++] Optimize bitset shift operations (PR #106225)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Sep 12 09:43:39 PDT 2024
================
@@ -290,6 +290,15 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> _
template <class _Cp, bool _IsConst>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, false>
copy(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
+ if (__builtin_constant_p(
+ __result.__ctz_ == 0 && __first.__seg_ == __last.__seg_ && __last.__seg_ == __result.__seg_) &&
+ __result.__ctz_ == 0 && __first.__seg_ == __last.__seg_ && __last.__seg_ == __result.__seg_) {
+ if (__first == __last)
+ return __result;
----------------
ldionne wrote:
We could move this outside the `__builtin_constant_p` block and then assume that `__n != 0` from `__copy_aligned` & `__copy_unaligned`. I'd add `_LIBCPP_ASSERT_INTERNAL` inside those functions just to bake in that assumption safely.
https://github.com/llvm/llvm-project/pull/106225
More information about the libcxx-commits
mailing list