optimizer discards sign information

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

 



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 






[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