Skip to content

Commit 22640e3

Browse files
Sema: change zirOverflowArithmetic to use new version of AIR insts
Also applies the change to Liveness
1 parent 9591d35 commit 22640e3

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/Liveness.zig

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

0 commit comments

Comments
 (0)