From 65b6faa0485253b284f7a63601dc7d0f5858515a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 6 Feb 2022 20:23:40 -0700 Subject: 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. --- src/stage1/codegen.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/stage1/codegen.cpp') diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp index ec1454ce4f..02f84beeab 100644 --- a/src/stage1/codegen.cpp +++ b/src/stage1/codegen.cpp @@ -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; -- cgit v1.2.3