From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 17775388C026; Sun, 21 Jun 2020 17:13:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 17775388C026 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592759638; bh=jnNne48xbXyLFTOM3P/xI9iNvATADHCNTFeDjqKAM9k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XRJna4to8ia4Zdb1T/4XXL8Cwf+hkHQuXrLQ6CxnGrF4kJhuCZUSh/FCQ1jjoA5hk A5bPeOOlWlWL0bngh2Xz86wtoVt98Iw6fhxJJbf1s+vY607HYx2vpjBb7mDlAdpv/B pE6Z25OlSf5dUlwocYfJkEAuMnhR/y2o0cGJjFT4= From: "glisse at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/90436] Redundant size checking in vector Date: Sun, 21 Jun 2020 17:13:57 +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: 10.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: glisse at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Jun 2020 17:13:58 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D90436 --- Comment #3 from Marc Glisse --- // possibly assumes that ptrdiff_t and size_t have the same size size_type _M_check_len_one(const char* __str) const { ptrdiff_t __n =3D sizeof(_Tp); ptrdiff_t __ms =3D max_size(); __ms *=3D sizeof(_Tp); ptrdiff_t __s =3D size(); __s *=3D sizeof(_Tp); if (__s > (__ms - __n)) __throw_length_error(__N(__str)); const ptrdiff_t __len =3D __s + (std::max)(__s, __n); if (__len <=3D 0) __builtin_unreachable(); ptrdiff_t __ret =3D (std::min)(__len, __ms); return (_Tp*)__ret-(_Tp*)0; // hack to generate divexact, so it simplifies with * sizeof(_Tp) } generates nicer code. But after those experiments, it seems clear that the performance of this code is irrelevant (not surprising since it is followed= by a call to operator new), and its effect on global performance is random. Possibly it causes something to get aligned differently, which can randomly= get this 25% speed-up, but can just as randomly go back to the slow version. Anyway, I don't think I'll be submitting any patch for this.=