public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* optimizer discards sign information
@ 2024-04-10  8:52 stefan
  2024-04-10  9:16 ` Alexander Monakov
  0 siblings, 1 reply; 20+ messages in thread
From: stefan @ 2024-04-10  8:52 UTC (permalink / raw)
  To: gcc-help

Hi all,

I just stumbled over an issue, which is present in almost all gcc versions.
I worked around using inline assembly…
Maybe gcc behaves correct and I am wrong? Here is the code:

https://godbolt.org/z/cW8jcdh56

typedef unsigned long long int u64;
typedef unsigned int u32;
typedef unsigned short u16;

u64 foo(u16 a, u16 b) {
    u32 x = a * b;
    u64 r = x;
    return r;
}

And on gcc 13.2 x86.64 you get

foo:
        movzx   esi, si
        movzx   edi, di
        imul    edi, esi
        movsx   rax, edi
        ret


There is a sign extension! The optimizer step discards the information

	 x_6 = (u32) _3;

and uses _3 directly instead, which is signed.

Am I wrong or is it gcc?

Since this is a tree pass, all targets are affected. And it’s already
present in gcc-6.5

Best regards

Stefan 



^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2024-04-11  0:32 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-10  8:52 optimizer discards sign information stefan
2024-04-10  9:16 ` Alexander Monakov
2024-04-10  9:19   ` Xi Ruoyao
2024-04-10  9:40     ` LIU Hao
2024-04-10  9:44       ` Xi Ruoyao
2024-04-10  9:51         ` LIU Hao
2024-04-10  9:52           ` Xi Ruoyao
2024-04-10 10:07             ` LIU Hao
2024-04-10 10:17               ` Xi Ruoyao
2024-04-10 10:03           ` AW: " stefan
2024-04-10 10:34             ` Xi Ruoyao
2024-04-10  9:24   ` stefan
2024-04-10  9:49     ` stefan
2024-04-10  9:54       ` Xi Ruoyao
2024-04-10  9:57       ` LIU Hao
2024-04-10 10:03         ` Xi Ruoyao
2024-04-10 11:52     ` David Brown
2024-04-10 14:25       ` Stefan Franke
2024-04-10 16:51         ` David Brown
2024-04-11  0:32         ` Oleg Endo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).