| Issue |
234116
|
| Summary |
[X86] [CodeGen] i32/i64/i128 to bfloat have double-rounds issue
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
minxuanz
|
```
// i32 -> bf16
int main(void)
{
volatile int a = 16842753; /* 2^24 + 2^16 + 1 */
__bf16 b = (__bf16)a;
/* Correct result: 2^24 + 2^17 = 16908288 */
printf("%.0f\n", (double)b);
return 0;
}
```
gcc is 16908288 ,clang is 16777216
gcc
```
push rbp
mov rbp, rsp
cvtsi2ss xmm0, edi
call __truncsfbf2@PLT
pop rbp
ret
```
clang
```
sub rsp, 8
pxor xmm0, xmm0
cvtsi2sd xmm0, edi
call "__truncdfbf2"
add rsp, 8
ret
```
i64 and i128 require special handle,but i32 can convert to f64 first. i32->f64->bf16
https://godbolt.org/z/b3GaTe3Yv
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs