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...@@ -5946,11 +5946,13 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue
5946 const ptr = try f.resolveInst(extra.ptr);5946 const ptr = try f.resolveInst(extra.ptr);
5947 const expected_value = try f.resolveInst(extra.expected_value);5947 const expected_value = try f.resolveInst(extra.expected_value);
5948 const new_value = try f.resolveInst(extra.new_value);5948 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();
5951 const ptr_ty = f.air.typeOf(extra.ptr);5949 const ptr_ty = f.air.typeOf(extra.ptr);
5952 const ty = ptr_ty.childType();5950 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
5954 const target = f.object.dg.module.getTarget();5956 const target = f.object.dg.module.getTarget();
5955 var repr_pl = Type.Payload.Bits{5957 var repr_pl = Type.Payload.Bits{
5956 .base = .{ .tag = .int_unsigned },5958 .base = .{ .tag = .int_unsigned },
...@@ -5958,7 +5960,6 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue...@@ -5958,7 +5960,6 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue
5958 };5960 };
5959 const repr_ty = if (ty.isRuntimeFloat()) Type.initPayload(&repr_pl.base) else ty;5961 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);
5962 const local = try f.allocLocal(inst, inst_ty);5963 const local = try f.allocLocal(inst, inst_ty);
5963 if (inst_ty.isPtrLikeOptional()) {5964 if (inst_ty.isPtrLikeOptional()) {
5964 {5965 {
...@@ -6052,9 +6053,10 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6052,9 +6053,10 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
6052 const ty = ptr_ty.childType();6053 const ty = ptr_ty.childType();
6053 const ptr = try f.resolveInst(pl_op.operand);6054 const ptr = try f.resolveInst(pl_op.operand);
6054 const operand = try f.resolveInst(extra.operand);6055 const operand = try f.resolveInst(extra.operand);
6055 try reap(f, inst, &.{ pl_op.operand, extra.operand });6056
6056 const writer = f.object.writer();6057 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
6059 const target = f.object.dg.module.getTarget();6061 const target = f.object.dg.module.getTarget();
6060 var repr_pl = Type.Payload.Bits{6062 var repr_pl = Type.Payload.Bits{
...@@ -6065,7 +6067,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6065,7 +6067,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
6065 const is_128 = repr_pl.data == 128;6067 const is_128 = repr_pl.data == 128;
6066 const repr_ty = if (is_float) Type.initPayload(&repr_pl.base) else ty;6068 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);
6069 try writer.print("zig_atomicrmw_{s}", .{toAtomicRmwSuffix(extra.op())});6071 try writer.print("zig_atomicrmw_{s}", .{toAtomicRmwSuffix(extra.op())});
6070 if (is_float) try writer.writeAll("_float") else if (is_128) try writer.writeAll("_int128");6072 if (is_float) try writer.writeAll("_float") else if (is_128) try writer.writeAll("_int128");
6071 try writer.writeByte('(');6073 try writer.writeByte('(');
...@@ -6144,8 +6146,10 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa...@@ -6144,8 +6146,10 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa
6144 const ty = ptr_ty.childType();6146 const ty = ptr_ty.childType();
6145 const ptr = try f.resolveInst(bin_op.lhs);6147 const ptr = try f.resolveInst(bin_op.lhs);
6146 const element = try f.resolveInst(bin_op.rhs);6148 const element = try f.resolveInst(bin_op.rhs);
6147 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });6149
6148 const writer = f.object.writer();6150 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
6150 const target = f.object.dg.module.getTarget();6154 const target = f.object.dg.module.getTarget();
6151 var repr_pl = Type.Payload.Bits{6155 var repr_pl = Type.Payload.Bits{
...@@ -6154,7 +6158,6 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa...@@ -6154,7 +6158,6 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa
6154 };6158 };
6155 const repr_ty = if (ty.isRuntimeFloat()) Type.initPayload(&repr_pl.base) else ty;6159 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);
6158 try writer.writeAll("zig_atomic_store((zig_atomic(");6161 try writer.writeAll("zig_atomic_store((zig_atomic(");
6159 try f.renderType(writer, ty);6162 try f.renderType(writer, ty);
6160 try writer.writeByte(')');6163 try writer.writeByte(')');