在 2023/1/9 19:48, Thomas Koenig via Gcc 写道:
On 09.01.23 12:35, Stefan Kanthak wrote:
20 superfluous instructions of the total 102 instructions!

The proper place for bug reports is https://gcc.gnu.org/bugzilla/ .
Feel free to submit these cases there.

Created https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108341, although I'm not sure whether it's related to this issue.


Given

   ```
   extern int r;

   int
   bz(int value)
     {
       r = __builtin_ctz(value);
       return value != 0;  // always true
     }
   ```

`value` is passed to `__builtin_ctz` and GCC should assume it can't be zero, otherwise the behavior is undefined. However GCC fails to optimize it and produces:

   ```
   bz:
     endbr64
     xor        eax, eax
     rep bsf    eax, edi
     mov        DWORD PTR r[rip], eax
     xor        eax, eax
     test       edi, edi
     setne      al
     ret
   ```


--
Best regards,
LIU Hao

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to