authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-12-04 23:50:28-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-06 12:15:04-07:00
logf421efbcc1eebfca5a723a5d4ee5aa685bcc10d8
tree4ffeebda36c712ac185bde4a70cefe59e9a2464f
parentce4e5fee6346d142a7a98d5c56a056ff8a25e1f1

CBE: fix bad local reuse for volatile memset


1 files changed, 3 insertions(+), 2 deletions(-)

src/codegen/c.zig+3-2
...@@ -5935,16 +5935,15 @@ fn airMemset(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5935,16 +5935,15 @@ fn airMemset(f: *Function, inst: Air.Inst.Index) !CValue {
5935 const dest_ptr = try f.resolveInst(pl_op.operand);5935 const dest_ptr = try f.resolveInst(pl_op.operand);
5936 const value = try f.resolveInst(extra.lhs);5936 const value = try f.resolveInst(extra.lhs);
5937 const len = try f.resolveInst(extra.rhs);5937 const len = try f.resolveInst(extra.rhs);
5938 try reap(f, inst, &.{ pl_op.operand, extra.lhs, extra.rhs });
59395938
5940 const writer = f.object.writer();5939 const writer = f.object.writer();
5941 if (dest_ty.isVolatilePtr()) {5940 if (dest_ty.isVolatilePtr()) {
5942 var u8_ptr_pl = dest_ty.ptrInfo();5941 var u8_ptr_pl = dest_ty.ptrInfo();
5943 u8_ptr_pl.data.pointee_type = Type.u8;5942 u8_ptr_pl.data.pointee_type = Type.u8;
5944 const u8_ptr_ty = Type.initPayload(&u8_ptr_pl.base);5943 const u8_ptr_ty = Type.initPayload(&u8_ptr_pl.base);
5944 const index = try f.allocLocal(inst, Type.usize);
59455945
5946 try writer.writeAll("for (");5946 try writer.writeAll("for (");
5947 const index = try f.allocLocal(inst, Type.usize);
5948 try f.writeCValue(writer, index, .Other);5947 try f.writeCValue(writer, index, .Other);
5949 try writer.writeAll(" = ");5948 try writer.writeAll(" = ");
5950 try f.object.dg.renderValue(writer, Type.usize, Value.zero, .Initializer);5949 try f.object.dg.renderValue(writer, Type.usize, Value.zero, .Initializer);
...@@ -5966,11 +5965,13 @@ fn airMemset(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5966,11 +5965,13 @@ fn airMemset(f: *Function, inst: Air.Inst.Index) !CValue {
5966 try f.writeCValue(writer, value, .FunctionArgument);5965 try f.writeCValue(writer, value, .FunctionArgument);
5967 try writer.writeAll(";\n");5966 try writer.writeAll(";\n");
59685967
5968 try reap(f, inst, &.{ pl_op.operand, extra.lhs, extra.rhs });
5969 try freeLocal(f, inst, index.local, 0);5969 try freeLocal(f, inst, index.local, 0);
59705970
5971 return CValue.none;5971 return CValue.none;
5972 }5972 }
59735973
5974 try reap(f, inst, &.{ pl_op.operand, extra.lhs, extra.rhs });
5974 try writer.writeAll("memset(");5975 try writer.writeAll("memset(");
5975 try f.writeCValue(writer, dest_ptr, .FunctionArgument);5976 try f.writeCValue(writer, dest_ptr, .FunctionArgument);
5976 try writer.writeAll(", ");5977 try writer.writeAll(", ");