public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "yann at droneaud dot fr" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/115095] New: [missed optimization] fixed processing on constant string Date: Tue, 14 May 2024 20:06:17 +0000 [thread overview] Message-ID: <bug-115095-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115095 Bug ID: 115095 Summary: [missed optimization] fixed processing on constant string Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: yann at droneaud dot fr Target Milestone: --- Created attachment 58208 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58208&action=edit source code of https://godbolt.org/z/Meqvbj8GG I've found clang was able to compute the result of hashing a constant string at compile time. I would have hope GCC -O3 would be able to optimize such computation as well: static inline unsigned int hash(unsigned int h, const char *s) { while (*s) { h += *s; h *= *s++; } return h; } #define LOCATION() hash(hash(0, __FILE__), __func__) unsigned int location(void) { return LOCATION(); } is translated by clang to location: movl $1418535820, %eax retq but not by GCC, which doesn't compute the value of LOCATION() at compile time but emit code that compute the value at runtime. At first, I thought it was an issue with handling __FILE__ or __func__, but trying with other string constants, GCC is not computing the value at compile time. See https://godbolt.org/z/Meqvbj8GG
next reply other threads:[~2024-05-14 20:06 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-05-14 20:06 yann at droneaud dot fr [this message] 2024-05-14 20:09 ` [Bug middle-end/115095] " pinskia at gcc dot gnu.org 2024-05-15 6:31 ` rguenth 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-115095-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).