public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/114224] New: popcount RTL cost seems wrong with cssc
@ 2024-03-04 7:19 pinskia at gcc dot gnu.org
2024-03-04 7:58 ` [Bug target/114224] " jakub at gcc dot gnu.org
2024-03-04 23:04 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-04 7:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114224
Bug ID: 114224
Summary: popcount RTL cost seems wrong with cssc
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Target: aarch64
I noticed this with:
```
#include <stdint.h>
bool is_power_of_2_1(uint64_t value)
{
return __builtin_popcountg(value) == 1;
}
```
Which I had expected to produce:
```
cnt x0, x0
cmp x0, 1
cset w0, eq
```
But instead we get:
```
sub x1, x0, #1
eor x0, x0, x1
cmp x0, x1
cset w0, hi
ret
```
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug target/114224] popcount RTL cost seems wrong with cssc
2024-03-04 7:19 [Bug target/114224] New: popcount RTL cost seems wrong with cssc pinskia at gcc dot gnu.org
@ 2024-03-04 7:58 ` jakub at gcc dot gnu.org
2024-03-04 23:04 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-03-04 7:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114224
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> ---
This is a matter of rtl costs.
.POPCOUNT expansion in expand_POPCOUNT expands the sequence both ways and asks
the backend what is cheaper:
/* If .POPCOUNT call has 2 arguments, match_single_bit_test marked it
because the result is only used in an equality comparison against 1.
Use rtx costs in that case to determine if .POPCOUNT (arg) == 1
or (arg ^ (arg - 1)) > arg - 1 is cheaper.
If .POPCOUNT second argument is 0, we additionally know that arg
is non-zero, so use arg & (arg - 1) == 0 instead. */
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug target/114224] popcount RTL cost seems wrong with cssc
2024-03-04 7:19 [Bug target/114224] New: popcount RTL cost seems wrong with cssc pinskia at gcc dot gnu.org
2024-03-04 7:58 ` [Bug target/114224] " jakub at gcc dot gnu.org
@ 2024-03-04 23:04 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-04 23:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114224
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org
Last reconfirmed| |2024-03-04
Ever confirmed|0 |1
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Interesting:
```
int h1(unsigned a)
{
return __builtin_popcountg(a) == 1;
}
```
works.
Anyways I will be adding POPCOUNT's rtl cost here.
We don't even handle POPCOUNT for vector modes either ...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-04 23:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-04 7:19 [Bug target/114224] New: popcount RTL cost seems wrong with cssc pinskia at gcc dot gnu.org
2024-03-04 7:58 ` [Bug target/114224] " jakub at gcc dot gnu.org
2024-03-04 23:04 ` 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).