authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-09-28 17:16:57+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-09-28 17:16:57+02:00
logcbbcf609688d70ce9e45bde444b2904b39a0ae2c
tree2d691a3896b897a88c99335f1babb5501f04d7eb
parent56b52dd0a357f87627fe96dc99377a397f3bb9a1

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.

2 files changed, 12 insertions(+), 10 deletions(-)

src/ir.cpp+4-10
...@@ -16715,16 +16715,12 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -16715,16 +16715,12 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
16715 }16715 }
16716 ZigType *dest_float_type = nullptr;16716 ZigType *dest_float_type = nullptr;
16717 uint32_t op1_bits;16717 uint32_t op1_bits;
16718 if (instr_is_comptime(op1)) {16718 if (instr_is_comptime(op1) && result_type->id != ZigTypeIdVector) {
16719 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefOk);16719 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefOk);
16720 if (op1_val == nullptr)16720 if (op1_val == nullptr)
16721 return ira->codegen->invalid_inst_gen;16721 return ira->codegen->invalid_inst_gen;
16722 if (op1_val->special == ConstValSpecialUndef)16722 if (op1_val->special == ConstValSpecialUndef)
16723 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);16723 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 }
16728 bool is_unsigned;16724 bool is_unsigned;
16729 if (op1_is_float) {16725 if (op1_is_float) {
16730 BigInt bigint = {};16726 BigInt bigint = {};
...@@ -16750,6 +16746,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -16750,6 +16746,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
16750 op1_bits += 1;16746 op1_bits += 1;
16751 }16747 }
16752 } else if (op1_is_float) {16748 } else if (op1_is_float) {
16749 ir_assert(op1_scalar_type->id == ZigTypeIdFloat, source_instr);
16753 dest_float_type = op1_scalar_type;16750 dest_float_type = op1_scalar_type;
16754 } else {16751 } else {
16755 ir_assert(op1_scalar_type->id == ZigTypeIdInt, source_instr);16752 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...@@ -16759,16 +16756,12 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
16759 }16756 }
16760 }16757 }
16761 uint32_t op2_bits;16758 uint32_t op2_bits;
16762 if (instr_is_comptime(op2)) {16759 if (instr_is_comptime(op2) && result_type->id != ZigTypeIdVector) {
16763 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefOk);16760 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefOk);
16764 if (op2_val == nullptr)16761 if (op2_val == nullptr)
16765 return ira->codegen->invalid_inst_gen;16762 return ira->codegen->invalid_inst_gen;
16766 if (op2_val->special == ConstValSpecialUndef)16763 if (op2_val->special == ConstValSpecialUndef)
16767 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);16764 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 }
16772 bool is_unsigned;16765 bool is_unsigned;
16773 if (op2_is_float) {16766 if (op2_is_float) {
16774 BigInt bigint = {};16767 BigInt bigint = {};
...@@ -16794,6 +16787,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -16794,6 +16787,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
16794 op2_bits += 1;16787 op2_bits += 1;
16795 }16788 }
16796 } else if (op2_is_float) {16789 } else if (op2_is_float) {
16790 ir_assert(op2_scalar_type->id == ZigTypeIdFloat, source_instr);
16797 dest_float_type = op2_scalar_type;16791 dest_float_type = op2_scalar_type;
16798 } else {16792 } else {
16799 ir_assert(op2_scalar_type->id == ZigTypeIdInt, source_instr);16793 ir_assert(op2_scalar_type->id == ZigTypeIdInt, source_instr);
test/stage1/behavior/vector.zig+8
...@@ -274,6 +274,14 @@ test "vector comparison operators" {...@@ -274,6 +274,14 @@ test "vector comparison operators" {
274 expectEqual(@splat(4, true), v1 != v3);274 expectEqual(@splat(4, true), v1 != v3);
275 expectEqual(@splat(4, false), v1 != v2);275 expectEqual(@splat(4, false), v1 != v2);
276 }276 }
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 }
277 }285 }
278 };286 };
279 S.doTheTest();287 S.doTheTest();