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
* [Bug middle-end/115095] [missed optimization] fixed processing on constant string
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 ` pinskia at gcc dot gnu.org
2024-05-15 6:31 ` rguenth at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-14 20:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115095
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Component|c |middle-end
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug middle-end/115095] [missed optimization] fixed processing on constant string
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
1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-05-15 6:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115095
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
CC| |hubicka at gcc dot gnu.org,
| |rguenth at gcc dot gnu.org
Status|UNCONFIRMED |NEW
Last reconfirmed| |2024-05-15
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC isn't able to compute the number of iterations of a loop like the following
which would be required for us to peel it and do the required constant folding.
We're also not trying brute-force peeling for loops we cannot compute an
upper bound of its number of iterations (attempting to arrive at one when
evaluating the peeled stmts).
<bb 3> [local count: 955630224]:
# _26 = PHI <_9(8), 116(2)>
# h_27 = PHI <h_15(8), 0(2)>
# s_29 = PHI <s_14(8), "t.c"(2)>
_10 = (unsigned int) _26;
h_12 = _10 + h_27;
s_14 = s_29 + 1;
h_15 = _10 * h_12;
_9 = *s_14;
if (_9 != 0)
goto <bb 8>; [89.00%]
else
goto <bb 4>; [11.00%]
<bb 8> [local count: 850510900]:
goto <bb 3>; [100.00%]
^ 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).