public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "antoshkka at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109931] New: Knowledge on literal not used in optimization Date: Mon, 22 May 2023 12:33:29 +0000 [thread overview] Message-ID: <bug-109931-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109931 Bug ID: 109931 Summary: Knowledge on literal not used in optimization Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: antoshkka at gmail dot com Target Milestone: --- Function for comparing a lower-cased string with runtime string of known size: constexpr bool ICaseEqualLowercase(const char* lowercase, const char* y, unsigned size) noexcept { constexpr char kLowerToUpperMask = static_cast<char>(~unsigned{32}); for (unsigned i = 0; i < size; ++i) { const auto lowercase_c = lowercase[i]; if (lowercase_c != y[i]) { if (!('a' <= lowercase_c && lowercase_c <= 'z') || (lowercase_c & kLowerToUpperMask) != y[i]) { return false; } } } return true; } bool test2(const char* y) { return ICaseEqualLowercase("hello", y, 5); } With GCC trunk and -O2 flags the GCC fails to understand that all the characters of `lowercase` are lowercase ASCII and the expression `!('a' <= lowercase_c && lowercase_c <= 'z')` is always `false`. Because of that, additional instructions in loop are emitted: lea esi, [rdx-97] cmp sil, 25 ja .L6 Godbolt playground: https://godbolt.org/z/xrc1T4oeW
next reply other threads:[~2023-05-22 12:33 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-22 12:33 antoshkka at gmail dot com [this message] 2023-05-22 12:37 ` [Bug tree-optimization/109931] " rguenth at gcc dot gnu.org 2023-05-22 12:38 ` jakub at gcc dot gnu.org 2023-05-22 12:57 ` antoshkka at gmail dot com 2023-05-22 14:53 ` pinskia 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-109931-4@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).