authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-01-28 02:06:14-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-29 15:02:04-05:00
logfcb05ee2e70ab76c21211ecc2581d5d4ae5917b1
tree13fa64d1d0a4f92581b4a6333028af7ce9fa3efb
parent317d57115dc11100022f55c1bdf432b68924b4d8

cbe: don't emit unused undefined array literals


1 files changed, 9 insertions(+), 6 deletions(-)

src/codegen/c.zig+9-6
...@@ -3726,16 +3726,15 @@ fn airStore(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3726,16 +3726,15 @@ fn airStore(f: *Function, inst: Air.Inst.Index) !CValue {
37263726
3727 const ptr_val = try f.resolveInst(bin_op.lhs);3727 const ptr_val = try f.resolveInst(bin_op.lhs);
3728 const src_ty = f.air.typeOf(bin_op.rhs);3728 const src_ty = f.air.typeOf(bin_op.rhs);
3729 const src_val = try f.resolveInst(bin_op.rhs);
3730
3731 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
37323729
3733 // TODO Sema should emit a different instruction when the store should3730 // TODO Sema should emit a different instruction when the store should
3734 // possibly do the safety 0xaa bytes for undefined.3731 // possibly do the safety 0xaa bytes for undefined.
3735 const src_val_is_undefined =3732 const src_val_is_undefined =
3736 if (f.air.value(bin_op.rhs)) |v| v.isUndefDeep() else false;3733 if (f.air.value(bin_op.rhs)) |v| v.isUndefDeep() else false;
3737 if (src_val_is_undefined)3734 if (src_val_is_undefined) {
3735 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
3738 return try storeUndefined(f, ptr_info.pointee_type, ptr_val);3736 return try storeUndefined(f, ptr_info.pointee_type, ptr_val);
3737 }
37393738
3740 const target = f.object.dg.module.getTarget();3739 const target = f.object.dg.module.getTarget();
3741 const is_aligned = ptr_info.@"align" == 0 or3740 const is_aligned = ptr_info.@"align" == 0 or
...@@ -3744,6 +3743,9 @@ fn airStore(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3744,6 +3743,9 @@ fn airStore(f: *Function, inst: Air.Inst.Index) !CValue {
3744 const need_memcpy = !is_aligned or is_array;3743 const need_memcpy = !is_aligned or is_array;
3745 const writer = f.object.writer();3744 const writer = f.object.writer();
37463745
3746 const src_val = try f.resolveInst(bin_op.rhs);
3747 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
3748
3747 if (need_memcpy) {3749 if (need_memcpy) {
3748 // For this memcpy to safely work we need the rhs to have the same3750 // For this memcpy to safely work we need the rhs to have the same
3749 // underlying type as the lhs (i.e. they must both be arrays of the same underlying type).3751 // underlying type as the lhs (i.e. they must both be arrays of the same underlying type).
...@@ -4344,8 +4346,9 @@ fn airDbgInline(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4344,8 +4346,9 @@ fn airDbgInline(f: *Function, inst: Air.Inst.Index) !CValue {
4344fn airDbgVar(f: *Function, inst: Air.Inst.Index) !CValue {4346fn airDbgVar(f: *Function, inst: Air.Inst.Index) !CValue {
4345 const pl_op = f.air.instructions.items(.data)[inst].pl_op;4347 const pl_op = f.air.instructions.items(.data)[inst].pl_op;
4346 const name = f.air.nullTerminatedString(pl_op.payload);4348 const name = f.air.nullTerminatedString(pl_op.payload);
4347 const operand = try f.resolveInst(pl_op.operand);4349 const operand_is_undef = if (f.air.value(pl_op.operand)) |v| v.isUndefDeep() else false;
4348 _ = operand;4350 if (!operand_is_undef) _ = try f.resolveInst(pl_op.operand);
4351
4349 try reap(f, inst, &.{pl_op.operand});4352 try reap(f, inst, &.{pl_op.operand});
4350 const writer = f.object.writer();4353 const writer = f.object.writer();
4351 try writer.print("/* var:{s} */\n", .{name});4354 try writer.print("/* var:{s} */\n", .{name});