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 {
37263726
37273727 const ptr_val = try f.resolveInst(bin_op.lhs);
37283728 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
37333730 // TODO Sema should emit a different instruction when the store should
37343731 // possibly do the safety 0xaa bytes for undefined.
37353732 const src_val_is_undefined =
37363733 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 });
37383736 return try storeUndefined(f, ptr_info.pointee_type, ptr_val);
3737 }
37393738
37403739 const target = f.object.dg.module.getTarget();
37413740 const is_aligned = ptr_info.@"align" == 0 or
......@@ -3744,6 +3743,9 @@ fn airStore(f: *Function, inst: Air.Inst.Index) !CValue {
37443743 const need_memcpy = !is_aligned or is_array;
37453744 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
37473749 if (need_memcpy) {
37483750 // For this memcpy to safely work we need the rhs to have the same
37493751 // 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 {
43444346fn airDbgVar(f: *Function, inst: Air.Inst.Index) !CValue {
43454347 const pl_op = f.air.instructions.items(.data)[inst].pl_op;
43464348 const name = f.air.nullTerminatedString(pl_op.payload);
4347 const operand = try f.resolveInst(pl_op.operand);
4348 _ = operand;
4349 const operand_is_undef = if (f.air.value(pl_op.operand)) |v| v.isUndefDeep() else false;
4350 if (!operand_is_undef) _ = try f.resolveInst(pl_op.operand);
4351
43494352 try reap(f, inst, &.{pl_op.operand});
43504353 const writer = f.object.writer();
43514354 try writer.print("/* var:{s} */\n", .{name});