public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/115095] New: [missed optimization] fixed processing on constant string
@ 2024-05-14 20:06 yann at droneaud dot fr
  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
  0 siblings, 2 replies; 3+ messages in thread
From: yann at droneaud dot fr @ 2024-05-14 20:06 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-15  6:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-14 20:06 [Bug c/115095] New: [missed optimization] fixed processing on constant string yann at droneaud dot fr
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

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).