https://bugs.llvm.org/show_bug.cgi?id=46316
Bug ID: 46316
Summary: Clang unnecessarily uses rbx and pushes it and rax
Product: new-bugs
Version: 10.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
Consider this code:
int g(int);
void h(void);
int f(int x) {
if(g(0) == -1) {
return 1;
}
h();
return 0;
}
When compiled on Clang 10.0.0 on x86-64 Linux with "-O3
-fno-omit-frame-pointer", it produces this:
f:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
xorl %ebx, %ebx
xorl %edi, %edi
callq g
cmpl $-1, %eax
je .LBB0_1
callq h
jmp .LBB0_3
.LBB0_1:
movl $1, %ebx
.LBB0_3:
movl %ebx, %eax
addq $8, %rsp
popq %rbx
popq %rbp
retq
https://godbolt.org/z/J3It3A
There's no need to mess with ebx at all, or to push anything other than rbp. It
should have produced something like this instead:
f:
pushq %rbp
movq %rsp, %rbp
xorl %edi, %edi
callq g
cmpl $-1, %eax
je .LBB0_1
callq h
xorl %eax, %eax
popq %rbp
retq
.LBB0_1:
movl $1, %eax
popq %rbp
retq
And Clang basically knows how to emit that code. In particular, if I change
"g(0)" to "g(x)", then that's exactly what I get, aside from the "xorl %edi,
%edi".
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs