diff --git a/releasenotes.md b/releasenotes.md index 33070e2b9..809838f77 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -53,6 +53,7 @@ - $vasplat was allowed inside of a function when passed as an argument to a function. - Prohibit raw vaargs in regular functions with a function body. - Assert on certain slice to slice casts. #1768. +- Fix vector float -> bool conversion. ### Stdlib changes - Increase BitWriter.write_bits limit up to 32 bits. diff --git a/src/compiler/enums.h b/src/compiler/enums.h index 9b3c60f6a..2385d3559 100644 --- a/src/compiler/enums.h +++ b/src/compiler/enums.h @@ -551,7 +551,6 @@ typedef enum CAST_ERPTR, CAST_ERROR, CAST_EUER, - CAST_FPBOOL, CAST_FPFP, CAST_FPINT, CAST_INTBOOL, diff --git a/src/compiler/expr.c b/src/compiler/expr.c index 54a25b62b..f1e8df700 100644 --- a/src/compiler/expr.c +++ b/src/compiler/expr.c @@ -360,7 +360,6 @@ static inline bool expr_cast_is_runtime_const(Expr *expr) case CAST_PTRBOOL: case CAST_BOOLFP: case CAST_BOOLBOOL: - case CAST_FPBOOL: case CAST_INTBOOL: case CAST_FPFP: case CAST_FPINT: diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index 38c9c107f..ff1d95e86 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -1471,11 +1471,6 @@ void llvm_emit_cast(GenContext *c, CastKind cast_kind, Expr *expr, BEValue *valu value->value = LLVMBuildIsNotNull(c->builder, value->value, "ptrbool"); value->kind = BE_BOOLEAN; break; - case CAST_FPBOOL: - llvm_value_rvalue(c, value); - value->value = LLVMBuildFCmp(c->builder, LLVMRealUNE, value->value, llvm_get_zero(c, from_type), "fpbool"); - value->kind = BE_BOOLEAN; - break; case CAST_BOOLBOOL: value->value = LLVMBuildTrunc(c->builder, value->value, c->bool_type, "boolbool"); value->kind = BE_BOOLEAN; diff --git a/src/compiler/sema_casts.c b/src/compiler/sema_casts.c index 8f10f06db..dc06696d6 100644 --- a/src/compiler/sema_casts.c +++ b/src/compiler/sema_casts.c @@ -1717,8 +1717,14 @@ static void cast_vec_to_vec(SemaContext *context, Expr *expr, Type *to_type) insert_runtime_cast(expr, CAST_FPFP, to_type); return; case TYPE_BOOL: - insert_runtime_cast(expr, CAST_FPBOOL, to_type); + { + Expr *left = expr_copy(expr); + Expr *right = expr_new_expr(EXPR_CONST, expr); + expr_rewrite_to_const_zero(right, left->type); + expr_rewrite_to_binary(expr, left, right, BINARYOP_VEC_NE); + expr->type = to_type; return; + } case ALL_INTS: insert_runtime_cast(expr, CAST_FPINT, to_type); return; diff --git a/test/unit/regression/vector_ops.c3 b/test/unit/regression/vector_ops.c3 index 4e0b6f979..84b4f2574 100644 --- a/test/unit/regression/vector_ops.c3 +++ b/test/unit/regression/vector_ops.c3 @@ -37,6 +37,8 @@ fn void! test_conv() @test fn void! testf() @test { + float[<4>] x = { 4, 0, -1, 33 }; + assert({ true, false, true, true} == (bool[<4>])x); float[<4>] y = { 1, 2, 3, 4 }; float[<4>] z = { 2, 2, 2, -100 }; float[<4>] w = y + z;