From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D5E5D3858CDB; Wed, 22 Nov 2023 11:27:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D5E5D3858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700652474; bh=/xEwmFX0MUQm838BmSY6nN9iheTY6ok17gEy8zBSkoM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ulTWg3BAyJpER445H9xUrHczgkkRPgLSNVE9AKqulCQY5ZH7RGV508eAPikygGIw8 lACiuA0AHuN6MDFDRlFQ4AHsPEddCBMYpRiEvMatfsVD4JC3LV/o39BaYFPqTyIWlC k36+67ND/VotrFF7iSuvkIG0Z+JN3vj21Pf2jgGI= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/110879] [14 Regression] Unnecessary reread from memory in a loop with std::vector Date: Wed, 22 Nov 2023 11:27:53 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: alias, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: FIXED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 14.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110879 --- Comment #4 from Jonathan Wakely --- Ah I think that's probably expected. In _M_realloc_insert (and now _M_realloc_append) we have: #if __cplusplus >=3D 201103L if _GLIBCXX17_CONSTEXPR (_S_use_relocate()) { // Relocation cannot throw. __new_finish =3D _S_relocate(__old_start, __position.base(), __new_start, _M_get_Tp_allocator()); ++__new_finish; __new_finish =3D _S_relocate(__position.base(), __old_finish, __new_finish, _M_get_Tp_allocator()); } else #endif and then an alternative path used for non-trivial types and for C++98. That alternative path does more work and probably can't be optimized as well, so= the reads from _M_end_of_storage aren't optimized out. I think we can just use { target c++11 } for the test.=