public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/106076] New: Sub-optimal code is generated for checking bitfields via proxy functions
@ 2022-06-24 10:02 kyrylo.bohdanenko at gmail dot com
2022-06-24 10:11 ` [Bug tree-optimization/106076] " kyrylo.bohdanenko at gmail dot com
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: kyrylo.bohdanenko at gmail dot com @ 2022-06-24 10:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106076
Bug ID: 106076
Summary: Sub-optimal code is generated for checking bitfields
via proxy functions
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: kyrylo.bohdanenko at gmail dot com
Target Milestone: ---
Consider the following struct:
#include <cstdint>
struct SomeClass {
uint16_t dummy1 : 1;
uint16_t cfg2 : 1;
uint16_t cfg3 : 1;
uint16_t dummy2 : 1;
uint16_t dummy3 : 1;
uint16_t dummy4 : 1;
uint16_t cfg1 : 1;
uint16_t dummy5 : 1;
uint16_t cfg4 : 1;
constexpr bool checkA() const { return cfg1 || cfg2 || cfg3; }
constexpr bool checkB() const { return cfg4; }
constexpr bool checkA_B() const { return (cfg1 || cfg2 || cfg3) || cfg4; }
constexpr bool checkA_B_SLOW() const { return checkA() || checkB(); }
};
For the following functions (which do the same thing) GCC generates different
assembly.
bool check(const SomeClass& rt) {
return rt.checkA_B();
}
bool check_SLOW(const SomeClass& rt) {
return rt.checkA_B_SLOW();
}
Compiled as:
g++ -std=c++17 -S
The assembly:
; demangled: check(SomeClass const&)
_Z5checkRK9SomeClass:
endbr64
testw $326, (%rdi)
setne %al
ret
; demangled: check_SLOW(SomeClass const&)
_Z10check_SLOWRK9SomeClass:
endbr64
movzwl (%rdi), %edx
movl $1, %eax
testb $70, %dl
jne .L3
movzbl %dh, %eax
andl $1, %eax
.L3:
ret
As we can see, during check_SLOW GCC decided to check the result on
byte-by-byte basis introducing a conditional jump in between. It looks like GCC
did not fully analyse the code after inlining checkA() and checkB().
FYI, the same code on Clang produces the 1st option of ASM for both functions.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/106076] Sub-optimal code is generated for checking bitfields via proxy functions
2022-06-24 10:02 [Bug tree-optimization/106076] New: Sub-optimal code is generated for checking bitfields via proxy functions kyrylo.bohdanenko at gmail dot com
@ 2022-06-24 10:11 ` kyrylo.bohdanenko at gmail dot com
2022-06-24 10:41 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: kyrylo.bohdanenko at gmail dot com @ 2022-06-24 10:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106076
--- Comment #1 from Kyrylo Bohdanenko <kyrylo.bohdanenko at gmail dot com> ---
The provided assembly is for -O2/-O3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/106076] Sub-optimal code is generated for checking bitfields via proxy functions
2022-06-24 10:02 [Bug tree-optimization/106076] New: Sub-optimal code is generated for checking bitfields via proxy functions kyrylo.bohdanenko at gmail dot com
2022-06-24 10:11 ` [Bug tree-optimization/106076] " kyrylo.bohdanenko at gmail dot com
@ 2022-06-24 10:41 ` rguenth at gcc dot gnu.org
2022-10-24 5:09 ` pinskia at gcc dot gnu.org
2022-10-24 5:09 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-06-24 10:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106076
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2022-06-24
Status|UNCONFIRMED |NEW
Keywords| |missed-optimization
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. that's fold-const.c optimize_bit_field_compare that doesn't work on
GIMPLE (after inlining). The fold-const.c part is also premature so moving it
to GIMPLE would be appreciated.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/106076] Sub-optimal code is generated for checking bitfields via proxy functions
2022-06-24 10:02 [Bug tree-optimization/106076] New: Sub-optimal code is generated for checking bitfields via proxy functions kyrylo.bohdanenko at gmail dot com
2022-06-24 10:11 ` [Bug tree-optimization/106076] " kyrylo.bohdanenko at gmail dot com
2022-06-24 10:41 ` rguenth at gcc dot gnu.org
@ 2022-10-24 5:09 ` pinskia at gcc dot gnu.org
2022-10-24 5:09 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-24 5:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106076
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Mine. I am going to get this upstream finally for GCC 14.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/106076] Sub-optimal code is generated for checking bitfields via proxy functions
2022-06-24 10:02 [Bug tree-optimization/106076] New: Sub-optimal code is generated for checking bitfields via proxy functions kyrylo.bohdanenko at gmail dot com
` (2 preceding siblings ...)
2022-10-24 5:09 ` pinskia at gcc dot gnu.org
@ 2022-10-24 5:09 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-24 5:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106076
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-10-24 5:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-24 10:02 [Bug tree-optimization/106076] New: Sub-optimal code is generated for checking bitfields via proxy functions kyrylo.bohdanenko at gmail dot com
2022-06-24 10:11 ` [Bug tree-optimization/106076] " kyrylo.bohdanenko at gmail dot com
2022-06-24 10:41 ` rguenth at gcc dot gnu.org
2022-10-24 5:09 ` pinskia at gcc dot gnu.org
2022-10-24 5:09 ` 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).