https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96062

--- Comment #1 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Joseph C. Sible from comment #0)
> Consider this C code:
> 
> long ps4_syscall0(long n) {
>     long ret;
>     int carry;
>     __asm__ __volatile__(
>         "syscall"
>         : "=a"(ret), "=@ccc"(carry)
>         : "a"(n)
>         : "rcx", "r8", "r9", "r10", "r11", "memory"
>     );
>     return carry ? -ret : ret;
> }
> 
> With "-O3", it results in this assembly:
> 
> ps4_syscall0:
>         movq    %rdi, %rax
>         syscall
>         setc    %dl
>         movq    %rax, %rdi
>         movzbl  %dl, %edx
>         negq    %rdi
>         testl   %edx, %edx
>         cmovne  %rdi, %rax
>         ret
> 
> On modern Intel CPUs, doing "setc %dl" creates a false dependency on rdx.
> Doing "movzbl %dl, %edx" doesn't do anything to fix that. Here's some ways
> that we could improve this code, without having to fall back to a
> conditional branch:
> 
> 1. Get rid of "movzbl %dl, %edx" (since it doesn't help), and then do "testb
> %dl, %dl" instead of "testl %edx, %edx".

Just declare "_Bool carry". There is no need for int.

Reply via email to