| ... | @@ -574,11 +574,13 @@ pub const Block = struct { | ... | @@ -574,11 +574,13 @@ pub const Block = struct { |
| 574 | }); | 574 | }); |
| 575 | } | 575 | } |
| 576 | | 576 | |
| 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 { |
| 578 | return block.addInst(.{ | 578 | return block.addInst(.{ |
| 579 | .tag = if (block.float_mode == .Optimized) .cmp_vector_optimized else .cmp_vector, | 579 | .tag = if (block.float_mode == .Optimized) .cmp_vector_optimized else .cmp_vector, |
| 580 | .data = .{ .ty_pl = .{ | 580 | .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 | ), |
| 582 | .payload = try block.sema.addExtra(Air.VectorCmp{ | 584 | .payload = try block.sema.addExtra(Air.VectorCmp{ |
| 583 | .lhs = lhs, | 585 | .lhs = lhs, |
| 584 | .rhs = rhs, | 586 | .rhs = rhs, |
| ... | @@ -9412,7 +9414,7 @@ fn intCast( | ... | @@ -9412,7 +9414,7 @@ fn intCast( |
| 9412 | const ok = if (is_vector) ok: { | 9414 | const ok = if (is_vector) ok: { |
| 9413 | const zeros = try Value.Tag.repeated.create(sema.arena, Value.zero); | 9415 | const zeros = try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 9414 | const zero_inst = try sema.addConstant(sema.typeOf(operand), zeros); | 9416 | 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); |
| 9416 | const all_in_range = try block.addInst(.{ | 9418 | const all_in_range = try block.addInst(.{ |
| 9417 | .tag = .reduce, | 9419 | .tag = .reduce, |
| 9418 | .data = .{ .reduce = .{ .operand = is_in_range, .operation = .And } }, | 9420 | .data = .{ .reduce = .{ .operand = is_in_range, .operation = .And } }, |
| ... | @@ -9466,7 +9468,7 @@ fn intCast( | ... | @@ -9466,7 +9468,7 @@ fn intCast( |
| 9466 | const dest_range = try sema.addConstant(unsigned_operand_ty, dest_range_val); | 9468 | const dest_range = try sema.addConstant(unsigned_operand_ty, dest_range_val); |
| 9467 | | 9469 | |
| 9468 | const ok = if (is_vector) ok: { | 9470 | 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); |
| 9470 | const all_in_range = try block.addInst(.{ | 9472 | const all_in_range = try block.addInst(.{ |
| 9471 | .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce, | 9473 | .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce, |
| 9472 | .data = .{ .reduce = .{ | 9474 | .data = .{ .reduce = .{ |
| ... | @@ -9483,7 +9485,7 @@ fn intCast( | ... | @@ -9483,7 +9485,7 @@ fn intCast( |
| 9483 | try sema.addSafetyCheck(block, ok, .cast_truncated_data); | 9485 | try sema.addSafetyCheck(block, ok, .cast_truncated_data); |
| 9484 | } else { | 9486 | } else { |
| 9485 | const ok = if (is_vector) ok: { | 9487 | 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); |
| 9487 | const all_in_range = try block.addInst(.{ | 9489 | const all_in_range = try block.addInst(.{ |
| 9488 | .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce, | 9490 | .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce, |
| 9489 | .data = .{ .reduce = .{ | 9491 | .data = .{ .reduce = .{ |
| ... | @@ -9504,7 +9506,7 @@ fn intCast( | ... | @@ -9504,7 +9506,7 @@ fn intCast( |
| 9504 | const ok = if (is_vector) ok: { | 9506 | const ok = if (is_vector) ok: { |
| 9505 | const zero_val = try Value.Tag.repeated.create(sema.arena, Value.zero); | 9507 | const zero_val = try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 9506 | const zero_inst = try sema.addConstant(operand_ty, zero_val); | 9508 | 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); |
| 9508 | const all_in_range = try block.addInst(.{ | 9510 | const all_in_range = try block.addInst(.{ |
| 9509 | .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce, | 9511 | .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce, |
| 9510 | .data = .{ .reduce = .{ | 9512 | .data = .{ .reduce = .{ |
| ... | @@ -12016,7 +12018,7 @@ fn zirShl( | ... | @@ -12016,7 +12018,7 @@ fn zirShl( |
| 12016 | | 12018 | |
| 12017 | const ok = if (rhs_ty.zigTypeTag() == .Vector) ok: { | 12019 | const ok = if (rhs_ty.zigTypeTag() == .Vector) ok: { |
| 12018 | const bit_count_inst = try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, bit_count_val)); | 12020 | 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); |
| 12020 | break :ok try block.addInst(.{ | 12022 | break :ok try block.addInst(.{ |
| 12021 | .tag = .reduce, | 12023 | .tag = .reduce, |
| 12022 | .data = .{ .reduce = .{ | 12024 | .data = .{ .reduce = .{ |
| ... | @@ -12172,7 +12174,7 @@ fn zirShr( | ... | @@ -12172,7 +12174,7 @@ fn zirShr( |
| 12172 | | 12174 | |
| 12173 | const ok = if (rhs_ty.zigTypeTag() == .Vector) ok: { | 12175 | const ok = if (rhs_ty.zigTypeTag() == .Vector) ok: { |
| 12174 | const bit_count_inst = try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, bit_count_val)); | 12176 | 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); |
| 12176 | break :ok try block.addInst(.{ | 12178 | break :ok try block.addInst(.{ |
| 12177 | .tag = .reduce, | 12179 | .tag = .reduce, |
| 12178 | .data = .{ .reduce = .{ | 12180 | .data = .{ .reduce = .{ |
| ... | @@ -12191,7 +12193,7 @@ fn zirShr( | ... | @@ -12191,7 +12193,7 @@ fn zirShr( |
| 12191 | const back = try block.addBinOp(.shl, result, rhs); | 12193 | const back = try block.addBinOp(.shl, result, rhs); |
| 12192 | | 12194 | |
| 12193 | const ok = if (rhs_ty.zigTypeTag() == .Vector) ok: { | 12195 | 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); |
| 12195 | break :ok try block.addInst(.{ | 12197 | break :ok try block.addInst(.{ |
| 12196 | .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce, | 12198 | .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce, |
| 12197 | .data = .{ .reduce = .{ | 12199 | .data = .{ .reduce = .{ |
| ... | @@ -13192,7 +13194,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13192,7 +13194,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13192 | const floored = try block.addUnOp(.floor, result); | 13194 | const floored = try block.addUnOp(.floor, result); |
| 13193 | | 13195 | |
| 13194 | if (resolved_type.zigTypeTag() == .Vector) { | 13196 | 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); |
| 13196 | break :ok try block.addInst(.{ | 13198 | break :ok try block.addInst(.{ |
| 13197 | .tag = switch (block.float_mode) { | 13199 | .tag = switch (block.float_mode) { |
| 13198 | .Strict => .reduce, | 13200 | .Strict => .reduce, |
| ... | @@ -13216,7 +13218,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13216,7 +13218,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13216 | if (resolved_type.zigTypeTag() == .Vector) { | 13218 | if (resolved_type.zigTypeTag() == .Vector) { |
| 13217 | const zero_val = try Value.Tag.repeated.create(sema.arena, Value.zero); | 13219 | const zero_val = try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 13218 | const zero = try sema.addConstant(resolved_type, zero_val); | 13220 | 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); |
| 13220 | break :ok try block.addInst(.{ | 13222 | break :ok try block.addInst(.{ |
| 13221 | .tag = .reduce, | 13223 | .tag = .reduce, |
| 13222 | .data = .{ .reduce = .{ | 13224 | .data = .{ .reduce = .{ |
| ... | @@ -13514,14 +13516,13 @@ fn addDivIntOverflowSafety( | ... | @@ -13514,14 +13516,13 @@ fn addDivIntOverflowSafety( |
| 13514 | | 13516 | |
| 13515 | var ok: Air.Inst.Ref = .none; | 13517 | var ok: Air.Inst.Ref = .none; |
| 13516 | if (resolved_type.zigTypeTag() == .Vector) { | 13518 | if (resolved_type.zigTypeTag() == .Vector) { |
| 13517 | const vector_ty_ref = try sema.addType(resolved_type); | | |
| 13518 | if (maybe_lhs_val == null) { | 13519 | if (maybe_lhs_val == null) { |
| 13519 | const min_int_ref = try sema.addConstant(resolved_type, min_int); | 13520 | 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); |
| 13521 | } | 13522 | } |
| 13522 | if (maybe_rhs_val == null) { | 13523 | if (maybe_rhs_val == null) { |
| 13523 | const neg_one_ref = try sema.addConstant(resolved_type, neg_one); | 13524 | 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); |
| 13525 | if (ok == .none) { | 13526 | if (ok == .none) { |
| 13526 | ok = rhs_ok; | 13527 | ok = rhs_ok; |
| 13527 | } else { | 13528 | } else { |
| ... | @@ -13573,7 +13574,7 @@ fn addDivByZeroSafety( | ... | @@ -13573,7 +13574,7 @@ fn addDivByZeroSafety( |
| 13573 | const ok = if (resolved_type.zigTypeTag() == .Vector) ok: { | 13574 | const ok = if (resolved_type.zigTypeTag() == .Vector) ok: { |
| 13574 | const zero_val = try Value.Tag.repeated.create(sema.arena, Value.zero); | 13575 | const zero_val = try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 13575 | const zero = try sema.addConstant(resolved_type, zero_val); | 13576 | 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); |
| 13577 | break :ok try block.addInst(.{ | 13578 | break :ok try block.addInst(.{ |
| 13578 | .tag = if (is_int) .reduce else .reduce_optimized, | 13579 | .tag = if (is_int) .reduce else .reduce_optimized, |
| 13579 | .data = .{ .reduce = .{ | 13580 | .data = .{ .reduce = .{ |
| ... | @@ -15202,9 +15203,7 @@ fn cmpSelf( | ... | @@ -15202,9 +15203,7 @@ fn cmpSelf( |
| 15202 | }; | 15203 | }; |
| 15203 | try sema.requireRuntimeBlock(block, src, runtime_src); | 15204 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 15204 | if (resolved_type.zigTypeTag() == .Vector) { | 15205 | if (resolved_type.zigTypeTag() == .Vector) { |
| 15205 | const result_ty = try Type.vector(sema.arena, resolved_type.vectorLen(), Type.bool); | 15206 | return block.addCmpVector(casted_lhs, casted_rhs, op); |
| 15206 | const result_ty_ref = try sema.addType(result_ty); | | |
| 15207 | return block.addCmpVector(casted_lhs, casted_rhs, op, result_ty_ref); | | |
| 15208 | } | 15207 | } |
| 15209 | const tag = Air.Inst.Tag.fromCmpOp(op, block.float_mode == .Optimized); | 15208 | const tag = Air.Inst.Tag.fromCmpOp(op, block.float_mode == .Optimized); |
| 15210 | return block.addBinOp(tag, casted_lhs, casted_rhs); | 15209 | return block.addBinOp(tag, casted_lhs, casted_rhs); |
| ... | @@ -23035,7 +23034,7 @@ fn panicSentinelMismatch( | ... | @@ -23035,7 +23034,7 @@ fn panicSentinelMismatch( |
| 23035 | | 23034 | |
| 23036 | const ok = if (sentinel_ty.zigTypeTag() == .Vector) ok: { | 23035 | const ok = if (sentinel_ty.zigTypeTag() == .Vector) ok: { |
| 23037 | const eql = | 23036 | 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); |
| 23039 | break :ok try parent_block.addInst(.{ | 23038 | break :ok try parent_block.addInst(.{ |
| 23040 | .tag = .reduce, | 23039 | .tag = .reduce, |
| 23041 | .data = .{ .reduce = .{ | 23040 | .data = .{ .reduce = .{ |
| ... | @@ -29368,8 +29367,7 @@ fn cmpVector( | ... | @@ -29368,8 +29367,7 @@ fn cmpVector( |
| 29368 | }; | 29367 | }; |
| 29369 | | 29368 | |
| 29370 | try sema.requireRuntimeBlock(block, src, runtime_src); | 29369 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 29371 | const result_ty_inst = try sema.addType(result_ty); | 29370 | return block.addCmpVector(lhs, rhs, op); |
| 29372 | return block.addCmpVector(lhs, rhs, op, result_ty_inst); | | |
| 29373 | } | 29371 | } |
| 29374 | | 29372 | |
| 29375 | fn wrapOptional( | 29373 | fn wrapOptional( |