authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-04-21 20:44:16-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-04-21 23:08:48-04:00
log08a8aa100d73bd87e6c39563d8f5c6186217afb3
tree715c70bbe82fa7c33b91cd7d1bbcd51c1e728349
parent5feb27c126bd25e6cdc93c390d90c4450076e75c

cbe: fix local aliasing issues in atomic ops


1 files changed, 11 insertions(+), 8 deletions(-)

src/codegen/c.zig+11-8
......@@ -5946,11 +5946,13 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue
59465946 const ptr = try f.resolveInst(extra.ptr);
59475947 const expected_value = try f.resolveInst(extra.expected_value);
59485948 const new_value = try f.resolveInst(extra.new_value);
5949 try reap(f, inst, &.{ extra.ptr, extra.expected_value, extra.new_value });
5950 const writer = f.object.writer();
59515949 const ptr_ty = f.air.typeOf(extra.ptr);
59525950 const ty = ptr_ty.childType();
59535951
5952 const writer = f.object.writer();
5953 const new_value_mat = try Materialize.start(f, inst, writer, ty, new_value);
5954 try reap(f, inst, &.{ extra.ptr, extra.expected_value, extra.new_value });
5955
59545956 const target = f.object.dg.module.getTarget();
59555957 var repr_pl = Type.Payload.Bits{
59565958 .base = .{ .tag = .int_unsigned },
......@@ -5958,7 +5960,6 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue
59585960 };
59595961 const repr_ty = if (ty.isRuntimeFloat()) Type.initPayload(&repr_pl.base) else ty;
59605962
5961 const new_value_mat = try Materialize.start(f, inst, writer, ty, new_value);
59625963 const local = try f.allocLocal(inst, inst_ty);
59635964 if (inst_ty.isPtrLikeOptional()) {
59645965 {
......@@ -6052,9 +6053,10 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
60526053 const ty = ptr_ty.childType();
60536054 const ptr = try f.resolveInst(pl_op.operand);
60546055 const operand = try f.resolveInst(extra.operand);
6055 try reap(f, inst, &.{ pl_op.operand, extra.operand });
6056
60566057 const writer = f.object.writer();
6057 const local = try f.allocLocal(inst, inst_ty);
6058 const operand_mat = try Materialize.start(f, inst, writer, ty, operand);
6059 try reap(f, inst, &.{ pl_op.operand, extra.operand });
60586060
60596061 const target = f.object.dg.module.getTarget();
60606062 var repr_pl = Type.Payload.Bits{
......@@ -6065,7 +6067,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
60656067 const is_128 = repr_pl.data == 128;
60666068 const repr_ty = if (is_float) Type.initPayload(&repr_pl.base) else ty;
60676069
6068 const operand_mat = try Materialize.start(f, inst, writer, ty, operand);
6070 const local = try f.allocLocal(inst, inst_ty);
60696071 try writer.print("zig_atomicrmw_{s}", .{toAtomicRmwSuffix(extra.op())});
60706072 if (is_float) try writer.writeAll("_float") else if (is_128) try writer.writeAll("_int128");
60716073 try writer.writeByte('(');
......@@ -6144,8 +6146,10 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa
61446146 const ty = ptr_ty.childType();
61456147 const ptr = try f.resolveInst(bin_op.lhs);
61466148 const element = try f.resolveInst(bin_op.rhs);
6147 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
6149
61486150 const writer = f.object.writer();
6151 const element_mat = try Materialize.start(f, inst, writer, ty, element);
6152 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
61496153
61506154 const target = f.object.dg.module.getTarget();
61516155 var repr_pl = Type.Payload.Bits{
......@@ -6154,7 +6158,6 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa
61546158 };
61556159 const repr_ty = if (ty.isRuntimeFloat()) Type.initPayload(&repr_pl.base) else ty;
61566160
6157 const element_mat = try Materialize.start(f, inst, writer, ty, element);
61586161 try writer.writeAll("zig_atomic_store((zig_atomic(");
61596162 try f.renderType(writer, ty);
61606163 try writer.writeByte(')');