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 {
20092009
20102010fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
20112011 for (body) |inst| {
2012 if (func.liveness.isUnused(inst) and !func.air.mustLower(inst)) {
2013 continue;
2014 }
20122015 const old_bookkeeping_value = func.air_bookkeeping;
2013 // TODO: Determine why we need to pre-allocate an extra 4 possible values here.
2014 try func.currentBranch().values.ensureUnusedCapacity(func.gpa, Liveness.bpi + 4);
2016 try func.currentBranch().values.ensureUnusedCapacity(func.gpa, Liveness.bpi);
20152017 try func.genInst(inst);
20162018
20172019 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
21852187 }
21862188
21872189 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()) {
21892191 break :result_value WValue{ .none = {} };
21902192 } else if (ret_ty.isNoReturn()) {
21912193 try func.addTag(.@"unreachable");
......@@ -2494,7 +2496,6 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
24942496
24952497fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
24962498 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 });
24982499 const lhs = try func.resolveInst(bin_op.lhs);
24992500 const rhs = try func.resolveInst(bin_op.rhs);
25002501 const ty = func.air.typeOf(bin_op.lhs);
......@@ -2649,7 +2650,6 @@ const FloatOp = enum {
26492650
26502651fn airUnaryFloatOp(func: *CodeGen, inst: Air.Inst.Index, op: FloatOp) InnerError!void {
26512652 const un_op = func.air.instructions.items(.data)[inst].un_op;
2652 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{un_op});
26532653 const operand = try func.resolveInst(un_op);
26542654 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
27232723
27242724fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
27252725 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
27282727 const lhs = try func.resolveInst(bin_op.lhs);
27292728 const rhs = try func.resolveInst(bin_op.rhs);
......@@ -3218,9 +3217,6 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
32183217
32193218 func.branches.appendAssumeCapacity(.{});
32203219 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 }
32243220 try func.genBody(else_body);
32253221 try func.endBlock();
32263222 var else_stack = func.branches.pop();
......@@ -3229,9 +3225,6 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
32293225 // Outer block that matches the condition
32303226 func.branches.appendAssumeCapacity(.{});
32313227 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 }
32353228 try func.genBody(then_body);
32363229 var then_stack = func.branches.pop();
32373230 defer then_stack.deinit(func.gpa);
......@@ -3249,7 +3242,7 @@ fn mergeBranch(func: *CodeGen, branch: *const Branch) !void {
32493242 const target_keys = target_slice.items(.key);
32503243 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());
32533246 for (target_keys, 0..) |key, index| {
32543247 // TODO: process deaths from branches
32553248 parent.values.putAssumeCapacity(key, target_values[index]);
......@@ -3258,7 +3251,6 @@ fn mergeBranch(func: *CodeGen, branch: *const Branch) !void {
32583251
32593252fn airCmp(func: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) InnerError!void {
32603253 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
32633255 const lhs = try func.resolveInst(bin_op.lhs);
32643256 const rhs = try func.resolveInst(bin_op.rhs);
......@@ -3375,7 +3367,6 @@ fn airBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
33753367
33763368fn airNot(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
33773369 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
33803371 const operand = try func.resolveInst(ty_op.operand);
33813372 const operand_ty = func.air.typeOf(ty_op.operand);
......@@ -3441,7 +3432,7 @@ fn airUnreachable(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
34413432
34423433fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
34433434 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
3444 const result = if (!func.liveness.isUnused(inst)) result: {
3435 const result = result: {
34453436 const operand = try func.resolveInst(ty_op.operand);
34463437 const wanted_ty = func.air.typeOfIndex(inst);
34473438 const given_ty = func.air.typeOf(ty_op.operand);
......@@ -3450,7 +3441,7 @@ fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
34503441 break :result try bitcast_result.toLocal(func, wanted_ty);
34513442 }
34523443 break :result func.reuseOperand(ty_op.operand, operand);
3453 } else WValue{ .none = {} };
3444 };
34543445 func.finishAir(inst, result, &.{ty_op.operand});
34553446}
34563447
......@@ -3474,7 +3465,6 @@ fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) Inn
34743465fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
34753466 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
34763467 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
34793469 const struct_ptr = try func.resolveInst(extra.data.struct_operand);
34803470 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 {
34843474
34853475fn airStructFieldPtrIndex(func: *CodeGen, inst: Air.Inst.Index, index: u32) InnerError!void {
34863476 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});
34883477 const struct_ptr = try func.resolveInst(ty_op.operand);
34893478 const struct_ty = func.air.typeOf(ty_op.operand).childType();
34903479
......@@ -3529,7 +3518,6 @@ fn structFieldPtr(
35293518fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
35303519 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
35313520 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
35343522 const struct_ty = func.air.typeOf(struct_field.struct_operand);
35353523 const operand = try func.resolveInst(struct_field.struct_operand);
......@@ -3795,7 +3783,6 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
37953783
37963784fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!void {
37973785 const un_op = func.air.instructions.items(.data)[inst].un_op;
3798 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{un_op});
37993786 const operand = try func.resolveInst(un_op);
38003787 const err_union_ty = func.air.typeOf(un_op);
38013788 const pl_ty = err_union_ty.errorUnionPayload();
......@@ -3830,7 +3817,6 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro
38303817
38313818fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
38323819 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
38353821 const operand = try func.resolveInst(ty_op.operand);
38363822 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
38533839
38543840fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
38553841 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
38583843 const operand = try func.resolveInst(ty_op.operand);
38593844 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)
38773862
38783863fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
38793864 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
38823866 const operand = try func.resolveInst(ty_op.operand);
38833867 const err_ty = func.air.typeOfIndex(inst);
......@@ -3904,7 +3888,6 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void
39043888
39053889fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
39063890 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
39093892 const operand = try func.resolveInst(ty_op.operand);
39103893 const err_ty = func.air.getRefType(ty_op.ty);
......@@ -3931,7 +3914,6 @@ fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
39313914
39323915fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
39333916 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
39363918 const ty = func.air.getRefType(ty_op.ty);
39373919 const operand = try func.resolveInst(ty_op.operand);
......@@ -3998,7 +3980,6 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
39983980
39993981fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind: enum { value, ptr }) InnerError!void {
40003982 const un_op = func.air.instructions.items(.data)[inst].un_op;
4001 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{un_op});
40023983 const operand = try func.resolveInst(un_op);
40033984
40043985 const op_ty = func.air.typeOf(un_op);
......@@ -4043,7 +4024,7 @@ fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
40434024 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
40444025 const opt_ty = func.air.typeOf(ty_op.operand);
40454026 const payload_ty = func.air.typeOfIndex(inst);
4046 if (func.liveness.isUnused(inst) or !payload_ty.hasRuntimeBitsIgnoreComptime()) {
4027 if (!payload_ty.hasRuntimeBitsIgnoreComptime()) {
40474028 return func.finishAir(inst, .none, &.{ty_op.operand});
40484029 }
40494030
......@@ -4063,7 +4044,6 @@ fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
40634044
40644045fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
40654046 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});
40674047 const operand = try func.resolveInst(ty_op.operand);
40684048 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
41084088
41094089fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41104090 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});
41124091 const payload_ty = func.air.typeOf(ty_op.operand);
41134092
41144093 const result = result: {
......@@ -4147,7 +4126,6 @@ fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41474126fn airSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41484127 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
41494128 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
41524130 const lhs = try func.resolveInst(bin_op.lhs);
41534131 const rhs = try func.resolveInst(bin_op.rhs);
......@@ -4162,7 +4140,6 @@ fn airSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41624140
41634141fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41644142 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
41674144 const operand = try func.resolveInst(ty_op.operand);
41684145 const len = try func.load(operand, Type.usize, func.ptrSize());
......@@ -4172,7 +4149,6 @@ fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41724149
41734150fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41744151 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
41774153 const slice_ty = func.air.typeOf(bin_op.lhs);
41784154 const slice = try func.resolveInst(bin_op.lhs);
......@@ -4203,7 +4179,6 @@ fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42034179fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42044180 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
42054181 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
42084183 const elem_ty = func.air.getRefType(ty_pl.ty).childType();
42094184 const elem_size = elem_ty.abiSize(func.target);
......@@ -4226,7 +4201,6 @@ fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42264201
42274202fn airSlicePtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42284203 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});
42304204 const operand = try func.resolveInst(ty_op.operand);
42314205 const ptr = try func.load(operand, Type.usize, 0);
42324206 const result = try ptr.toLocal(func, Type.usize);
......@@ -4235,7 +4209,6 @@ fn airSlicePtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42354209
42364210fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42374211 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
42404213 const operand = try func.resolveInst(ty_op.operand);
42414214 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
42644237
42654238fn airBoolToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42664239 const un_op = func.air.instructions.items(.data)[inst].un_op;
4267 const result = if (func.liveness.isUnused(inst))
4268 WValue{ .none = {} }
4269 else result: {
4270 const operand = try func.resolveInst(un_op);
4271 break :result func.reuseOperand(un_op, operand);
4272 };
4240 const operand = try func.resolveInst(un_op);
4241 const result = func.reuseOperand(un_op, operand);
42734242
42744243 func.finishAir(inst, result, &.{un_op});
42754244}
42764245
42774246fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42784247 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
42814249 const operand = try func.resolveInst(ty_op.operand);
42824250 const array_ty = func.air.typeOf(ty_op.operand).childType();
......@@ -4299,7 +4267,6 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42994267
43004268fn airPtrToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43014269 const un_op = func.air.instructions.items(.data)[inst].un_op;
4302 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{un_op});
43034270 const operand = try func.resolveInst(un_op);
43044271
43054272 const result = switch (operand) {
......@@ -4312,7 +4279,6 @@ fn airPtrToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43124279
43134280fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43144281 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
43174283 const ptr_ty = func.air.typeOf(bin_op.lhs);
43184284 const ptr = try func.resolveInst(bin_op.lhs);
......@@ -4350,7 +4316,6 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43504316fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43514317 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
43524318 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
43554320 const ptr_ty = func.air.typeOf(bin_op.lhs);
43564321 const elem_ty = func.air.getRefType(ty_pl.ty).childType();
......@@ -4380,7 +4345,6 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43804345fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
43814346 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
43824347 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
43854349 const ptr = try func.resolveInst(bin_op.lhs);
43864350 const offset = try func.resolveInst(bin_op.rhs);
......@@ -4504,7 +4468,6 @@ fn memset(func: *CodeGen, ptr: WValue, len: WValue, value: WValue) InnerError!vo
45044468
45054469fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45064470 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
45094472 const array_ty = func.air.typeOf(bin_op.lhs);
45104473 const array = try func.resolveInst(bin_op.lhs);
......@@ -4573,7 +4536,6 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45734536
45744537fn airFloatToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45754538 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
45784540 const operand = try func.resolveInst(ty_op.operand);
45794541 const dest_ty = func.air.typeOfIndex(inst);
......@@ -4598,7 +4560,6 @@ fn airFloatToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45984560
45994561fn airIntToFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46004562 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
46034564 const operand = try func.resolveInst(ty_op.operand);
46044565 const dest_ty = func.air.typeOfIndex(inst);
......@@ -4713,10 +4674,6 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47134674 const child_ty = inst_ty.childType();
47144675 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
47204677 const module = func.bin_file.base.options.module.?;
47214678 // TODO: One of them could be by ref; handle in loop
47224679 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 {
47824739 const elements = @ptrCast([]const Air.Inst.Ref, func.air.extra[ty_pl.payload..][0..len]);
47834740
47844741 const result: WValue = result_value: {
4785 if (func.liveness.isUnused(inst)) break :result_value WValue.none;
47864742 switch (result_ty.zigTypeTag()) {
47874743 .Array => {
47884744 const result = try func.allocStack(result_ty);
......@@ -4888,7 +4844,6 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
48884844fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
48894845 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
48904846 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
48934848 const result = result: {
48944849 const union_ty = func.air.typeOfIndex(inst);
......@@ -4927,7 +4882,6 @@ fn airPrefetch(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49274882
49284883fn airWasmMemorySize(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49294884 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
49324886 const result = try func.allocLocal(func.air.typeOfIndex(inst));
49334887 try func.addLabel(.memory_size, pl_op.payload);
......@@ -4937,7 +4891,6 @@ fn airWasmMemorySize(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49374891
49384892fn airWasmMemoryGrow(func: *CodeGen, inst: Air.Inst.Index) !void {
49394893 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
49424895 const operand = try func.resolveInst(pl_op.operand);
49434896 const result = try func.allocLocal(func.air.typeOfIndex(inst));
......@@ -5049,7 +5002,6 @@ fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50495002
50505003fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50515004 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
50545006 const un_ty = func.air.typeOf(ty_op.operand);
50555007 const tag_ty = func.air.typeOfIndex(inst);
......@@ -5069,7 +5021,6 @@ fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50695021
50705022fn airFpext(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50715023 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
50745025 const dest_ty = func.air.typeOfIndex(inst);
50755026 const operand = try func.resolveInst(ty_op.operand);
......@@ -5115,7 +5066,6 @@ fn fpext(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!
51155066
51165067fn airFptrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51175068 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
51205070 const dest_ty = func.air.typeOfIndex(inst);
51215071 const operand = try func.resolveInst(ty_op.operand);
......@@ -5156,7 +5106,6 @@ fn fptrunc(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
51565106
51575107fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51585108 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
51615110 const err_set_ty = func.air.typeOf(ty_op.operand).childType();
51625111 const payload_ty = err_set_ty.errorUnionPayload();
......@@ -5171,8 +5120,6 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
51715120 );
51725121
51735122 const result = result: {
5174 if (func.liveness.isUnused(inst)) break :result WValue{ .none = {} };
5175
51765123 if (!payload_ty.hasRuntimeBitsIgnoreComptime()) {
51775124 break :result func.reuseOperand(ty_op.operand, operand);
51785125 }
......@@ -5185,7 +5132,6 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
51855132fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51865133 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
51875134 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
51905136 const field_ptr = try func.resolveInst(extra.field_ptr);
51915137 const parent_ty = func.air.getRefType(ty_pl.ty).childType();
......@@ -5225,7 +5171,6 @@ fn airRetAddr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52255171
52265172fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52275173 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
52305175 const operand = try func.resolveInst(ty_op.operand);
52315176 const op_ty = func.air.typeOf(ty_op.operand);
......@@ -5270,7 +5215,6 @@ fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52705215
52715216fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52725217 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
52755219 const operand = try func.resolveInst(un_op);
52765220 // First retrieve the symbol index to the error name table
......@@ -5312,7 +5256,6 @@ fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53125256
53135257fn airPtrSliceFieldPtr(func: *CodeGen, inst: Air.Inst.Index, offset: u32) InnerError!void {
53145258 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});
53165259 const slice_ptr = try func.resolveInst(ty_op.operand);
53175260 const result = try func.buildPointerOffset(slice_ptr, offset, .new);
53185261 func.finishAir(inst, result, &.{ty_op.operand});
......@@ -5322,7 +5265,6 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro
53225265 assert(op == .add or op == .sub);
53235266 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
53245267 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
53275269 const lhs_op = try func.resolveInst(extra.lhs);
53285270 const rhs_op = try func.resolveInst(extra.rhs);
......@@ -5465,7 +5407,6 @@ fn addSubWithOverflowBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type,
54655407fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54665408 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
54675409 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
54705411 const lhs = try func.resolveInst(extra.lhs);
54715412 const rhs = try func.resolveInst(extra.rhs);
......@@ -5513,7 +5454,6 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
55135454fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
55145455 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
55155456 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
55185458 const lhs = try func.resolveInst(extra.lhs);
55195459 const rhs = try func.resolveInst(extra.rhs);
......@@ -5599,7 +5539,6 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
55995539
56005540fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: enum { max, min }) InnerError!void {
56015541 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
56045543 const ty = func.air.typeOfIndex(inst);
56055544 if (ty.zigTypeTag() == .Vector) {
......@@ -5631,8 +5570,6 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: enum { max, min }) InnerE
56315570fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
56325571 const pl_op = func.air.instructions.items(.data)[inst].pl_op;
56335572 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
56375574 const ty = func.air.typeOfIndex(inst);
56385575 if (ty.zigTypeTag() == .Vector) {
......@@ -5665,7 +5602,6 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
56655602
56665603fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
56675604 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
56705606 const ty = func.air.typeOf(ty_op.operand);
56715607 const result_ty = func.air.typeOfIndex(inst);
......@@ -5718,7 +5654,6 @@ fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57185654
57195655fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57205656 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
57235658 const ty = func.air.typeOf(ty_op.operand);
57245659 const result_ty = func.air.typeOfIndex(inst);
......@@ -5886,7 +5821,6 @@ fn lowerTry(
58865821
58875822fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58885823 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
58915825 const ty = func.air.typeOfIndex(inst);
58925826 const operand = try func.resolveInst(ty_op.operand);
......@@ -5957,7 +5891,6 @@ fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
59575891
59585892fn airDiv(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
59595893 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
59625895 const ty = func.air.typeOfIndex(inst);
59635896 const lhs = try func.resolveInst(bin_op.lhs);
......@@ -5972,7 +5905,6 @@ fn airDiv(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
59725905
59735906fn airDivFloor(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
59745907 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
59775909 const ty = func.air.typeOfIndex(inst);
59785910 const lhs = try func.resolveInst(bin_op.lhs);
......@@ -6121,7 +6053,6 @@ fn signAbsValue(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
61216053fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
61226054 assert(op == .add or op == .sub);
61236055 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
61266057 const ty = func.air.typeOfIndex(inst);
61276058 const lhs = try func.resolveInst(bin_op.lhs);
......@@ -6234,7 +6165,6 @@ fn signedSat(func: *CodeGen, lhs_operand: WValue, rhs_operand: WValue, ty: Type,
62346165
62356166fn airShlSat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
62366167 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
62396169 const ty = func.air.typeOfIndex(inst);
62406170 const int_info = ty.intInfo(func.target);
......@@ -6393,7 +6323,6 @@ fn callIntrinsic(
63936323
63946324fn airTagName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63956325 const un_op = func.air.instructions.items(.data)[inst].un_op;
6396 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{un_op});
63976326 const operand = try func.resolveInst(un_op);
63986327 const enum_ty = func.air.typeOf(un_op);
63996328
test/behavior/var_args.zig+4
......@@ -217,6 +217,10 @@ test "copy VaList" {
217217}
218218
219219test "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
220224 const S = struct {
221225 fn thirdArg(dummy: c_int, ...) callconv(.C) c_int {
222226 _ = dummy;