From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 56B81385829F; Tue, 9 Jan 2024 14:32:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56B81385829F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704810740; bh=R0Kbh692Vza8Z24KotQd9I8/lOKwzlQdFrR0uyu2VSE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RtIJaI7DgExyzLB2pHf4tZN9Cy+WCkoDGhr8cz9A8xKthBYUjUFQbJUd/+aIQP/If CxGkU6dRG5AW8O1kaUErvRcdeYelfsFXORP3B/E3AcQlekbsjPDTn48ooEhEMrLCdU 97Y/VB+s+Zq4/L/3hEbMMk+AbIFRfTeBvjsYL1Gg= From: "aldyh at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102958] std::u8string suboptimal compared to std::string Date: Tue, 09 Jan 2024 14:32:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: aldyh at gcc dot gnu.org X-Bugzilla-Status: NEW 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: cc short_desc 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=3D102958 Aldy Hernandez changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |aldyh at gcc dot gnu.org, | |amacleod at redhat dot com, | |jakub at gcc dot gnu.org, | |jason at gcc dot gnu.org, | |jwakely.gcc at gmail dot c= om Summary|std::u8string suboptimal |std::u8string suboptimal |compared to std::string, |compared to std::string |triggers warnings | --- Comment #6 from Aldy Hernandez --- Adjusting description, since not only have we disabled the warning in the C= ++ headers so this no longer warns, but the underlying problem has nothing to = do with warnings. The char_traits specialization is opaque enough such that we can't figure out the length: static _GLIBCXX17_CONSTEXPR size_t length(const char_type* __s) { #if __cplusplus >=3D 201703L if (std::__is_constant_evaluated()) return __gnu_cxx::char_traits::length(__s); #endif size_t __i =3D 0; while (!eq(__s[__i], char_type())) ++__i; return __i; } OTOH, the specialization falls back to a __builtin_strlen which whic= h is trivial to see through. I think this boils down to pinski's comment that we fail to see a string le= ngth calculation in the following sequence, which survives all the way to the .optimized dump: [local count: 8687547538]: # __i_46 =3D PHI <__i_22(3), 0(2)> __i_22 =3D __i_46 + 1; _24 =3D MEM[(const char_type &)"123456789" + __i_22 * 1]; if (_24 !=3D 0) goto ; [89.00%] else goto ; [11.00%] I've seen variations of the above being turned into __builtin_strlen by fre, ldist, as well as the strlen [ass. Who's job is it perform this optimizati= on?=