public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/103457] New: boolean operations on bit-fields are not merged
@ 2021-11-28 19:58 roland.illig at gmx dot de
2021-11-28 22:27 ` [Bug tree-optimization/103457] " pinskia at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: roland.illig at gmx dot de @ 2021-11-28 19:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103457
Bug ID: 103457
Summary: boolean operations on bit-fields are not merged
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: roland.illig at gmx dot de
Target Milestone: ---
~~~c
#include <stdbool.h>
typedef struct GNodeFlagsS {
bool remake:1;
bool childMade:1;
bool force:1;
bool doneWait:1;
bool doneOrder:1;
bool fromDepend:1;
bool doneAllsrc:1;
bool cycle:1;
bool doneCycle:1;
} GNodeFlags;
bool
GNodeFlags_IsNone(GNodeFlags flags)
{
return !flags.remake
&& !flags.childMade
&& !flags.force
&& !flags.doneWait
&& !flags.doneOrder
&& !flags.fromDepend
&& !flags.doneAllsrc
&& !flags.cycle
&& !flags.doneCycle;
}
~~~
On x86_64, GCC 11.2 generates:
~~~asm
GNodeFlags_IsNone(GNodeFlagsS):
mov eax, edi
and eax, 1
jne .L6
test dil, 2
jne .L1
mov eax, edi
shr ax, 2
and eax, 1
jne .L6
test dil, 8
jne .L1
mov eax, edi
shr ax, 4
and eax, 1
jne .L6
test dil, 32
jne .L1
mov eax, edi
shr ax, 6
and eax, 1
jne .L6
test dil, dil
js .L1
shr di, 8
mov eax, edi
and eax, 1
xor eax, 1
ret
.L6:
xor eax, eax
.L1:
ret
~~~
ICC 2021.3.0 generates shorter code:
~~~asm
test edi, 1 #18.10
jne ..B1.10 # Prob 50% #18.10
test edi, 2 #19.13
jne ..B1.10 # Prob 50% #19.13
test edi, 4 #20.13
jne ..B1.10 # Prob 50% #20.13
(and so on)
~~~
Many other compilers fail to see the potential for optimizing this code as
well.
Clang is better, it generates:
~~~asm
GNodeFlags_IsNone(GNodeFlagsS): # @GNodeFlags_IsNone(GNodeFlagsS)
test edi, 511
sete al
ret
~~~
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/103457] boolean operations on bit-fields are not merged
2021-11-28 19:58 [Bug tree-optimization/103457] New: boolean operations on bit-fields are not merged roland.illig at gmx dot de
@ 2021-11-28 22:27 ` pinskia at gcc dot gnu.org
2021-11-28 23:20 ` roland.illig at gmx dot de
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-28 22:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103457
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org
Ever confirmed|0 |1
Last reconfirmed| |2021-11-28
Severity|normal |enhancement
Status|UNCONFIRMED |ASSIGNED
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Mine for GCC 13. There is other bugs which are similar too.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/103457] boolean operations on bit-fields are not merged
2021-11-28 19:58 [Bug tree-optimization/103457] New: boolean operations on bit-fields are not merged roland.illig at gmx dot de
2021-11-28 22:27 ` [Bug tree-optimization/103457] " pinskia at gcc dot gnu.org
@ 2021-11-28 23:20 ` roland.illig at gmx dot de
2021-11-29 8:52 ` marxin at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: roland.illig at gmx dot de @ 2021-11-28 23:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103457
--- Comment #2 from Roland Illig <roland.illig at gmx dot de> ---
Cool, thank you for taking this optimization.
Just to give you a bit of background: I discovered this while converting some
of the enum types in BSD Make to proper bitfields, which theoretically should
be possible without affecting the generated code.
https://github.com/NetBSD/src/blob/trunk/usr.bin/make/make.h
It was interesting to play around with this code on https://godbolt.org/,
seeing how differently the available compilers translate this simple code
fragment. That's where the Intel assembler syntax comes from. :)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/103457] boolean operations on bit-fields are not merged
2021-11-28 19:58 [Bug tree-optimization/103457] New: boolean operations on bit-fields are not merged roland.illig at gmx dot de
2021-11-28 22:27 ` [Bug tree-optimization/103457] " pinskia at gcc dot gnu.org
2021-11-28 23:20 ` roland.illig at gmx dot de
@ 2021-11-29 8:52 ` marxin at gcc dot gnu.org
2023-04-26 6:55 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-11-29 8:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103457
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |marxin at gcc dot gnu.org
Target Milestone|--- |13.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/103457] boolean operations on bit-fields are not merged
2021-11-28 19:58 [Bug tree-optimization/103457] New: boolean operations on bit-fields are not merged roland.illig at gmx dot de
` (2 preceding siblings ...)
2021-11-29 8:52 ` marxin at gcc dot gnu.org
@ 2023-04-26 6:55 ` rguenth at gcc dot gnu.org
2023-07-27 9:22 ` rguenth at gcc dot gnu.org
2024-05-21 9:10 ` jakub at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-04-26 6:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103457
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|13.0 |13.2
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 13.1 is being released, retargeting bugs to GCC 13.2.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/103457] boolean operations on bit-fields are not merged
2021-11-28 19:58 [Bug tree-optimization/103457] New: boolean operations on bit-fields are not merged roland.illig at gmx dot de
` (3 preceding siblings ...)
2023-04-26 6:55 ` rguenth at gcc dot gnu.org
@ 2023-07-27 9:22 ` rguenth at gcc dot gnu.org
2024-05-21 9:10 ` jakub at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-27 9:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103457
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|13.2 |13.3
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 13.2 is being released, retargeting bugs to GCC 13.3.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/103457] boolean operations on bit-fields are not merged
2021-11-28 19:58 [Bug tree-optimization/103457] New: boolean operations on bit-fields are not merged roland.illig at gmx dot de
` (4 preceding siblings ...)
2023-07-27 9:22 ` rguenth at gcc dot gnu.org
@ 2024-05-21 9:10 ` jakub at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-05-21 9:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103457
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|13.3 |13.4
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 13.3 is being released, retargeting bugs to GCC 13.4.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-05-21 9:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-28 19:58 [Bug tree-optimization/103457] New: boolean operations on bit-fields are not merged roland.illig at gmx dot de
2021-11-28 22:27 ` [Bug tree-optimization/103457] " pinskia at gcc dot gnu.org
2021-11-28 23:20 ` roland.illig at gmx dot de
2021-11-29 8:52 ` marxin at gcc dot gnu.org
2023-04-26 6:55 ` rguenth at gcc dot gnu.org
2023-07-27 9:22 ` rguenth at gcc dot gnu.org
2024-05-21 9:10 ` 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).