[clang] [clang] fix half && bfloat16 convert node expr codegen (PR #89051)

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 5 23:13:41 PDT 2024


JinjinLi868 wrote:

i add the gcc behavior in this case 
```
__bf16 test_convert_from_fp16_to_bf16(_Float16 a) {
    return (__bf16)a;
}
test_convert_from_fp16_to_bf16(_Float16):
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        movd    eax, xmm0
        mov     WORD PTR [rbp-2], ax
        pinsrw  xmm0, WORD PTR [rbp-2], 0
        call    __trunchfbf2
        movd    eax, xmm0
        movd    xmm0, eax
        leave
        ret
```
```
_Float16 test_convert_from_bf16_to_fp16(__bf16 a) {
    return (_Float16)a;
}
test_convert_from_bf16_to_fp16(std::bfloat16_t):
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        movd    eax, xmm0
        mov     WORD PTR [rbp-2], ax
        movzx   eax, WORD PTR [rbp-2]
        sal     eax, 16
        movd    xmm0, eax
        call    __truncsfhf2
        movd    eax, xmm0
        movd    xmm0, eax
        leave
        ret
```

https://github.com/llvm/llvm-project/pull/89051


More information about the cfe-commits mailing list