diff options
| author | joachimschmidt557 <joachim.schmidt557@outlook.com> | 2022-03-25 21:35:28 +0100 |
|---|---|---|
| committer | joachimschmidt557 <joachim.schmidt557@outlook.com> | 2022-03-26 17:21:42 +0100 |
| commit | e2468e3f2732a7a301f4174eb4d99bca5315a643 (patch) | |
| tree | a4c1ae95a4f040b3e27d8903bf3af770cf567bd9 | |
| parent | 1803167db2d5045e71015498b8e5b184c53edf07 (diff) | |
| download | zig-e2468e3f2732a7a301f4174eb4d99bca5315a643.tar.gz zig-e2468e3f2732a7a301f4174eb4d99bca5315a643.zip | |
Sema: change zirOverflowArithmetic to use new version of AIR insts
Also applies the change to Liveness
| -rw-r--r-- | src/Liveness.zig | 11 | ||||
| -rw-r--r-- | src/Sema.zig | 28 |
2 files changed, 32 insertions, 7 deletions
diff --git a/src/Liveness.zig b/src/Liveness.zig index b9f4e6b33a..4b099baf6d 100644 --- a/src/Liveness.zig +++ b/src/Liveness.zig @@ -508,14 +508,19 @@ fn analyzeInst( }, .memset, .memcpy, + => { + const pl_op = inst_datas[inst].pl_op; + const extra = a.air.extraData(Air.Bin, pl_op.payload).data; + return trackOperands(a, new_set, inst, main_tomb, .{ pl_op.operand, extra.lhs, extra.rhs }); + }, .add_with_overflow, .sub_with_overflow, .mul_with_overflow, .shl_with_overflow, => { - const pl_op = inst_datas[inst].pl_op; - const extra = a.air.extraData(Air.Bin, pl_op.payload).data; - return trackOperands(a, new_set, inst, main_tomb, .{ pl_op.operand, extra.lhs, extra.rhs }); + const ty_pl = inst_datas[inst].ty_pl; + const extra = a.air.extraData(Air.Bin, ty_pl.payload).data; + return trackOperands(a, new_set, inst, main_tomb, .{ extra.lhs, extra.rhs, .none }); }, .br => { const br = inst_datas[inst].br; diff --git a/src/Sema.zig b/src/Sema.zig index f41528eca4..d2295a01a8 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -9064,6 +9064,18 @@ fn zirOverflowArithmetic( const maybe_lhs_val = try sema.resolveMaybeUndefVal(block, lhs_src, lhs); const maybe_rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs); + const types = try sema.arena.alloc(Type, 2); + const values = try sema.arena.alloc(Value, 2); + const tuple_ty = try Type.Tag.tuple.create(sema.arena, .{ + .types = types, + .values = values, + }); + + types[0] = dest_ty; + types[1] = Type.initTag(.u1); + values[0] = Value.initTag(.unreachable_value); + values[1] = Value.initTag(.unreachable_value); + const result: struct { overflowed: enum { yes, no, undef }, wrapped: Air.Inst.Ref, @@ -9188,16 +9200,24 @@ fn zirOverflowArithmetic( }; try sema.requireRuntimeBlock(block, src); - return block.addInst(.{ + + const tuple = try block.addInst(.{ .tag = air_tag, - .data = .{ .pl_op = .{ - .operand = ptr, - .payload = try sema.addExtra(Air.Bin{ + .data = .{ .ty_pl = .{ + .ty = try block.sema.addType(tuple_ty), + .payload = try block.sema.addExtra(Air.Bin{ .lhs = lhs, .rhs = rhs, }), } }, }); + + const wrapped = try block.addStructFieldVal(tuple, 0, dest_ty); + try sema.storePtr2(block, src, ptr, ptr_src, wrapped, src, .store); + + const overflow_bit = try block.addStructFieldVal(tuple, 1, Type.initTag(.u1)); + const zero_u1 = try sema.addConstant(Type.initTag(.u1), Value.zero); + return try block.addBinOp(.cmp_neq, overflow_bit, zero_u1); }; try sema.storePtr2(block, src, ptr, ptr_src, result.wrapped, src, .store); |
