public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "aldyh at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-102958-4-le0hG0YdWD@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-102958-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102958 Aldy Hernandez <aldyh at gcc dot gnu.org> 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 com Summary|std::u8string suboptimal |std::u8string suboptimal |compared to std::string, |compared to std::string |triggers warnings | --- Comment #6 from Aldy Hernandez <aldyh at gcc dot gnu.org> --- 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<char8_t> 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 >= 201703L if (std::__is_constant_evaluated()) return __gnu_cxx::char_traits<char_type>::length(__s); #endif size_t __i = 0; while (!eq(__s[__i], char_type())) ++__i; return __i; } OTOH, the <char> specialization falls back to a __builtin_strlen which which is trivial to see through. I think this boils down to pinski's comment that we fail to see a string length calculation in the following sequence, which survives all the way to the .optimized dump: <bb 3> [local count: 8687547538]: # __i_46 = PHI <__i_22(3), 0(2)> __i_22 = __i_46 + 1; _24 = MEM[(const char_type &)"123456789" + __i_22 * 1]; if (_24 != 0) goto <bb 3>; [89.00%] else goto <bb 4>; [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 optimization?
next prev parent reply other threads:[~2024-01-09 14:32 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-10-26 22:37 [Bug tree-optimization/102958] New: std::u8string suboptimal compared to std::string, triggers warnings msebor at gcc dot gnu.org 2021-10-26 22:40 ` [Bug tree-optimization/102958] " msebor at gcc dot gnu.org 2021-11-19 18:16 ` cvs-commit at gcc dot gnu.org 2021-11-25 19:17 ` pinskia at gcc dot gnu.org 2021-12-09 23:24 ` cvs-commit at gcc dot gnu.org 2021-12-10 22:11 ` jason at gcc dot gnu.org 2024-01-09 14:32 ` aldyh at gcc dot gnu.org [this message] 2024-01-09 14:34 ` [Bug tree-optimization/102958] std::u8string suboptimal compared to std::string aldyh at gcc dot gnu.org 2024-01-09 14:37 ` redi at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-102958-4-le0hG0YdWD@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).