From patchwork Sat Sep 15 12:27:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 970228 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-485705-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="YHXM02gi"; 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 42CBVT08V8z9sCS for ; Sat, 15 Sep 2018 22:27: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:subject:message-id:mime-version:content-type; q=dns; s= default; b=EF6f7dfZqGsn9cZjj/xci2q3bNeiCX6GIRgPJhp5GQFjBwxrS1a3w pEnMtLsxmKf9mj7/pO5szH8aVNNB3UBzQIet3dzx2T5Ih/1SlMABdnXV6+1tPvyk pq/ieNdu7rFyYTOXSDwlur9+TQDd6x7Xa7aAhK9KRwainQBYD/uoqE= 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:subject:message-id:mime-version:content-type; s= default; bh=AVAQieJ/1K6lHc21Ry8DnfO7hnY=; b=YHXM02gigx1S+izvKtKI BCxuCamFFiRkB9DQ7Lwfao4AypAf91g2U+7rnwukkiXEwhS/aMxHVKRIk2NHZVzT XZNQSAnabXoWB4u0XjmevRmp0Qa26t/cy8rTY2DhOzz1G9kPL27XdKZzUNjO9xOx l/GNa314PDRf28JGV8Qjpgo= Received: (qmail 17337 invoked by alias); 15 Sep 2018 12:27:27 -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 17318 invoked by uid 89); 15 Sep 2018 12:27:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=preserving, nicer, 264178, Hx-languages-length:2294 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, 15 Sep 2018 12:27:25 +0000 Received: from ip-133.net-89-2-166.rev.numericable.fr (HELO stedding) ([89.2.166.133]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 15 Sep 2018 14:27:22 +0200 Date: Sat, 15 Sep 2018 14:27:18 +0200 (CEST) From: Marc Glisse To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: vector _M_start and 0 offset Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Hello, as explained in the PR, the implementation of vector is weirdly wasteful. Preserving the ABI prevents from changing much for now, but this small tweak can help the compiler remove quite a bit of dead code. I think most other direct uses of _M_start are in constructors where the offset has just been initialized to 0, so the compiler should already know enough there, but I may have missed a few relevant places where the same idea could be used. I used C++11 syntax because I find it nicer, and the compiler accepts it in C++98 mode with just a warning, suppressed in a standard header. Bootstrap+regtest on powerpc64le-unknown-linux-gnu. 2018-09-15 Marc Glisse PR libstdc++/87258 * include/bits/stl_bvector.h (vector::begin(), vector::cbegin()): Rebuild _M_start with an explicit 0 offset. Index: include/bits/stl_bvector.h =================================================================== --- include/bits/stl_bvector.h (revision 264178) +++ include/bits/stl_bvector.h (working copy) @@ -802,25 +802,25 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER #endif #if __cplusplus >= 201103L void assign(initializer_list __l) { _M_assign_aux(__l.begin(), __l.end(), random_access_iterator_tag()); } #endif iterator begin() _GLIBCXX_NOEXCEPT - { return this->_M_impl._M_start; } + { return { this->_M_impl._M_start._M_p, 0 }; } const_iterator begin() const _GLIBCXX_NOEXCEPT - { return this->_M_impl._M_start; } + { return { this->_M_impl._M_start._M_p, 0 }; } iterator end() _GLIBCXX_NOEXCEPT { return this->_M_impl._M_finish; } const_iterator end() const _GLIBCXX_NOEXCEPT { return this->_M_impl._M_finish; } reverse_iterator @@ -835,21 +835,21 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(begin()); } const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(begin()); } #if __cplusplus >= 201103L const_iterator cbegin() const noexcept - { return this->_M_impl._M_start; } + { return { this->_M_impl._M_start._M_p, 0 }; } const_iterator cend() const noexcept { return this->_M_impl._M_finish; } const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } const_reverse_iterator