Suboptimal code generated for _Bool
Marcin 'Qrczak' Kowalczyk
qrczak@knm.org.pl
Sun Jun 20 12:22:00 GMT 2004
W liście z nie, 20-06-2004, godz. 12:14 +0200, Marcin 'Qrczak' Kowalczyk
napisał(a):
> The movzbl is completely unnecessary. It's inserted even if the called
> function is inline.
Another example:
#include <stdbool.h>
static inline bool test1(int x) {return x == 5;}
static inline bool test2(int x) {return test1(x) || x == 10;}
int test3(int x) {return test2(x) ? x : 0;}
Generated code:
test3:
movl 4(%esp), %eax
xorl %edx, %edx
cmpl $5, %eax
je .L5
cmpl $10, %eax
jne .L4
.p2align 4,,7
.L5:
movl $1, %edx
.L4:
testb %dl, %dl
jne .L3
xorl %eax, %eax
.L3:
rep ; ret
BTW, what is the "rep ; ret" in the last line?
If bool is replaced with int, the code is better, but still with
redundant movl's, even with -O2 or -O3:
test3:
movl 4(%esp), %eax
cmpl $5, %eax
je .L5
xorl %edx, %edx
cmpl $10, %eax
je .L5
movl %edx, %eax
ret
.p2align 4,,7
.L5:
movl %eax, %edx
movl %edx, %eax
.p2align 4,,2
ret
--
__("< Marcin Kowalczyk
\__/ qrczak@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/
More information about the Gcc
mailing list