public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114853] New: Inefficient code with a bunch of bitwise checks
@ 2024-04-25 13:05 gh228df at gmail dot com
2024-04-25 13:40 ` [Bug tree-optimization/114853] " rguenth at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: gh228df at gmail dot com @ 2024-04-25 13:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114853
Bug ID: 114853
Summary: Inefficient code with a bunch of bitwise checks
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gh228df at gmail dot com
Target Milestone: ---
Here is a compiler explorer link https://godbolt.org/z/WccxhnTfK, the first
function is 'inefficient' while the second function does the same while having
1/2 assembly lines of the first function and will probably run faster in some
cases. The problem is that the compiler doesnt generate negated constant once
in the start but rather keeps generating it over and over again before every
check which is very inefficient
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/114853] Inefficient code with a bunch of bitwise checks
2024-04-25 13:05 [Bug c++/114853] New: Inefficient code with a bunch of bitwise checks gh228df at gmail dot com
@ 2024-04-25 13:40 ` rguenth at gcc dot gnu.org
2024-04-25 15:42 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-25 13:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114853
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c++ |tree-optimization
Keywords| |missed-optimization
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
possibly switch-conversion related
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/114853] Inefficient code with a bunch of bitwise checks
2024-04-25 13:05 [Bug c++/114853] New: Inefficient code with a bunch of bitwise checks gh228df at gmail dot com
2024-04-25 13:40 ` [Bug tree-optimization/114853] " rguenth at gcc dot gnu.org
@ 2024-04-25 15:42 ` pinskia at gcc dot gnu.org
2024-04-25 15:48 ` pinskia at gcc dot gnu.org
2024-04-25 17:47 ` [Bug middle-end/114853] " pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-25 15:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114853
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 58040
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58040&action=edit
testcase
Please next time, attach (or place inline) the testcase and not just link to
godbolt.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/114853] Inefficient code with a bunch of bitwise checks
2024-04-25 13:05 [Bug c++/114853] New: Inefficient code with a bunch of bitwise checks gh228df at gmail dot com
2024-04-25 13:40 ` [Bug tree-optimization/114853] " rguenth at gcc dot gnu.org
2024-04-25 15:42 ` pinskia at gcc dot gnu.org
@ 2024-04-25 15:48 ` pinskia at gcc dot gnu.org
2024-04-25 17:47 ` [Bug middle-end/114853] " pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-25 15:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114853
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Last reconfirmed| |2024-04-25
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #1)
> possibly switch-conversion related
iftoswitch does not get invoked here but maybe it should ...
I will note that for aarch64, clang/LLVM is able to vectorize this function.
But not for x86_64.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug middle-end/114853] Inefficient code with a bunch of bitwise checks
2024-04-25 13:05 [Bug c++/114853] New: Inefficient code with a bunch of bitwise checks gh228df at gmail dot com
` (2 preceding siblings ...)
2024-04-25 15:48 ` pinskia at gcc dot gnu.org
@ 2024-04-25 17:47 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-25 17:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114853
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|tree-optimization |middle-end
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So what is happening is there is a missed Canonicalization happening here at
the gimple level and only at the RTL level we decide to expand `(num & 7LL) ==
7LL` as `((~num) & 7) == 0` (for x86_64). For aarch64 we expand still as `(num
&7) == 7`.
So we should pick one for the gimple level and then expand it and also actually
do better CSE of `~num` for the RTL level.
The other thing GCC should do better at is handle:
```
bool checko(long long num) {
if((num & 7LL) == 7LL)
return true;
if((num & 22LL) == 22LL)
return true;
return false;
}
```
Into:
```
and x1, x0, 7
mov x2, 22
cmp x1, 7
and x0, x0, x2
ccmp x0, x2, 4, ne
cset w0, eq
```
For aarch64.
I have an idea there ...
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-04-25 17:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-25 13:05 [Bug c++/114853] New: Inefficient code with a bunch of bitwise checks gh228df at gmail dot com
2024-04-25 13:40 ` [Bug tree-optimization/114853] " rguenth at gcc dot gnu.org
2024-04-25 15:42 ` pinskia at gcc dot gnu.org
2024-04-25 15:48 ` pinskia at gcc dot gnu.org
2024-04-25 17:47 ` [Bug middle-end/114853] " 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).