Skip to content

Commit cbbcf60

Browse files
committed
stage1: Allow comparison with comptime-known vectors
Since comptime_{int,float} vectors are not allowed (thanks $DEITY) we can use the element type infos to determine the minimum operand size.
1 parent 56b52dd commit cbbcf60

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/ir.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16715,16 +16715,12 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
1671516715
}
1671616716
ZigType *dest_float_type = nullptr;
1671716717
uint32_t op1_bits;
16718-
if (instr_is_comptime(op1)) {
16718+
if (instr_is_comptime(op1) && result_type->id != ZigTypeIdVector) {
1671916719
ZigValue *op1_val = ir_resolve_const(ira, op1, UndefOk);
1672016720
if (op1_val == nullptr)
1672116721
return ira->codegen->invalid_inst_gen;
1672216722
if (op1_val->special == ConstValSpecialUndef)
1672316723
return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
16724-
if (result_type->id == ZigTypeIdVector) {
16725-
ir_add_error(ira, &op1->base, buf_sprintf("compiler bug: TODO: support comptime vector here"));
16726-
return ira->codegen->invalid_inst_gen;
16727-
}
1672816724
bool is_unsigned;
1672916725
if (op1_is_float) {
1673016726
BigInt bigint = {};
@@ -16750,6 +16746,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
1675016746
op1_bits += 1;
1675116747
}
1675216748
} else if (op1_is_float) {
16749+
ir_assert(op1_scalar_type->id == ZigTypeIdFloat, source_instr);
1675316750
dest_float_type = op1_scalar_type;
1675416751
} else {
1675516752
ir_assert(op1_scalar_type->id == ZigTypeIdInt, source_instr);
@@ -16759,16 +16756,12 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
1675916756
}
1676016757
}
1676116758
uint32_t op2_bits;
16762-
if (instr_is_comptime(op2)) {
16759+
if (instr_is_comptime(op2) && result_type->id != ZigTypeIdVector) {
1676316760
ZigValue *op2_val = ir_resolve_const(ira, op2, UndefOk);
1676416761
if (op2_val == nullptr)
1676516762
return ira->codegen->invalid_inst_gen;
1676616763
if (op2_val->special == ConstValSpecialUndef)
1676716764
return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
16768-
if (result_type->id == ZigTypeIdVector) {
16769-
ir_add_error(ira, &op2->base, buf_sprintf("compiler bug: TODO: support comptime vector here"));
16770-
return ira->codegen->invalid_inst_gen;
16771-
}
1677216765
bool is_unsigned;
1677316766
if (op2_is_float) {
1677416767
BigInt bigint = {};
@@ -16794,6 +16787,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
1679416787
op2_bits += 1;
1679516788
}
1679616789
} else if (op2_is_float) {
16790+
ir_assert(op2_scalar_type->id == ZigTypeIdFloat, source_instr);
1679716791
dest_float_type = op2_scalar_type;
1679816792
} else {
1679916793
ir_assert(op2_scalar_type->id == ZigTypeIdInt, source_instr);

test/stage1/behavior/vector.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@ test "vector comparison operators" {
274274
expectEqual(@splat(4, true), v1 != v3);
275275
expectEqual(@splat(4, false), v1 != v2);
276276
}
277+
{
278+
// Comptime-known LHS/RHS
279+
var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 };
280+
const v2 = @splat(4, @as(u32, 2));
281+
const v3: @Vector(4, bool) = [_]bool{ true, false, true, false };
282+
expectEqual(v3, v1 == v2);
283+
expectEqual(v3, v2 == v1);
284+
}
277285
}
278286
};
279287
S.doTheTest();

0 commit comments

Comments
 (0)