From patchwork Sat Apr 27 10:03:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 1091905 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-499783-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=inria.fr Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="AsSnjiOy"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44rmhy0JR0z9s4V for ; Sat, 27 Apr 2019 20:03:41 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=c9PF0Jsv3MHRHcZOmLhUpdpd+00DnVac/5nLTQDm1aumLMpSSr k6JJ7hKlbsCWkIIzkp8ru6hkXJCsDk4mB3zywufM7jkfKT6uCZwfpa8kWfyL5yT0 HdKlNe4v5NbAOgoSphlPE9ixtfr6wnifHYasIyVzTUVCXIOAGNZnK0sfo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=PGjywFH4K6OLIYrYWpWAMri3sh0=; b=AsSnjiOyFoaTyBeT1+LO WguHCCUyXPUzVf3tYoFYYtYIiNWmUbIEzikeHqvlbuXCeDykB7tc8MPPJjuPIDqn PMXFSVwd4fzHQzaOXM5V2uwWUR/zqV9BcwEA2HmECOj8Lx0+lmzl2/UE6IDZ4Tw8 HTEisAZ2uQIR/TUsSTVurhw= Received: (qmail 3852 invoked by alias); 27 Apr 2019 10:03:33 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 3830 invoked by uid 89); 27 Apr 2019 10:03:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=mix, chose, Marc, marc X-HELO: mail3-relais-sop.national.inria.fr Received: from mail3-relais-sop.national.inria.fr (HELO mail3-relais-sop.national.inria.fr) (192.134.164.104) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 27 Apr 2019 10:03:31 +0000 Received: from grove.saclay.inria.fr ([193.55.177.244]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 27 Apr 2019 12:03:28 +0200 Date: Sat, 27 Apr 2019 12:03:23 +0200 (CEST) From: Marc Glisse To: libstdc++@gcc.gnu.org cc: gcc-patches@gcc.gnu.org Subject: Use __restrict for __relocate_object_a Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Hello, this small patch feels safe: we are moving an existing object to an uninitialized location so the 2 locations can't overlap. And it helps with std::vector> where it lets the compiler get rid of the branches "if(...) delete ..." when moving elements around, for instance in reserve(). We don't get a call to memmove yet (ldist may be confused by clobbers, I'll investigate and report that later), but the code gets much smaller at -O2, and we vectorize at -O3. Similarly, I think the call to memmove in __relocate_a_1 could probably be memcpy (I don't remember why I chose memmove), but that seems less important and I don't want to mix it with this patch. Bootstrap+regtest on x86_64-pc-linux-gnu. 2019-04-29 Marc Glisse PR libstdc++/87106 * include/bits/stl_uninitialized.h (__relocate_object_a): Mark the arguments with __restrict. Index: libstdc++-v3/include/bits/stl_uninitialized.h =================================================================== --- libstdc++-v3/include/bits/stl_uninitialized.h (revision 270586) +++ libstdc++-v3/include/bits/stl_uninitialized.h (working copy) @@ -877,21 +877,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION auto __res = std::__uninitialized_copy_n_pair (_GLIBCXX_MAKE_MOVE_ITERATOR(__first), __count, __result); return {__res.first.base(), __res.second}; } #endif // C++17 #if __cplusplus >= 201103L template inline void - __relocate_object_a(_Tp* __dest, _Up* __orig, _Allocator& __alloc) + __relocate_object_a(_Tp* __restrict __dest, _Up* __restrict __orig, + _Allocator& __alloc) noexcept(noexcept(std::allocator_traits<_Allocator>::construct(__alloc, __dest, std::move(*__orig))) && noexcept(std::allocator_traits<_Allocator>::destroy( __alloc, std::__addressof(*__orig)))) { typedef std::allocator_traits<_Allocator> __traits; __traits::construct(__alloc, __dest, std::move(*__orig)); __traits::destroy(__alloc, std::__addressof(*__orig)); }