Skip to content

Commit 3f8f3c5

Browse files
committed
LLVM: correctly pad result tuple of airOverflow
1 parent 1cbfcc5 commit 3f8f3c5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/codegen/llvm.zig

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5499,14 +5499,24 @@ pub const FuncGen = struct {
54995499

55005500
const lhs_ty = self.air.typeOf(extra.lhs);
55015501
const scalar_ty = lhs_ty.scalarType();
5502+
const dest_ty = self.air.typeOfIndex(inst);
55025503

55035504
const intrinsic_name = if (scalar_ty.isSignedInt()) signed_intrinsic else unsigned_intrinsic;
55045505

55055506
const llvm_lhs_ty = try self.dg.llvmType(lhs_ty);
5507+
const llvm_dest_ty = try self.dg.llvmType(dest_ty);
5508+
5509+
const tg = self.dg.module.getTarget();
55065510

55075511
const llvm_fn = self.getIntrinsic(intrinsic_name, &.{llvm_lhs_ty});
55085512
const result_struct = self.builder.buildCall(llvm_fn, &[_]*const llvm.Value{ lhs, rhs }, 2, .Fast, .Auto, "");
5509-
return result_struct;
5513+
5514+
const result = self.builder.buildExtractValue(result_struct, 0, "");
5515+
const overflow_bit = self.builder.buildExtractValue(result_struct, 1, "");
5516+
5517+
var ty_buf: Type.Payload.Pointer = undefined;
5518+
const partial = self.builder.buildInsertValue(llvm_dest_ty.getUndef(), result, llvmFieldIndex(dest_ty, 0, tg, &ty_buf).?, "");
5519+
return self.builder.buildInsertValue(partial, overflow_bit, llvmFieldIndex(dest_ty, 1, tg, &ty_buf).?, "");
55105520
}
55115521

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

0 commit comments

Comments
 (0)