Skip to content

Commit af701ed

Browse files
stage2 LLVM: Adjust to new AIR arithmetic overflow instructions
1 parent 22640e3 commit af701ed

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

src/codegen/llvm.zig

+9-18
Original file line numberDiff line numberDiff line change
@@ -5189,14 +5189,12 @@ pub const FuncGen = struct {
51895189
if (self.liveness.isUnused(inst))
51905190
return null;
51915191

5192-
const pl_op = self.air.instructions.items(.data)[inst].pl_op;
5193-
const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
5192+
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
5193+
const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
51945194

5195-
const ptr = try self.resolveInst(pl_op.operand);
51965195
const lhs = try self.resolveInst(extra.lhs);
51975196
const rhs = try self.resolveInst(extra.rhs);
51985197

5199-
const ptr_ty = self.air.typeOf(pl_op.operand);
52005198
const lhs_ty = self.air.typeOf(extra.lhs);
52015199

52025200
const intrinsic_name = if (lhs_ty.isSignedInt()) signed_intrinsic else unsigned_intrinsic;
@@ -5205,13 +5203,7 @@ pub const FuncGen = struct {
52055203

52065204
const llvm_fn = self.getIntrinsic(intrinsic_name, &.{llvm_lhs_ty});
52075205
const result_struct = self.builder.buildCall(llvm_fn, &[_]*const llvm.Value{ lhs, rhs }, 2, .Fast, .Auto, "");
5208-
5209-
const result = self.builder.buildExtractValue(result_struct, 0, "");
5210-
const overflow_bit = self.builder.buildExtractValue(result_struct, 1, "");
5211-
5212-
self.store(ptr, ptr_ty, result, .NotAtomic);
5213-
5214-
return overflow_bit;
5206+
return result_struct;
52155207
}
52165208

52175209
fn airMulAdd(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
@@ -5293,16 +5285,16 @@ pub const FuncGen = struct {
52935285
if (self.liveness.isUnused(inst))
52945286
return null;
52955287

5296-
const pl_op = self.air.instructions.items(.data)[inst].pl_op;
5297-
const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
5288+
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
5289+
const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
52985290

5299-
const ptr = try self.resolveInst(pl_op.operand);
53005291
const lhs = try self.resolveInst(extra.lhs);
53015292
const rhs = try self.resolveInst(extra.rhs);
53025293

5303-
const ptr_ty = self.air.typeOf(pl_op.operand);
53045294
const lhs_ty = self.air.typeOf(extra.lhs);
53055295
const rhs_ty = self.air.typeOf(extra.rhs);
5296+
const dest_ty = self.air.typeOfIndex(inst);
5297+
const llvm_dest_ty = try self.dg.llvmType(dest_ty);
53065298

53075299
const tg = self.dg.module.getTarget();
53085300

@@ -5319,9 +5311,8 @@ pub const FuncGen = struct {
53195311

53205312
const overflow_bit = self.builder.buildICmp(.NE, lhs, reconstructed, "");
53215313

5322-
self.store(ptr, ptr_ty, result, .NotAtomic);
5323-
5324-
return overflow_bit;
5314+
const partial = self.builder.buildInsertValue(llvm_dest_ty.getUndef(), result, 0, "");
5315+
return self.builder.buildInsertValue(partial, overflow_bit, 1, "");
53255316
}
53265317

53275318
fn airAnd(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {

0 commit comments

Comments
 (0)