From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E93223858D3C; Fri, 16 Jun 2023 15:37:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E93223858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686929821; bh=LUqSL50l+r2vsFiyfg1lBbXBIhgCnacmi1NLbOx5wOE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CJzwzLMjtFrT+W9VHOZOY3jRFI9W6wtSsO5PFDlwLKro8vShOTwezr9Dw2fdvrqWs h5KpgB18PXsXGQ4PVcoQUETTtuLt0MFLX3+GJ6MBIbIZOk9/O3zTiWwSWTBZT7P8L7 zSAGcguPryJ1PdLGyXfQ3ITR5Maahcb6rnFqQKbQ= From: "hubicka at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/110287] _M_check_len is expensive Date: Fri, 16 Jun 2023 15:37:01 +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: 13.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hubicka 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110287 --- Comment #2 from Jan Hubicka --- With patch in PR110289 to optimize the std::max int MAX_EXPR and the throw commented out I get: size_type std::vector >::_M_check_len (const struct vector * const this, size_type __n, const char * __s) { const size_type __len; size_type iftmp.2_1; long unsigned int _2; long unsigned int _5; long unsigned int _7; struct pair * _8; struct pair * _9; long int _10; long int _11; long unsigned int _12; [local count: 1073741824]: _8 =3D this_4(D)->D.26707._M_impl.D.26014._M_finish; _9 =3D this_4(D)->D.26707._M_impl.D.26014._M_start; _10 =3D _8 - _9; _11 =3D _10 /[ex] 8; _12 =3D (long unsigned int) _11; _7 =3D __n; _5 =3D MAX_EXPR <_7, _12>; __len_6 =3D _5 + _12; if (__len_6 < _12) goto ; [35.00%] else goto ; [65.00%] [local count: 697932185]: _2 =3D MIN_EXPR <__len_6, 1152921504606846975>; [local count: 1073741824]: # iftmp.2_1 =3D PHI <1152921504606846975(2), _2(3)> return iftmp.2_1; } which fits early inlining limits. So modifying libstdc++ to avoid the throw would be great. Again optimized _M_check_len could avoid: [local count: 697932185]: _2 =3D MIN_EXPR <__len_6, 1152921504606846975>; [local count: 1073741824]: # iftmp.2_1 =3D PHI <1152921504606846975(2), _2(3)> return iftmp.2_1; since __len can not get that large without running out of memory. Which wou= ld help further inlining. Testcase from PR109849 now runs in 0.39s while without these two changes it runs in 0.528s, clang's build runs in 0.057s, so still a long way to go.=