Skip to content

Commit

Permalink
Fixed an issue with SIMD vector equality.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Barinzaya committed Feb 20, 2025
1 parent c25ac93 commit 266e841
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/llvm_backend_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 266e841

Please sign in to comment.