authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-03-04 19:02:42-05:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-03-05 02:59:02-05:00
logb2e9c0d0ff1dc6799fe3b5fdbecd53af176f37b7
treec0dfe9b7af93db50ce4ef23d5bb0d096b31df5ba
parent9e3a5ecd39227aff3b2821d0c0b489eb9713b146

Sema: fix cmp_vector type


1 files changed, 19 insertions(+), 21 deletions(-)

src/Sema.zig+19-21
......@@ -574,11 +574,13 @@ pub const Block = struct {
574574 });
575575 }
576576
577 fn addCmpVector(block: *Block, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref, cmp_op: std.math.CompareOperator, vector_ty: Air.Inst.Ref) !Air.Inst.Ref {
577 fn addCmpVector(block: *Block, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref, cmp_op: std.math.CompareOperator) !Air.Inst.Ref {
578578 return block.addInst(.{
579579 .tag = if (block.float_mode == .Optimized) .cmp_vector_optimized else .cmp_vector,
580580 .data = .{ .ty_pl = .{
581 .ty = vector_ty,
581 .ty = try block.sema.addType(
582 try Type.vector(block.sema.arena, block.sema.typeOf(lhs).vectorLen(), Type.bool),
583 ),
582584 .payload = try block.sema.addExtra(Air.VectorCmp{
583585 .lhs = lhs,
584586 .rhs = rhs,
......@@ -9412,7 +9414,7 @@ fn intCast(
94129414 const ok = if (is_vector) ok: {
94139415 const zeros = try Value.Tag.repeated.create(sema.arena, Value.zero);
94149416 const zero_inst = try sema.addConstant(sema.typeOf(operand), zeros);
9415 const is_in_range = try block.addCmpVector(operand, zero_inst, .eq, try sema.addType(operand_ty));
9417 const is_in_range = try block.addCmpVector(operand, zero_inst, .eq);
94169418 const all_in_range = try block.addInst(.{
94179419 .tag = .reduce,
94189420 .data = .{ .reduce = .{ .operand = is_in_range, .operation = .And } },
......@@ -9466,7 +9468,7 @@ fn intCast(
94669468 const dest_range = try sema.addConstant(unsigned_operand_ty, dest_range_val);
94679469
94689470 const ok = if (is_vector) ok: {
9469 const is_in_range = try block.addCmpVector(diff_unsigned, dest_range, .lte, try sema.addType(operand_ty));
9471 const is_in_range = try block.addCmpVector(diff_unsigned, dest_range, .lte);
94709472 const all_in_range = try block.addInst(.{
94719473 .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce,
94729474 .data = .{ .reduce = .{
......@@ -9483,7 +9485,7 @@ fn intCast(
94839485 try sema.addSafetyCheck(block, ok, .cast_truncated_data);
94849486 } else {
94859487 const ok = if (is_vector) ok: {
9486 const is_in_range = try block.addCmpVector(diff, dest_max, .lte, try sema.addType(operand_ty));
9488 const is_in_range = try block.addCmpVector(diff, dest_max, .lte);
94879489 const all_in_range = try block.addInst(.{
94889490 .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce,
94899491 .data = .{ .reduce = .{
......@@ -9504,7 +9506,7 @@ fn intCast(
95049506 const ok = if (is_vector) ok: {
95059507 const zero_val = try Value.Tag.repeated.create(sema.arena, Value.zero);
95069508 const zero_inst = try sema.addConstant(operand_ty, zero_val);
9507 const is_in_range = try block.addCmpVector(operand, zero_inst, .gte, try sema.addType(operand_ty));
9509 const is_in_range = try block.addCmpVector(operand, zero_inst, .gte);
95089510 const all_in_range = try block.addInst(.{
95099511 .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce,
95109512 .data = .{ .reduce = .{
......@@ -12016,7 +12018,7 @@ fn zirShl(
1201612018
1201712019 const ok = if (rhs_ty.zigTypeTag() == .Vector) ok: {
1201812020 const bit_count_inst = try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, bit_count_val));
12019 const lt = try block.addCmpVector(rhs, bit_count_inst, .lt, try sema.addType(rhs_ty));
12021 const lt = try block.addCmpVector(rhs, bit_count_inst, .lt);
1202012022 break :ok try block.addInst(.{
1202112023 .tag = .reduce,
1202212024 .data = .{ .reduce = .{
......@@ -12172,7 +12174,7 @@ fn zirShr(
1217212174
1217312175 const ok = if (rhs_ty.zigTypeTag() == .Vector) ok: {
1217412176 const bit_count_inst = try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, bit_count_val));
12175 const lt = try block.addCmpVector(rhs, bit_count_inst, .lt, try sema.addType(rhs_ty));
12177 const lt = try block.addCmpVector(rhs, bit_count_inst, .lt);
1217612178 break :ok try block.addInst(.{
1217712179 .tag = .reduce,
1217812180 .data = .{ .reduce = .{
......@@ -12191,7 +12193,7 @@ fn zirShr(
1219112193 const back = try block.addBinOp(.shl, result, rhs);
1219212194
1219312195 const ok = if (rhs_ty.zigTypeTag() == .Vector) ok: {
12194 const eql = try block.addCmpVector(lhs, back, .eq, try sema.addType(rhs_ty));
12196 const eql = try block.addCmpVector(lhs, back, .eq);
1219512197 break :ok try block.addInst(.{
1219612198 .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce,
1219712199 .data = .{ .reduce = .{
......@@ -13192,7 +13194,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1319213194 const floored = try block.addUnOp(.floor, result);
1319313195
1319413196 if (resolved_type.zigTypeTag() == .Vector) {
13195 const eql = try block.addCmpVector(result, floored, .eq, try sema.addType(resolved_type));
13197 const eql = try block.addCmpVector(result, floored, .eq);
1319613198 break :ok try block.addInst(.{
1319713199 .tag = switch (block.float_mode) {
1319813200 .Strict => .reduce,
......@@ -13216,7 +13218,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1321613218 if (resolved_type.zigTypeTag() == .Vector) {
1321713219 const zero_val = try Value.Tag.repeated.create(sema.arena, Value.zero);
1321813220 const zero = try sema.addConstant(resolved_type, zero_val);
13219 const eql = try block.addCmpVector(remainder, zero, .eq, try sema.addType(resolved_type));
13221 const eql = try block.addCmpVector(remainder, zero, .eq);
1322013222 break :ok try block.addInst(.{
1322113223 .tag = .reduce,
1322213224 .data = .{ .reduce = .{
......@@ -13514,14 +13516,13 @@ fn addDivIntOverflowSafety(
1351413516
1351513517 var ok: Air.Inst.Ref = .none;
1351613518 if (resolved_type.zigTypeTag() == .Vector) {
13517 const vector_ty_ref = try sema.addType(resolved_type);
1351813519 if (maybe_lhs_val == null) {
1351913520 const min_int_ref = try sema.addConstant(resolved_type, min_int);
13520 ok = try block.addCmpVector(casted_lhs, min_int_ref, .neq, vector_ty_ref);
13521 ok = try block.addCmpVector(casted_lhs, min_int_ref, .neq);
1352113522 }
1352213523 if (maybe_rhs_val == null) {
1352313524 const neg_one_ref = try sema.addConstant(resolved_type, neg_one);
13524 const rhs_ok = try block.addCmpVector(casted_rhs, neg_one_ref, .neq, vector_ty_ref);
13525 const rhs_ok = try block.addCmpVector(casted_rhs, neg_one_ref, .neq);
1352513526 if (ok == .none) {
1352613527 ok = rhs_ok;
1352713528 } else {
......@@ -13573,7 +13574,7 @@ fn addDivByZeroSafety(
1357313574 const ok = if (resolved_type.zigTypeTag() == .Vector) ok: {
1357413575 const zero_val = try Value.Tag.repeated.create(sema.arena, Value.zero);
1357513576 const zero = try sema.addConstant(resolved_type, zero_val);
13576 const ok = try block.addCmpVector(casted_rhs, zero, .neq, try sema.addType(resolved_type));
13577 const ok = try block.addCmpVector(casted_rhs, zero, .neq);
1357713578 break :ok try block.addInst(.{
1357813579 .tag = if (is_int) .reduce else .reduce_optimized,
1357913580 .data = .{ .reduce = .{
......@@ -15202,9 +15203,7 @@ fn cmpSelf(
1520215203 };
1520315204 try sema.requireRuntimeBlock(block, src, runtime_src);
1520415205 if (resolved_type.zigTypeTag() == .Vector) {
15205 const result_ty = try Type.vector(sema.arena, resolved_type.vectorLen(), Type.bool);
15206 const result_ty_ref = try sema.addType(result_ty);
15207 return block.addCmpVector(casted_lhs, casted_rhs, op, result_ty_ref);
15206 return block.addCmpVector(casted_lhs, casted_rhs, op);
1520815207 }
1520915208 const tag = Air.Inst.Tag.fromCmpOp(op, block.float_mode == .Optimized);
1521015209 return block.addBinOp(tag, casted_lhs, casted_rhs);
......@@ -23035,7 +23034,7 @@ fn panicSentinelMismatch(
2303523034
2303623035 const ok = if (sentinel_ty.zigTypeTag() == .Vector) ok: {
2303723036 const eql =
23038 try parent_block.addCmpVector(expected_sentinel, actual_sentinel, .eq, try sema.addType(sentinel_ty));
23037 try parent_block.addCmpVector(expected_sentinel, actual_sentinel, .eq);
2303923038 break :ok try parent_block.addInst(.{
2304023039 .tag = .reduce,
2304123040 .data = .{ .reduce = .{
......@@ -29368,8 +29367,7 @@ fn cmpVector(
2936829367 };
2936929368
2937029369 try sema.requireRuntimeBlock(block, src, runtime_src);
29371 const result_ty_inst = try sema.addType(result_ty);
29372 return block.addCmpVector(lhs, rhs, op, result_ty_inst);
29370 return block.addCmpVector(lhs, rhs, op);
2937329371}
2937429372
2937529373fn wrapOptional(