public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/106244] New: Failure to optimize (1 << x) & 1 to `x == 0` if separated into multiple statements
@ 2022-07-10 8:56 gabravier at gmail dot com
2022-07-10 20:22 ` [Bug tree-optimization/106244] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: gabravier at gmail dot com @ 2022-07-10 8:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106244
Bug ID: 106244
Summary: Failure to optimize (1 << x) & 1 to `x == 0` if
separated into multiple statements
Product: gcc
Version: 13.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: ---
#include <stdint.h>
int8_t f(int8_t x)
{
int8_t sh = 1 << x;
return sh & 1;
}
This can be optimized to `return x == 0;`. This transformation is done by LLVM,
but not by GCC.
PS: For some reason GCC manages to do this optimization if I replace `f` with
`return (1 << x) & 1;` instead of having it spelled out in 2 statements.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-07-10 20:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-10 8:56 [Bug tree-optimization/106244] New: Failure to optimize (1 << x) & 1 to `x == 0` if separated into multiple statements gabravier at gmail dot com
2022-07-10 20:22 ` [Bug tree-optimization/106244] " pinskia 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).