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

--- Comment #24 from Bernd Buschinski <b.buschinski at googlemail dot com> ---
Hi, during development I found 2 more potential differences/issues:

Compiler Explorer: https://godbolt.org/z/8597v3rz8

For the code:
```
#include <stdbool.h>

int foo2(int a, int b) {
    return !!(a & (1 << b));
}

bool foo3(int a, int b, int c) {
    return (a & b & (1 << c));
}
```

GCC generated:
```
"foo2":
        mov     ecx, esi
        sar     edi, cl
        mov     eax, edi
        and     eax, 1
        ret
"foo3":
        mov     ecx, edx
        mov     eax, 1
        sal     eax, cl
        and     eax, esi
        test    eax, edi
        setne   al
        ret
```

and clang:

```
foo2:
        xorl    %eax, %eax
        btl     %esi, %edi
        setb    %al
        retq

foo3:
        andl    %esi, %edi
        btl     %edx, %edi
        setb    %al
        retq
```

which looks shorter and possible faster.
Can GCC be improved to generate similar code to clang?

Reply via email to