GNU C version 4.0.0 20041209 (experimental)
_Bool f1(const _Bool *p) { return *p & 1; }
_Bool f2(const _Bool *p) { return *p + 0; }
_Bool f3(_Bool *p) { *p ^= 1; }
_Bool f4(_Bool *p) { *p = ~*p; }
yields
f1: ldbu v0,0(a0)
and v0,0x1,v0
ret
f2: ldbu v0,0(a0)
cmpult zero,v0,v0
ret
f3: ldbu t0,0(a0)
cmpeq t0,0x1,t0
cmpeq t0,0,t0
stb t0,0(a0)
ret
f4: ldbu t0,0(a0)
not t0,t0
sextl t0,t0
cmpult zero,t0,t0
stb t0,0(a0)
ret
all of which contain at least one superfluous instruction.
--
Summary: Missed folding opportunities with bools
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P2
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: falk at debian dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: alphaev68-unknown-linux-gnu
GCC host triplet: alphaev68-unknown-linux-gnu
GCC target triplet: alphaev68-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18908