This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/80770] New: suboptimal code negating a 1-bit _Bool field
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 15 May 2017 23:06:08 +0000
- Subject: [Bug rtl-optimization/80770] New: suboptimal code negating a 1-bit _Bool field
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80770
Bug ID: 80770
Summary: suboptimal code negating a 1-bit _Bool field
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
For all targets I tried (powerpc64, sparcv9, and x86_64), GCC emits worse code
for the negation of a 1-bit _Bool field than it does for the equivalent _Bool
(non-bit) field. The following test case shows the difference. The code for
fb1 should look the same as the code for fb2. A _Bool bit-field is typically
used as a (space) optimization so emitting bigger and slower code defeats its
sole purpose.
Clang emits the same code for both function for the same targets.
$ cat a.c && gcc -O2 -S -Wall -Wextra -Wconversion -o/dev/stdout a.c
struct S {
_Bool b1: 1;
_Bool b;
};
void fb1 (struct S *s)
{
s->b1 = !s->b1;
}
void fb (struct S *s)
{
s->b = !s->b;
}
.file "a.c"
.text
.p2align 4,,15
.globl fb1
.type fb1, @function
fb1:
.LFB0:
.cfi_startproc
movzbl (%rdi), %eax
movl %eax, %edx
andl $-2, %eax
andl $1, %edx
xorl $1, %edx
orl %edx, %eax
movb %al, (%rdi)
ret
.cfi_endproc
.LFE0:
.size fb1, .-fb1
.p2align 4,,15
.globl fb
.type fb, @function
fb:
.LFB1:
.cfi_startproc
xorb $1, 1(%rdi)
ret
.cfi_endproc
.LFE1:
.size fb, .-fb
.ident "GCC: (GNU) 7.0.1 20170418 (experimental)"
.section .note.GNU-stack,"",@progbits
tmp$