Re: optimizer discards sign information

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



在 2024-04-10 17:19, Xi Ruoyao via Gcc-help 写道:
$ cc t.c -O2 -fsanitize=undefined
$ ./a.out
t.c:7:15: runtime error: signed integer overflow: 65535 * 65535 cannot be represented in type 'int'
fffe0001

Undefined behavior is not a valid point, as it never happens. It's a real bug. There are many PRs on bugzilla.


The sign extension could have been eliminated completely:

   movzx eax, si
   movzx edi, di
   imul eax, edi
   ret


And here is a similar issue:

   typedef unsigned long long int u64;
   typedef unsigned int u32;

   u64 foo(u64 a) {
     return (u32) __builtin_ctzll(a);
   }

which results in

   xor eax, eax
   rep bsf rax, rdi   // effectively `tzcnt rax, rdi`
   cdqe               // unnecessary sign-extension
   ret


--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux