public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/95836] New: Failure to remove strchr converted to bool with string literal when bit magic would be much more efficient (and sometimes smaller)
@ 2020-06-23 9:41 gabravier at gmail dot com
2020-06-23 9:48 ` [Bug tree-optimization/95836] " jakub at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: gabravier at gmail dot com @ 2020-06-23 9:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95836
Bug ID: 95836
Summary: Failure to remove strchr converted to bool with string
literal when bit magic would be much more efficient
(and sometimes smaller)
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
bool f(char c)
{
return strchr("1234567890", c);
}
This (and a lot of other similar strchr calls with string literals) can be
optimized to using a few bitwise operations (here, to something like `return
((unsigned)c < 64) & ((((uint64_t)1 << c) & 287948901175001089) != 0);`). This
transformation is done by LLVM, but not by GCC.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/95836] Failure to remove strchr converted to bool with string literal when bit magic would be much more efficient (and sometimes smaller)
2020-06-23 9:41 [Bug tree-optimization/95836] New: Failure to remove strchr converted to bool with string literal when bit magic would be much more efficient (and sometimes smaller) gabravier at gmail dot com
@ 2020-06-23 9:48 ` jakub at gcc dot gnu.org
2020-06-23 15:55 ` gabravier at gmail dot com
2020-06-23 16:43 ` jakub at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-06-23 9:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95836
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
With & it would actually invoke UB for c >= 64U.
So it has to be either &&, or << (c & 63), at least until we know exactly what
the behavior on out of bounds shift will be.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/95836] Failure to remove strchr converted to bool with string literal when bit magic would be much more efficient (and sometimes smaller)
2020-06-23 9:41 [Bug tree-optimization/95836] New: Failure to remove strchr converted to bool with string literal when bit magic would be much more efficient (and sometimes smaller) gabravier at gmail dot com
2020-06-23 9:48 ` [Bug tree-optimization/95836] " jakub at gcc dot gnu.org
@ 2020-06-23 15:55 ` gabravier at gmail dot com
2020-06-23 16:43 ` jakub at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: gabravier at gmail dot com @ 2020-06-23 15:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95836
--- Comment #2 from Gabriel Ravier <gabravier at gmail dot com> ---
Yeah I wasn't sure whether this was legitimate, I was just trying to give a
small example here, I dont think doesn't changes anything to how the
optimization is able to work unless GCC has targets where `a << b` with `b >
BITS_IN_A` traps.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/95836] Failure to remove strchr converted to bool with string literal when bit magic would be much more efficient (and sometimes smaller)
2020-06-23 9:41 [Bug tree-optimization/95836] New: Failure to remove strchr converted to bool with string literal when bit magic would be much more efficient (and sometimes smaller) gabravier at gmail dot com
2020-06-23 9:48 ` [Bug tree-optimization/95836] " jakub at gcc dot gnu.org
2020-06-23 15:55 ` gabravier at gmail dot com
@ 2020-06-23 16:43 ` jakub at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-06-23 16:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95836
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Well, it does, we can't keep it in the IL in that form because the compiler
itself might optimize it away on the assumption that UB doesn't happen.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-06-23 16:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23 9:41 [Bug tree-optimization/95836] New: Failure to remove strchr converted to bool with string literal when bit magic would be much more efficient (and sometimes smaller) gabravier at gmail dot com
2020-06-23 9:48 ` [Bug tree-optimization/95836] " jakub at gcc dot gnu.org
2020-06-23 15:55 ` gabravier at gmail dot com
2020-06-23 16:43 ` jakub 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).