authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-04-17 18:42:54+02:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-04-20 20:49:34+01:00
loge0886506531d662067ae42ade9f099ff9c940f58
treeb0a4939d1bc78391d1e72915cabd6935cfb146c7
parent6fc524de4267fce0d381215bfda9c2caca9a4f07
signature Commit is signed but in an unrecognized format.

wasm: integrate new Liveness behaviour

Uses the new liveness behaviour. This also removes useless calls to `processDeath` on branches that were just initialized. Branch consolidation and processing deaths on branches inside `condbr` is still a TODO, just like before. This also skips var_args on other native backends as they do not support this feature yet.

2 files changed, 15 insertions(+), 82 deletions(-)

src/arch/wasm/CodeGen.zig+11-82
...@@ -2009,9 +2009,11 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2009,9 +2009,11 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
20092009
2010fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {2010fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2011 for (body) |inst| {2011 for (body) |inst| {
2012 if (func.liveness.isUnused(inst) and !func.air.mustLower(inst)) {
2013 continue;
2014 }
2012 const old_bookkeeping_value = func.air_bookkeeping;2015 const old_bookkeeping_value = func.air_bookkeeping;
2013 // TODO: Determine why we need to pre-allocate an extra 4 possible values here.2016 try func.currentBranch().values.ensureUnusedCapacity(func.gpa, Liveness.bpi);
2014 try func.currentBranch().values.ensureUnusedCapacity(func.gpa, Liveness.bpi + 4);
2015 try func.genInst(inst);2017 try func.genInst(inst);
20162018
2017 if (builtin.mode == .Debug and func.air_bookkeeping < old_bookkeeping_value + 1) {2019 if (builtin.mode == .Debug and func.air_bookkeeping < old_bookkeeping_value + 1) {
...@@ -2185,7 +2187,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -2185,7 +2187,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
2185 }2187 }
21862188
2187 const result_value = result_value: {2189 const result_value = result_value: {
2188 if (func.liveness.isUnused(inst) or (!ret_ty.hasRuntimeBitsIgnoreComptime() and !ret_ty.isError())) {2190 if (!ret_ty.hasRuntimeBitsIgnoreComptime() and !ret_ty.isError()) {
2189 break :result_value WValue{ .none = {} };2191 break :result_value WValue{ .none = {} };
2190 } else if (ret_ty.isNoReturn()) {2192 } else if (ret_ty.isNoReturn()) {
2191 try func.addTag(.@"unreachable");2193 try func.addTag(.@"unreachable");
...@@ -2494,7 +2496,6 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2494,7 +2496,6 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
24942496
2495fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {2497fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
2496 const bin_op = func.air.instructions.items(.data)[inst].bin_op;2498 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
2497 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
2498 const lhs = try func.resolveInst(bin_op.lhs);2499 const lhs = try func.resolveInst(bin_op.lhs);
2499 const rhs = try func.resolveInst(bin_op.rhs);2500 const rhs = try func.resolveInst(bin_op.rhs);
2500 const ty = func.air.typeOf(bin_op.lhs);2501 const ty = func.air.typeOf(bin_op.lhs);
...@@ -2649,7 +2650,6 @@ const FloatOp = enum {...@@ -2649,7 +2650,6 @@ const FloatOp = enum {
26492650
2650fn airUnaryFloatOp(func: *CodeGen, inst: Air.Inst.Index, op: FloatOp) InnerError!void {2651fn airUnaryFloatOp(func: *CodeGen, inst: Air.Inst.Index, op: FloatOp) InnerError!void {
2651 const un_op = func.air.instructions.items(.data)[inst].un_op;2652 const un_op = func.air.instructions.items(.data)[inst].un_op;
2652 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{un_op});
2653 const operand = try func.resolveInst(un_op);2653 const operand = try func.resolveInst(un_op);
2654 const ty = func.air.typeOf(un_op);2654 const ty = func.air.typeOf(un_op);
26552655
...@@ -2723,7 +2723,6 @@ fn floatOp(func: *CodeGen, float_op: FloatOp, ty: Type, args: []const WValue) In...@@ -2723,7 +2723,6 @@ fn floatOp(func: *CodeGen, float_op: FloatOp, ty: Type, args: []const WValue) In
27232723
2724fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {2724fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
2725 const bin_op = func.air.instructions.items(.data)[inst].bin_op;2725 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
2726 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
27272726
2728 const lhs = try func.resolveInst(bin_op.lhs);2727 const lhs = try func.resolveInst(bin_op.lhs);
2729 const rhs = try func.resolveInst(bin_op.rhs);2728 const rhs = try func.resolveInst(bin_op.rhs);
...@@ -3218,9 +3217,6 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3218,9 +3217,6 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
32183217
3219 func.branches.appendAssumeCapacity(.{});3218 func.branches.appendAssumeCapacity(.{});
3220 try func.currentBranch().values.ensureUnusedCapacity(func.gpa, @intCast(u32, liveness_condbr.else_deaths.len));3219 try func.currentBranch().values.ensureUnusedCapacity(func.gpa, @intCast(u32, liveness_condbr.else_deaths.len));
3221 for (liveness_condbr.else_deaths) |death| {
3222 func.processDeath(Air.indexToRef(death));
3223 }
3224 try func.genBody(else_body);3220 try func.genBody(else_body);
3225 try func.endBlock();3221 try func.endBlock();
3226 var else_stack = func.branches.pop();3222 var else_stack = func.branches.pop();
...@@ -3229,9 +3225,6 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3229,9 +3225,6 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3229 // Outer block that matches the condition3225 // Outer block that matches the condition
3230 func.branches.appendAssumeCapacity(.{});3226 func.branches.appendAssumeCapacity(.{});
3231 try func.currentBranch().values.ensureUnusedCapacity(func.gpa, @intCast(u32, liveness_condbr.then_deaths.len));3227 try func.currentBranch().values.ensureUnusedCapacity(func.gpa, @intCast(u32, liveness_condbr.then_deaths.len));
3232 for (liveness_condbr.then_deaths) |death| {
3233 func.processDeath(Air.indexToRef(death));
3234 }
3235 try func.genBody(then_body);3228 try func.genBody(then_body);
3236 var then_stack = func.branches.pop();3229 var then_stack = func.branches.pop();
3237 defer then_stack.deinit(func.gpa);3230 defer then_stack.deinit(func.gpa);
...@@ -3249,7 +3242,7 @@ fn mergeBranch(func: *CodeGen, branch: *const Branch) !void {...@@ -3249,7 +3242,7 @@ fn mergeBranch(func: *CodeGen, branch: *const Branch) !void {
3249 const target_keys = target_slice.items(.key);3242 const target_keys = target_slice.items(.key);
3250 const target_values = target_slice.items(.value);3243 const target_values = target_slice.items(.value);
32513244
3252 try parent.values.ensureUnusedCapacity(func.gpa, branch.values.count());3245 try parent.values.ensureTotalCapacity(func.gpa, parent.values.capacity() + branch.values.count());
3253 for (target_keys, 0..) |key, index| {3246 for (target_keys, 0..) |key, index| {
3254 // TODO: process deaths from branches3247 // TODO: process deaths from branches
3255 parent.values.putAssumeCapacity(key, target_values[index]);3248 parent.values.putAssumeCapacity(key, target_values[index]);
...@@ -3258,7 +3251,6 @@ fn mergeBranch(func: *CodeGen, branch: *const Branch) !void {...@@ -3258,7 +3251,6 @@ fn mergeBranch(func: *CodeGen, branch: *const Branch) !void {
32583251
3259fn airCmp(func: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) InnerError!void {3252fn airCmp(func: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) InnerError!void {
3260 const bin_op = func.air.instructions.items(.data)[inst].bin_op;3253 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
3261 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
32623254
3263 const lhs = try func.resolveInst(bin_op.lhs);3255 const lhs = try func.resolveInst(bin_op.lhs);
3264 const rhs = try func.resolveInst(bin_op.rhs);3256 const rhs = try func.resolveInst(bin_op.rhs);
...@@ -3375,7 +3367,6 @@ fn airBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3375,7 +3367,6 @@ fn airBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
33753367
3376fn airNot(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3368fn airNot(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3377 const ty_op = func.air.instructions.items(.data)[inst].ty_op;3369 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
3378 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
33793370
3380 const operand = try func.resolveInst(ty_op.operand);3371 const operand = try func.resolveInst(ty_op.operand);
3381 const operand_ty = func.air.typeOf(ty_op.operand);3372 const operand_ty = func.air.typeOf(ty_op.operand);
...@@ -3441,7 +3432,7 @@ fn airUnreachable(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3441,7 +3432,7 @@ fn airUnreachable(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
34413432
3442fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3433fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3443 const ty_op = func.air.instructions.items(.data)[inst].ty_op;3434 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
3444 const result = if (!func.liveness.isUnused(inst)) result: {3435 const result = result: {
3445 const operand = try func.resolveInst(ty_op.operand);3436 const operand = try func.resolveInst(ty_op.operand);
3446 const wanted_ty = func.air.typeOfIndex(inst);3437 const wanted_ty = func.air.typeOfIndex(inst);
3447 const given_ty = func.air.typeOf(ty_op.operand);3438 const given_ty = func.air.typeOf(ty_op.operand);
...@@ -3450,7 +3441,7 @@ fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3450,7 +3441,7 @@ fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3450 break :result try bitcast_result.toLocal(func, wanted_ty);3441 break :result try bitcast_result.toLocal(func, wanted_ty);
3451 }3442 }
3452 break :result func.reuseOperand(ty_op.operand, operand);3443 break :result func.reuseOperand(ty_op.operand, operand);
3453 } else WValue{ .none = {} };3444 };
3454 func.finishAir(inst, result, &.{ty_op.operand});3445 func.finishAir(inst, result, &.{ty_op.operand});
3455}3446}
34563447
...@@ -3474,7 +3465,6 @@ fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) Inn...@@ -3474,7 +3465,6 @@ fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) Inn
3474fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3465fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3475 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;3466 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
3476 const extra = func.air.extraData(Air.StructField, ty_pl.payload);3467 const extra = func.air.extraData(Air.StructField, ty_pl.payload);
3477 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{extra.data.struct_operand});
34783468
3479 const struct_ptr = try func.resolveInst(extra.data.struct_operand);3469 const struct_ptr = try func.resolveInst(extra.data.struct_operand);
3480 const struct_ty = func.air.typeOf(extra.data.struct_operand).childType();3470 const struct_ty = func.air.typeOf(extra.data.struct_operand).childType();
...@@ -3484,7 +3474,6 @@ fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3484,7 +3474,6 @@ fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
34843474
3485fn airStructFieldPtrIndex(func: *CodeGen, inst: Air.Inst.Index, index: u32) InnerError!void {3475fn airStructFieldPtrIndex(func: *CodeGen, inst: Air.Inst.Index, index: u32) InnerError!void {
3486 const ty_op = func.air.instructions.items(.data)[inst].ty_op;3476 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
3487 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
3488 const struct_ptr = try func.resolveInst(ty_op.operand);3477 const struct_ptr = try func.resolveInst(ty_op.operand);
3489 const struct_ty = func.air.typeOf(ty_op.operand).childType();3478 const struct_ty = func.air.typeOf(ty_op.operand).childType();
34903479
...@@ -3529,7 +3518,6 @@ fn structFieldPtr(...@@ -3529,7 +3518,6 @@ fn structFieldPtr(
3529fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3518fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3530 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;3519 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
3531 const struct_field = func.air.extraData(Air.StructField, ty_pl.payload).data;3520 const struct_field = func.air.extraData(Air.StructField, ty_pl.payload).data;
3532 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{struct_field.struct_operand});
35333521
3534 const struct_ty = func.air.typeOf(struct_field.struct_operand);3522 const struct_ty = func.air.typeOf(struct_field.struct_operand);
3535 const operand = try func.resolveInst(struct_field.struct_operand);3523 const operand = try func.resolveInst(struct_field.struct_operand);
...@@ -3795,7 +3783,6 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3795,7 +3783,6 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
37953783
3796fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!void {3784fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!void {
3797 const un_op = func.air.instructions.items(.data)[inst].un_op;3785 const un_op = func.air.instructions.items(.data)[inst].un_op;
3798 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{un_op});
3799 const operand = try func.resolveInst(un_op);3786 const operand = try func.resolveInst(un_op);
3800 const err_union_ty = func.air.typeOf(un_op);3787 const err_union_ty = func.air.typeOf(un_op);
3801 const pl_ty = err_union_ty.errorUnionPayload();3788 const pl_ty = err_union_ty.errorUnionPayload();
...@@ -3830,7 +3817,6 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro...@@ -3830,7 +3817,6 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro
38303817
3831fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {3818fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
3832 const ty_op = func.air.instructions.items(.data)[inst].ty_op;3819 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
3833 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
38343820
3835 const operand = try func.resolveInst(ty_op.operand);3821 const operand = try func.resolveInst(ty_op.operand);
3836 const op_ty = func.air.typeOf(ty_op.operand);3822 const op_ty = func.air.typeOf(ty_op.operand);
...@@ -3853,7 +3839,6 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo...@@ -3853,7 +3839,6 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo
38533839
3854fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {3840fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
3855 const ty_op = func.air.instructions.items(.data)[inst].ty_op;3841 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
3856 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
38573842
3858 const operand = try func.resolveInst(ty_op.operand);3843 const operand = try func.resolveInst(ty_op.operand);
3859 const op_ty = func.air.typeOf(ty_op.operand);3844 const op_ty = func.air.typeOf(ty_op.operand);
...@@ -3877,7 +3862,6 @@ fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)...@@ -3877,7 +3862,6 @@ fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)
38773862
3878fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3863fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3879 const ty_op = func.air.instructions.items(.data)[inst].ty_op;3864 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
3880 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
38813865
3882 const operand = try func.resolveInst(ty_op.operand);3866 const operand = try func.resolveInst(ty_op.operand);
3883 const err_ty = func.air.typeOfIndex(inst);3867 const err_ty = func.air.typeOfIndex(inst);
...@@ -3904,7 +3888,6 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void...@@ -3904,7 +3888,6 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void
39043888
3905fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3889fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3906 const ty_op = func.air.instructions.items(.data)[inst].ty_op;3890 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
3907 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
39083891
3909 const operand = try func.resolveInst(ty_op.operand);3892 const operand = try func.resolveInst(ty_op.operand);
3910 const err_ty = func.air.getRefType(ty_op.ty);3893 const err_ty = func.air.getRefType(ty_op.ty);
...@@ -3931,7 +3914,6 @@ fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3931,7 +3914,6 @@ fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
39313914
3932fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3915fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3933 const ty_op = func.air.instructions.items(.data)[inst].ty_op;3916 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
3934 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
39353917
3936 const ty = func.air.getRefType(ty_op.ty);3918 const ty = func.air.getRefType(ty_op.ty);
3937 const operand = try func.resolveInst(ty_op.operand);3919 const operand = try func.resolveInst(ty_op.operand);
...@@ -3998,7 +3980,6 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro...@@ -3998,7 +3980,6 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
39983980
3999fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind: enum { value, ptr }) InnerError!void {3981fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind: enum { value, ptr }) InnerError!void {
4000 const un_op = func.air.instructions.items(.data)[inst].un_op;3982 const un_op = func.air.instructions.items(.data)[inst].un_op;
4001 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{un_op});
4002 const operand = try func.resolveInst(un_op);3983 const operand = try func.resolveInst(un_op);
40033984
4004 const op_ty = func.air.typeOf(un_op);3985 const op_ty = func.air.typeOf(un_op);
...@@ -4043,7 +4024,7 @@ fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4043,7 +4024,7 @@ fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4043 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4024 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
4044 const opt_ty = func.air.typeOf(ty_op.operand);4025 const opt_ty = func.air.typeOf(ty_op.operand);
4045 const payload_ty = func.air.typeOfIndex(inst);4026 const payload_ty = func.air.typeOfIndex(inst);
4046 if (func.liveness.isUnused(inst) or !payload_ty.hasRuntimeBitsIgnoreComptime()) {4027 if (!payload_ty.hasRuntimeBitsIgnoreComptime()) {
4047 return func.finishAir(inst, .none, &.{ty_op.operand});4028 return func.finishAir(inst, .none, &.{ty_op.operand});
4048 }4029 }
40494030
...@@ -4063,7 +4044,6 @@ fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4063,7 +4044,6 @@ fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
40634044
4064fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4045fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4065 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4046 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
4066 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
4067 const operand = try func.resolveInst(ty_op.operand);4047 const operand = try func.resolveInst(ty_op.operand);
4068 const opt_ty = func.air.typeOf(ty_op.operand).childType();4048 const opt_ty = func.air.typeOf(ty_op.operand).childType();
40694049
...@@ -4108,7 +4088,6 @@ fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi...@@ -4108,7 +4088,6 @@ fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
41084088
4109fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4089fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4110 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4090 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
4111 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
4112 const payload_ty = func.air.typeOf(ty_op.operand);4091 const payload_ty = func.air.typeOf(ty_op.operand);
41134092
4114 const result = result: {4093 const result = result: {
...@@ -4147,7 +4126,6 @@ fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4147,7 +4126,6 @@ fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4147fn airSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4126fn airSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4148 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;4127 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
4149 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;4128 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
4150 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
41514129
4152 const lhs = try func.resolveInst(bin_op.lhs);4130 const lhs = try func.resolveInst(bin_op.lhs);
4153 const rhs = try func.resolveInst(bin_op.rhs);4131 const rhs = try func.resolveInst(bin_op.rhs);
...@@ -4162,7 +4140,6 @@ fn airSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4162,7 +4140,6 @@ fn airSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41624140
4163fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4141fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4164 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4142 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
4165 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
41664143
4167 const operand = try func.resolveInst(ty_op.operand);4144 const operand = try func.resolveInst(ty_op.operand);
4168 const len = try func.load(operand, Type.usize, func.ptrSize());4145 const len = try func.load(operand, Type.usize, func.ptrSize());
...@@ -4172,7 +4149,6 @@ fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4172,7 +4149,6 @@ fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41724149
4173fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4150fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4174 const bin_op = func.air.instructions.items(.data)[inst].bin_op;4151 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
4175 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
41764152
4177 const slice_ty = func.air.typeOf(bin_op.lhs);4153 const slice_ty = func.air.typeOf(bin_op.lhs);
4178 const slice = try func.resolveInst(bin_op.lhs);4154 const slice = try func.resolveInst(bin_op.lhs);
...@@ -4203,7 +4179,6 @@ fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4203,7 +4179,6 @@ fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4203fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4179fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4204 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;4180 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
4205 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;4181 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
4206 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
42074182
4208 const elem_ty = func.air.getRefType(ty_pl.ty).childType();4183 const elem_ty = func.air.getRefType(ty_pl.ty).childType();
4209 const elem_size = elem_ty.abiSize(func.target);4184 const elem_size = elem_ty.abiSize(func.target);
...@@ -4226,7 +4201,6 @@ fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4226,7 +4201,6 @@ fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42264201
4227fn airSlicePtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4202fn airSlicePtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4228 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4203 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
4229 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
4230 const operand = try func.resolveInst(ty_op.operand);4204 const operand = try func.resolveInst(ty_op.operand);
4231 const ptr = try func.load(operand, Type.usize, 0);4205 const ptr = try func.load(operand, Type.usize, 0);
4232 const result = try ptr.toLocal(func, Type.usize);4206 const result = try ptr.toLocal(func, Type.usize);
...@@ -4235,7 +4209,6 @@ fn airSlicePtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4235,7 +4209,6 @@ fn airSlicePtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42354209
4236fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4210fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4237 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4211 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
4238 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
42394212
4240 const operand = try func.resolveInst(ty_op.operand);4213 const operand = try func.resolveInst(ty_op.operand);
4241 const wanted_ty = func.air.getRefType(ty_op.ty);4214 const wanted_ty = func.air.getRefType(ty_op.ty);
...@@ -4264,19 +4237,14 @@ fn trunc(func: *CodeGen, operand: WValue, wanted_ty: Type, given_ty: Type) Inner...@@ -4264,19 +4237,14 @@ fn trunc(func: *CodeGen, operand: WValue, wanted_ty: Type, given_ty: Type) Inner
42644237
4265fn airBoolToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4238fn airBoolToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4266 const un_op = func.air.instructions.items(.data)[inst].un_op;4239 const un_op = func.air.instructions.items(.data)[inst].un_op;
4267 const result = if (func.liveness.isUnused(inst))4240 const operand = try func.resolveInst(un_op);
4268 WValue{ .none = {} }4241 const result = func.reuseOperand(un_op, operand);
4269 else result: {
4270 const operand = try func.resolveInst(un_op);
4271 break :result func.reuseOperand(un_op, operand);
4272 };
42734242
4274 func.finishAir(inst, result, &.{un_op});4243 func.finishAir(inst, result, &.{un_op});
4275}4244}
42764245
4277fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4246fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4278 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4247 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
4279 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
42804248
4281 const operand = try func.resolveInst(ty_op.operand);4249 const operand = try func.resolveInst(ty_op.operand);
4282 const array_ty = func.air.typeOf(ty_op.operand).childType();4250 const array_ty = func.air.typeOf(ty_op.operand).childType();
...@@ -4299,7 +4267,6 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4299,7 +4267,6 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42994267
4300fn airPtrToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4268fn airPtrToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4301 const un_op = func.air.instructions.items(.data)[inst].un_op;4269 const un_op = func.air.instructions.items(.data)[inst].un_op;
4302 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{un_op});
4303 const operand = try func.resolveInst(un_op);4270 const operand = try func.resolveInst(un_op);
43044271
4305 const result = switch (operand) {4272 const result = switch (operand) {
...@@ -4312,7 +4279,6 @@ fn airPtrToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4312,7 +4279,6 @@ fn airPtrToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43124279
4313fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4280fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4314 const bin_op = func.air.instructions.items(.data)[inst].bin_op;4281 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
4315 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
43164282
4317 const ptr_ty = func.air.typeOf(bin_op.lhs);4283 const ptr_ty = func.air.typeOf(bin_op.lhs);
4318 const ptr = try func.resolveInst(bin_op.lhs);4284 const ptr = try func.resolveInst(bin_op.lhs);
...@@ -4350,7 +4316,6 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4350,7 +4316,6 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4350fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4316fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4351 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;4317 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
4352 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;4318 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
4353 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
43544319
4355 const ptr_ty = func.air.typeOf(bin_op.lhs);4320 const ptr_ty = func.air.typeOf(bin_op.lhs);
4356 const elem_ty = func.air.getRefType(ty_pl.ty).childType();4321 const elem_ty = func.air.getRefType(ty_pl.ty).childType();
...@@ -4380,7 +4345,6 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4380,7 +4345,6 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4380fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {4345fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
4381 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;4346 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
4382 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;4347 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
4383 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
43844348
4385 const ptr = try func.resolveInst(bin_op.lhs);4349 const ptr = try func.resolveInst(bin_op.lhs);
4386 const offset = try func.resolveInst(bin_op.rhs);4350 const offset = try func.resolveInst(bin_op.rhs);
...@@ -4504,7 +4468,6 @@ fn memset(func: *CodeGen, ptr: WValue, len: WValue, value: WValue) InnerError!vo...@@ -4504,7 +4468,6 @@ fn memset(func: *CodeGen, ptr: WValue, len: WValue, value: WValue) InnerError!vo
45044468
4505fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4469fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4506 const bin_op = func.air.instructions.items(.data)[inst].bin_op;4470 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
4507 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
45084471
4509 const array_ty = func.air.typeOf(bin_op.lhs);4472 const array_ty = func.air.typeOf(bin_op.lhs);
4510 const array = try func.resolveInst(bin_op.lhs);4473 const array = try func.resolveInst(bin_op.lhs);
...@@ -4573,7 +4536,6 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4573,7 +4536,6 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45734536
4574fn airFloatToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4537fn airFloatToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4575 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4538 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
4576 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
45774539
4578 const operand = try func.resolveInst(ty_op.operand);4540 const operand = try func.resolveInst(ty_op.operand);
4579 const dest_ty = func.air.typeOfIndex(inst);4541 const dest_ty = func.air.typeOfIndex(inst);
...@@ -4598,7 +4560,6 @@ fn airFloatToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4598,7 +4560,6 @@ fn airFloatToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45984560
4599fn airIntToFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4561fn airIntToFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4600 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4562 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
4601 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
46024563
4603 const operand = try func.resolveInst(ty_op.operand);4564 const operand = try func.resolveInst(ty_op.operand);
4604 const dest_ty = func.air.typeOfIndex(inst);4565 const dest_ty = func.air.typeOfIndex(inst);
...@@ -4713,10 +4674,6 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4713,10 +4674,6 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4713 const child_ty = inst_ty.childType();4674 const child_ty = inst_ty.childType();
4714 const elem_size = child_ty.abiSize(func.target);4675 const elem_size = child_ty.abiSize(func.target);
47154676
4716 if (func.liveness.isUnused(inst)) {
4717 return func.finishAir(inst, .none, &.{ extra.a, extra.b });
4718 }
4719
4720 const module = func.bin_file.base.options.module.?;4677 const module = func.bin_file.base.options.module.?;
4721 // TODO: One of them could be by ref; handle in loop4678 // TODO: One of them could be by ref; handle in loop
4722 if (isByRef(func.air.typeOf(extra.a), func.target) or isByRef(inst_ty, func.target)) {4679 if (isByRef(func.air.typeOf(extra.a), func.target) or isByRef(inst_ty, func.target)) {
...@@ -4782,7 +4739,6 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4782,7 +4739,6 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4782 const elements = @ptrCast([]const Air.Inst.Ref, func.air.extra[ty_pl.payload..][0..len]);4739 const elements = @ptrCast([]const Air.Inst.Ref, func.air.extra[ty_pl.payload..][0..len]);
47834740
4784 const result: WValue = result_value: {4741 const result: WValue = result_value: {
4785 if (func.liveness.isUnused(inst)) break :result_value WValue.none;
4786 switch (result_ty.zigTypeTag()) {4742 switch (result_ty.zigTypeTag()) {
4787 .Array => {4743 .Array => {
4788 const result = try func.allocStack(result_ty);4744 const result = try func.allocStack(result_ty);
...@@ -4888,7 +4844,6 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4888,7 +4844,6 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4888fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4844fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4889 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;4845 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
4890 const extra = func.air.extraData(Air.UnionInit, ty_pl.payload).data;4846 const extra = func.air.extraData(Air.UnionInit, ty_pl.payload).data;
4891 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{extra.init});
48924847
4893 const result = result: {4848 const result = result: {
4894 const union_ty = func.air.typeOfIndex(inst);4849 const union_ty = func.air.typeOfIndex(inst);
...@@ -4927,7 +4882,6 @@ fn airPrefetch(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4927,7 +4882,6 @@ fn airPrefetch(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49274882
4928fn airWasmMemorySize(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4883fn airWasmMemorySize(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4929 const pl_op = func.air.instructions.items(.data)[inst].pl_op;4884 const pl_op = func.air.instructions.items(.data)[inst].pl_op;
4930 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{pl_op.operand});
49314885
4932 const result = try func.allocLocal(func.air.typeOfIndex(inst));4886 const result = try func.allocLocal(func.air.typeOfIndex(inst));
4933 try func.addLabel(.memory_size, pl_op.payload);4887 try func.addLabel(.memory_size, pl_op.payload);
...@@ -4937,7 +4891,6 @@ fn airWasmMemorySize(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4937,7 +4891,6 @@ fn airWasmMemorySize(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49374891
4938fn airWasmMemoryGrow(func: *CodeGen, inst: Air.Inst.Index) !void {4892fn airWasmMemoryGrow(func: *CodeGen, inst: Air.Inst.Index) !void {
4939 const pl_op = func.air.instructions.items(.data)[inst].pl_op;4893 const pl_op = func.air.instructions.items(.data)[inst].pl_op;
4940 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{pl_op.operand});
49414894
4942 const operand = try func.resolveInst(pl_op.operand);4895 const operand = try func.resolveInst(pl_op.operand);
4943 const result = try func.allocLocal(func.air.typeOfIndex(inst));4896 const result = try func.allocLocal(func.air.typeOfIndex(inst));
...@@ -5049,7 +5002,6 @@ fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5049,7 +5002,6 @@ fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50495002
5050fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5003fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5051 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5004 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
5052 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
50535005
5054 const un_ty = func.air.typeOf(ty_op.operand);5006 const un_ty = func.air.typeOf(ty_op.operand);
5055 const tag_ty = func.air.typeOfIndex(inst);5007 const tag_ty = func.air.typeOfIndex(inst);
...@@ -5069,7 +5021,6 @@ fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5069,7 +5021,6 @@ fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50695021
5070fn airFpext(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5022fn airFpext(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5071 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5023 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
5072 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
50735024
5074 const dest_ty = func.air.typeOfIndex(inst);5025 const dest_ty = func.air.typeOfIndex(inst);
5075 const operand = try func.resolveInst(ty_op.operand);5026 const operand = try func.resolveInst(ty_op.operand);
...@@ -5115,7 +5066,6 @@ fn fpext(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!...@@ -5115,7 +5066,6 @@ fn fpext(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!
51155066
5116fn airFptrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5067fn airFptrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5117 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5068 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
5118 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
51195069
5120 const dest_ty = func.air.typeOfIndex(inst);5070 const dest_ty = func.air.typeOfIndex(inst);
5121 const operand = try func.resolveInst(ty_op.operand);5071 const operand = try func.resolveInst(ty_op.operand);
...@@ -5156,7 +5106,6 @@ fn fptrunc(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro...@@ -5156,7 +5106,6 @@ fn fptrunc(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
51565106
5157fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5107fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5158 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5108 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
5159 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
51605109
5161 const err_set_ty = func.air.typeOf(ty_op.operand).childType();5110 const err_set_ty = func.air.typeOf(ty_op.operand).childType();
5162 const payload_ty = err_set_ty.errorUnionPayload();5111 const payload_ty = err_set_ty.errorUnionPayload();
...@@ -5171,8 +5120,6 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi...@@ -5171,8 +5120,6 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
5171 );5120 );
51725121
5173 const result = result: {5122 const result = result: {
5174 if (func.liveness.isUnused(inst)) break :result WValue{ .none = {} };
5175
5176 if (!payload_ty.hasRuntimeBitsIgnoreComptime()) {5123 if (!payload_ty.hasRuntimeBitsIgnoreComptime()) {
5177 break :result func.reuseOperand(ty_op.operand, operand);5124 break :result func.reuseOperand(ty_op.operand, operand);
5178 }5125 }
...@@ -5185,7 +5132,6 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi...@@ -5185,7 +5132,6 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
5185fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5132fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5186 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;5133 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
5187 const extra = func.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;5134 const extra = func.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
5188 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{extra.field_ptr});
51895135
5190 const field_ptr = try func.resolveInst(extra.field_ptr);5136 const field_ptr = try func.resolveInst(extra.field_ptr);
5191 const parent_ty = func.air.getRefType(ty_pl.ty).childType();5137 const parent_ty = func.air.getRefType(ty_pl.ty).childType();
...@@ -5225,7 +5171,6 @@ fn airRetAddr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5225,7 +5171,6 @@ fn airRetAddr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52255171
5226fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5172fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5227 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5173 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
5228 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
52295174
5230 const operand = try func.resolveInst(ty_op.operand);5175 const operand = try func.resolveInst(ty_op.operand);
5231 const op_ty = func.air.typeOf(ty_op.operand);5176 const op_ty = func.air.typeOf(ty_op.operand);
...@@ -5270,7 +5215,6 @@ fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5270,7 +5215,6 @@ fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52705215
5271fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5216fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5272 const un_op = func.air.instructions.items(.data)[inst].un_op;5217 const un_op = func.air.instructions.items(.data)[inst].un_op;
5273 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{un_op});
52745218
5275 const operand = try func.resolveInst(un_op);5219 const operand = try func.resolveInst(un_op);
5276 // First retrieve the symbol index to the error name table5220 // First retrieve the symbol index to the error name table
...@@ -5312,7 +5256,6 @@ fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5312,7 +5256,6 @@ fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53125256
5313fn airPtrSliceFieldPtr(func: *CodeGen, inst: Air.Inst.Index, offset: u32) InnerError!void {5257fn airPtrSliceFieldPtr(func: *CodeGen, inst: Air.Inst.Index, offset: u32) InnerError!void {
5314 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5258 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
5315 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
5316 const slice_ptr = try func.resolveInst(ty_op.operand);5259 const slice_ptr = try func.resolveInst(ty_op.operand);
5317 const result = try func.buildPointerOffset(slice_ptr, offset, .new);5260 const result = try func.buildPointerOffset(slice_ptr, offset, .new);
5318 func.finishAir(inst, result, &.{ty_op.operand});5261 func.finishAir(inst, result, &.{ty_op.operand});
...@@ -5322,7 +5265,6 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro...@@ -5322,7 +5265,6 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro
5322 assert(op == .add or op == .sub);5265 assert(op == .add or op == .sub);
5323 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;5266 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
5324 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;5267 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;
5325 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ extra.lhs, extra.rhs });
53265268
5327 const lhs_op = try func.resolveInst(extra.lhs);5269 const lhs_op = try func.resolveInst(extra.lhs);
5328 const rhs_op = try func.resolveInst(extra.rhs);5270 const rhs_op = try func.resolveInst(extra.rhs);
...@@ -5465,7 +5407,6 @@ fn addSubWithOverflowBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type,...@@ -5465,7 +5407,6 @@ fn addSubWithOverflowBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type,
5465fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5407fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5466 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;5408 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
5467 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;5409 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;
5468 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ extra.lhs, extra.rhs });
54695410
5470 const lhs = try func.resolveInst(extra.lhs);5411 const lhs = try func.resolveInst(extra.lhs);
5471 const rhs = try func.resolveInst(extra.rhs);5412 const rhs = try func.resolveInst(extra.rhs);
...@@ -5513,7 +5454,6 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5513,7 +5454,6 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5513fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5454fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5514 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;5455 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
5515 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;5456 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;
5516 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ extra.lhs, extra.rhs });
55175457
5518 const lhs = try func.resolveInst(extra.lhs);5458 const lhs = try func.resolveInst(extra.lhs);
5519 const rhs = try func.resolveInst(extra.rhs);5459 const rhs = try func.resolveInst(extra.rhs);
...@@ -5599,7 +5539,6 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5599,7 +5539,6 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
55995539
5600fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: enum { max, min }) InnerError!void {5540fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: enum { max, min }) InnerError!void {
5601 const bin_op = func.air.instructions.items(.data)[inst].bin_op;5541 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
5602 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
56035542
5604 const ty = func.air.typeOfIndex(inst);5543 const ty = func.air.typeOfIndex(inst);
5605 if (ty.zigTypeTag() == .Vector) {5544 if (ty.zigTypeTag() == .Vector) {
...@@ -5631,8 +5570,6 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: enum { max, min }) InnerE...@@ -5631,8 +5570,6 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: enum { max, min }) InnerE
5631fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5570fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5632 const pl_op = func.air.instructions.items(.data)[inst].pl_op;5571 const pl_op = func.air.instructions.items(.data)[inst].pl_op;
5633 const bin_op = func.air.extraData(Air.Bin, pl_op.payload).data;5572 const bin_op = func.air.extraData(Air.Bin, pl_op.payload).data;
5634 if (func.liveness.isUnused(inst))
5635 return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs, pl_op.operand });
56365573
5637 const ty = func.air.typeOfIndex(inst);5574 const ty = func.air.typeOfIndex(inst);
5638 if (ty.zigTypeTag() == .Vector) {5575 if (ty.zigTypeTag() == .Vector) {
...@@ -5665,7 +5602,6 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5665,7 +5602,6 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
56655602
5666fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5603fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5667 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5604 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
5668 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
56695605
5670 const ty = func.air.typeOf(ty_op.operand);5606 const ty = func.air.typeOf(ty_op.operand);
5671 const result_ty = func.air.typeOfIndex(inst);5607 const result_ty = func.air.typeOfIndex(inst);
...@@ -5718,7 +5654,6 @@ fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5718,7 +5654,6 @@ fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57185654
5719fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5655fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5720 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5656 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
5721 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
57225657
5723 const ty = func.air.typeOf(ty_op.operand);5658 const ty = func.air.typeOf(ty_op.operand);
5724 const result_ty = func.air.typeOfIndex(inst);5659 const result_ty = func.air.typeOfIndex(inst);
...@@ -5886,7 +5821,6 @@ fn lowerTry(...@@ -5886,7 +5821,6 @@ fn lowerTry(
58865821
5887fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5822fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5888 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5823 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
5889 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ty_op.operand});
58905824
5891 const ty = func.air.typeOfIndex(inst);5825 const ty = func.air.typeOfIndex(inst);
5892 const operand = try func.resolveInst(ty_op.operand);5826 const operand = try func.resolveInst(ty_op.operand);
...@@ -5957,7 +5891,6 @@ fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5957,7 +5891,6 @@ fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
59575891
5958fn airDiv(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5892fn airDiv(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5959 const bin_op = func.air.instructions.items(.data)[inst].bin_op;5893 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
5960 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
59615894
5962 const ty = func.air.typeOfIndex(inst);5895 const ty = func.air.typeOfIndex(inst);
5963 const lhs = try func.resolveInst(bin_op.lhs);5896 const lhs = try func.resolveInst(bin_op.lhs);
...@@ -5972,7 +5905,6 @@ fn airDiv(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5972,7 +5905,6 @@ fn airDiv(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
59725905
5973fn airDivFloor(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5906fn airDivFloor(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5974 const bin_op = func.air.instructions.items(.data)[inst].bin_op;5907 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
5975 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
59765908
5977 const ty = func.air.typeOfIndex(inst);5909 const ty = func.air.typeOfIndex(inst);
5978 const lhs = try func.resolveInst(bin_op.lhs);5910 const lhs = try func.resolveInst(bin_op.lhs);
...@@ -6121,7 +6053,6 @@ fn signAbsValue(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {...@@ -6121,7 +6053,6 @@ fn signAbsValue(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
6121fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {6053fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
6122 assert(op == .add or op == .sub);6054 assert(op == .add or op == .sub);
6123 const bin_op = func.air.instructions.items(.data)[inst].bin_op;6055 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
6124 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
61256056
6126 const ty = func.air.typeOfIndex(inst);6057 const ty = func.air.typeOfIndex(inst);
6127 const lhs = try func.resolveInst(bin_op.lhs);6058 const lhs = try func.resolveInst(bin_op.lhs);
...@@ -6234,7 +6165,6 @@ fn signedSat(func: *CodeGen, lhs_operand: WValue, rhs_operand: WValue, ty: Type,...@@ -6234,7 +6165,6 @@ fn signedSat(func: *CodeGen, lhs_operand: WValue, rhs_operand: WValue, ty: Type,
62346165
6235fn airShlSat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6166fn airShlSat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6236 const bin_op = func.air.instructions.items(.data)[inst].bin_op;6167 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
6237 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
62386168
6239 const ty = func.air.typeOfIndex(inst);6169 const ty = func.air.typeOfIndex(inst);
6240 const int_info = ty.intInfo(func.target);6170 const int_info = ty.intInfo(func.target);
...@@ -6393,7 +6323,6 @@ fn callIntrinsic(...@@ -6393,7 +6323,6 @@ fn callIntrinsic(
63936323
6394fn airTagName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6324fn airTagName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6395 const un_op = func.air.instructions.items(.data)[inst].un_op;6325 const un_op = func.air.instructions.items(.data)[inst].un_op;
6396 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{un_op});
6397 const operand = try func.resolveInst(un_op);6326 const operand = try func.resolveInst(un_op);
6398 const enum_ty = func.air.typeOf(un_op);6327 const enum_ty = func.air.typeOf(un_op);
63996328
test/behavior/var_args.zig+4
...@@ -217,6 +217,10 @@ test "copy VaList" {...@@ -217,6 +217,10 @@ test "copy VaList" {
217}217}
218218
219test "unused VaList arg" {219test "unused VaList arg" {
220 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
221 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
222 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
223
220 const S = struct {224 const S = struct {
221 fn thirdArg(dummy: c_int, ...) callconv(.C) c_int {225 fn thirdArg(dummy: c_int, ...) callconv(.C) c_int {
222 _ = dummy;226 _ = dummy;