authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2022-03-25 21:35:28+01:00
committergravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2022-03-26 17:21:42+01:00
loge2468e3f2732a7a301f4174eb4d99bca5315a643
treea4c1ae95a4f040b3e27d8903bf3af770cf567bd9
parent1803167db2d5045e71015498b8e5b184c53edf07
signaturelock-open Commit is signed but in an unrecognized format.

Sema: change zirOverflowArithmetic to use new version of AIR insts

Also applies the change to Liveness

2 files changed, 32 insertions(+), 7 deletions(-)

src/Liveness.zig+8-3
......@@ -508,14 +508,19 @@ fn analyzeInst(
508508 },
509509 .memset,
510510 .memcpy,
511 => {
512 const pl_op = inst_datas[inst].pl_op;
513 const extra = a.air.extraData(Air.Bin, pl_op.payload).data;
514 return trackOperands(a, new_set, inst, main_tomb, .{ pl_op.operand, extra.lhs, extra.rhs });
515 },
511516 .add_with_overflow,
512517 .sub_with_overflow,
513518 .mul_with_overflow,
514519 .shl_with_overflow,
515520 => {
516 const pl_op = inst_datas[inst].pl_op;
517 const extra = a.air.extraData(Air.Bin, pl_op.payload).data;
518 return trackOperands(a, new_set, inst, main_tomb, .{ pl_op.operand, extra.lhs, extra.rhs });
521 const ty_pl = inst_datas[inst].ty_pl;
522 const extra = a.air.extraData(Air.Bin, ty_pl.payload).data;
523 return trackOperands(a, new_set, inst, main_tomb, .{ extra.lhs, extra.rhs, .none });
519524 },
520525 .br => {
521526 const br = inst_datas[inst].br;
src/Sema.zig+24-4
......@@ -9064,6 +9064,18 @@ fn zirOverflowArithmetic(
90649064 const maybe_lhs_val = try sema.resolveMaybeUndefVal(block, lhs_src, lhs);
90659065 const maybe_rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs);
90669066
9067 const types = try sema.arena.alloc(Type, 2);
9068 const values = try sema.arena.alloc(Value, 2);
9069 const tuple_ty = try Type.Tag.tuple.create(sema.arena, .{
9070 .types = types,
9071 .values = values,
9072 });
9073
9074 types[0] = dest_ty;
9075 types[1] = Type.initTag(.u1);
9076 values[0] = Value.initTag(.unreachable_value);
9077 values[1] = Value.initTag(.unreachable_value);
9078
90679079 const result: struct {
90689080 overflowed: enum { yes, no, undef },
90699081 wrapped: Air.Inst.Ref,
......@@ -9188,16 +9200,24 @@ fn zirOverflowArithmetic(
91889200 };
91899201
91909202 try sema.requireRuntimeBlock(block, src);
9191 return block.addInst(.{
9203
9204 const tuple = try block.addInst(.{
91929205 .tag = air_tag,
9193 .data = .{ .pl_op = .{
9194 .operand = ptr,
9195 .payload = try sema.addExtra(Air.Bin{
9206 .data = .{ .ty_pl = .{
9207 .ty = try block.sema.addType(tuple_ty),
9208 .payload = try block.sema.addExtra(Air.Bin{
91969209 .lhs = lhs,
91979210 .rhs = rhs,
91989211 }),
91999212 } },
92009213 });
9214
9215 const wrapped = try block.addStructFieldVal(tuple, 0, dest_ty);
9216 try sema.storePtr2(block, src, ptr, ptr_src, wrapped, src, .store);
9217
9218 const overflow_bit = try block.addStructFieldVal(tuple, 1, Type.initTag(.u1));
9219 const zero_u1 = try sema.addConstant(Type.initTag(.u1), Value.zero);
9220 return try block.addBinOp(.cmp_neq, overflow_bit, zero_u1);
92019221 };
92029222
92039223 try sema.storePtr2(block, src, ptr, ptr_src, result.wrapped, src, .store);