From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1984) id 39D8A398D05B; Fri, 17 Jul 2020 12:54:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39D8A398D05B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1594990487; bh=OyxoTdlby9hFc3PiBuB//3conPGpW6GTXsmQUOeApg8=; h=From:To:Subject:Date:From; b=HzlDz7o5TtuXn30Lav+O4ysRh7oqoQ+So2rzs4iLuZZ8l5JYW3veJ23GCk93j5PRZ qTH1FV0ueVE3sefbLYHUScLzKvbNscVeGjwSy/3wZSQ3St9dth5pJnSd7/LW2XM8/4 VooPh1cHAcB/qsEa3tZfeKLArnknqt1EvK07mTMI= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Tamar Christina To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/arm-struct-reorg-wip)] libstdc++: Move code after an early exit constexpr if to under an else branch X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/vendors/ARM/heads/arm-struct-reorg-wip X-Git-Oldrev: e19c49e0dab1345684813a7e7e1e80fc21c38cf9 X-Git-Newrev: 93b8cfce27abe795f56ab467570f66682e9688ca Message-Id: <20200717125447.39D8A398D05B@sourceware.org> Date: Fri, 17 Jul 2020 12:54:47 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Jul 2020 12:54:47 -0000 https://gcc.gnu.org/g:93b8cfce27abe795f56ab467570f66682e9688ca commit 93b8cfce27abe795f56ab467570f66682e9688ca Author: Patrick Palka Date: Sat Feb 15 10:59:36 2020 -0500 libstdc++: Move code after an early exit constexpr if to under an else branch This avoids instantiating dead code when the true branch of the constexpr if is taken. libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__lexicographical_compare_fn::operator()): Move code after an early exit constexpr if to under an else branch. * include/bits/ranges_algobase.h (__equal_fn::operator()): Likewise. Diff: --- libstdc++-v3/ChangeLog | 6 ++ libstdc++-v3/include/bits/ranges_algo.h | 103 ++++++++++++++-------------- libstdc++-v3/include/bits/ranges_algobase.h | 7 +- 3 files changed, 61 insertions(+), 55 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b57ac9658e8..25fa9ba6098 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2020-02-16 Patrick Palka + + * include/bits/ranges_algo.h (__lexicographical_compare_fn::operator()): + Move code after an early exit constexpr if to under an else branch. + * include/bits/ranges_algobase.h (__equal_fn::operator()): Likewise. + 2020-02-15 Patrick Palka * include/bits/ranges_algo.h: Adjust whitespace and formatting. diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h index 7f8f0fb964b..ff1b40f6ace 100644 --- a/libstdc++-v3/include/bits/ranges_algo.h +++ b/libstdc++-v3/include/bits/ranges_algo.h @@ -3318,65 +3318,68 @@ namespace ranges std::__niter_base(std::move(__last2)), std::move(__comp), std::move(__proj1), std::move(__proj2)); - - constexpr bool __sized_iters - = (sized_sentinel_for<_Sent1, _Iter1> - && sized_sentinel_for<_Sent2, _Iter2>); - if constexpr (__sized_iters) + else { - auto __d1 = ranges::distance(__first1, __last1); - auto __d2 = ranges::distance(__first2, __last2); - - using _ValueType1 = iter_value_t<_Iter1>; - using _ValueType2 = iter_value_t<_Iter2>; - constexpr bool __use_memcmp - = ((is_integral_v<_ValueType1> || is_pointer_v<_ValueType1>) - && is_same_v<_ValueType1, _ValueType2> - && is_pointer_v<_Iter1> - && is_pointer_v<_Iter2> - && (is_same_v<_Comp, ranges::less> - || is_same_v<_Comp, ranges::greater>) - && is_same_v<_Proj1, identity> - && is_same_v<_Proj2, identity>); - if constexpr (__use_memcmp) + constexpr bool __sized_iters + = (sized_sentinel_for<_Sent1, _Iter1> + && sized_sentinel_for<_Sent2, _Iter2>); + if constexpr (__sized_iters) { - if (const auto __len = std::min(__d1, __d2)) + auto __d1 = ranges::distance(__first1, __last1); + auto __d2 = ranges::distance(__first2, __last2); + + using _ValueType1 = iter_value_t<_Iter1>; + using _ValueType2 = iter_value_t<_Iter2>; + constexpr bool __use_memcmp + = ((is_integral_v<_ValueType1> || is_pointer_v<_ValueType1>) + && is_same_v<_ValueType1, _ValueType2> + && is_pointer_v<_Iter1> + && is_pointer_v<_Iter2> + && (is_same_v<_Comp, ranges::less> + || is_same_v<_Comp, ranges::greater>) + && is_same_v<_Proj1, identity> + && is_same_v<_Proj2, identity>); + if constexpr (__use_memcmp) { - const auto __c = std::__memcmp(__first1, __first2, __len); - if constexpr (is_same_v<_Comp, ranges::less>) - { - if (__c < 0) - return true; - if (__c > 0) - return false; - } - else if constexpr (is_same_v<_Comp, ranges::greater>) + if (const auto __len = std::min(__d1, __d2)) { - if (__c > 0) - return true; - if (__c < 0) - return false; + const auto __c + = std::__memcmp(__first1, __first2, __len); + if constexpr (is_same_v<_Comp, ranges::less>) + { + if (__c < 0) + return true; + if (__c > 0) + return false; + } + else if constexpr (is_same_v<_Comp, ranges::greater>) + { + if (__c > 0) + return true; + if (__c < 0) + return false; + } + else + __builtin_unreachable(); } - else - __builtin_unreachable(); + return (__last1 - __first1 < __last2 - __first2); } - return (__last1 - __first1 < __last2 - __first2); } - } - for (; __first1 != __last1 && __first2 != __last2; - ++__first1, (void) ++__first2) - { - if (std::__invoke(__comp, - std::__invoke(__proj1, *__first1), - std::__invoke(__proj2, *__first2))) - return true; - if (std::__invoke(__comp, - std::__invoke(__proj2, *__first2), - std::__invoke(__proj1, *__first1))) - return false; + for (; __first1 != __last1 && __first2 != __last2; + ++__first1, (void) ++__first2) + { + if (std::__invoke(__comp, + std::__invoke(__proj1, *__first1), + std::__invoke(__proj2, *__first2))) + return true; + if (std::__invoke(__comp, + std::__invoke(__proj2, *__first2), + std::__invoke(__proj1, *__first1))) + return false; + } + return __first1 == __last1 && __first2 != __last2; } - return __first1 == __last1 && __first2 != __last2; } template - && sized_sentinel_for<_Sent2, _Iter2>); - if constexpr (__sized_iters) + else if constexpr (sized_sentinel_for<_Sent1, _Iter1> + && sized_sentinel_for<_Sent2, _Iter2>) { auto __d1 = ranges::distance(__first1, __last1); auto __d2 = ranges::distance(__first2, __last2);