Sema: avoid @intToFloat for f80 which breaks on non-x86 targets

Currently Zig lowers `@intToFloat` for f80 incorrectly on non-x86
targets:

```
broken LLVM module found:
UIToFP result must be FP or FP vector
  %62 = uitofp i64 %61 to i128
SIToFP result must be FP or FP vector
  %66 = sitofp i64 %65 to i128
```

This happens because on such targets, we use i128 instead of x86_fp80 in
order to avoid "LLVM ERROR: Cannot select". `@intToFloat` must be
lowered differently to account for this difference as well.
This commit is contained in:
Andrew Kelley
2022-02-06 20:23:40 -07:00
parent 3bcce5f6d1
commit 65b6faa048
2 changed files with 22 additions and 7 deletions

View File

@@ -9432,11 +9432,14 @@ static void define_builtin_types(CodeGen *g) {
if (target_has_f80(g->zig_target)) {
entry->llvm_type = LLVMX86FP80Type();
} else {
// We use i128 here instead of x86_fp80 because on targets such as arm,
// LLVM will give "ERROR: Cannot select" for any instructions involving
// the x86_fp80 type.
entry->llvm_type = get_int_type(g, false, 128)->llvm_type;
}
entry->size_in_bits = 8 * 16;
entry->abi_size = 16;
entry->abi_align = 16;
entry->abi_size = 16; // matches LLVMABISizeOfType(LLVMX86FP80Type())
entry->abi_align = 16; // matches LLVMABIAlignmentOfType(LLVMX86FP80Type())
buf_init_from_str(&entry->name, "f80");
entry->data.floating.bit_count = 80;