From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8B6713858C3A; Tue, 14 May 2024 20:06:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B6713858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715717178; bh=Ni3cE3OsghYJAnxxyjdQ9yh2Fp5sy735kBYmNoEpd6Q=; h=From:To:Subject:Date:From; b=bQR0r74Cwc0BkjyAx02EtKJFZNZ/1zmzot+dszJp7zo0nSBAatu3ZKI/VscAHlZyO xZTl9IMA81ejuxkYT6GZjbUSw19Wx2iE9DrG0yYXj3rzLA02rkT8WktQ1/SyRYnU6z HjQr1RkornSe3CKAP5YRsn2kx4U3Lc6HB2hRY5aI= From: "yann at droneaud dot fr" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 15.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: yann at droneaud dot fr X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: 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=3D115095 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=3D58208&action=3Dedit source code of https://godbolt.org/z/Meqvbj8GG I've found clang was able to compute the result of hashing a constant strin= g 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 +=3D *s; h *=3D *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 ti= me 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 compi= le time. See https://godbolt.org/z/Meqvbj8GG=