From 266e84103ef92464e6f31dda91f3aa6587d8efea Mon Sep 17 00:00:00 2001 From: Barinzaya Date: Thu, 20 Feb 2025 17:05:07 -0500 Subject: [PATCH] Fixed an issue with SIMD vector equality. Comparing SIMD vectors with `==` was checking that the mask of elements that matched was not 0, meaning it succeeded if *any* element was equal, rather than if *all* elements were equal. --- src/llvm_backend_expr.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp index 693f2e225fd..9e115b9ca93 100644 --- a/src/llvm_backend_expr.cpp +++ b/src/llvm_backend_expr.cpp @@ -3004,7 +3004,16 @@ gb_internal lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left LLVMTypeRef mask_int_type = LLVMIntTypeInContext(p->module->ctx, cast(unsigned)(8*type_size_of(a))); LLVMValueRef mask_int = LLVMBuildBitCast(p->builder, mask, mask_int_type, ""); - res.value = LLVMBuildICmp(p->builder, LLVMIntNE, mask_int, LLVMConstNull(LLVMTypeOf(mask_int)), ""); + + switch (op_kind) { + case Token_CmpEq: + res.value = LLVMBuildICmp(p->builder, LLVMIntEQ, mask_int, LLVMConstInt(mask_int_type, U64_MAX, true), ""); + break; + case Token_NotEq: + res.value = LLVMBuildICmp(p->builder, LLVMIntNE, mask_int, LLVMConstNull(mask_int_type), ""); + break; + } + return res; } else {