From 0c6cb8d8c80f0a316a77eddfebaa42cb77c8bf7d Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Tue, 14 Nov 2023 18:10:29 -0500 Subject: [PATCH] x86_64: actually track state during `@divFloor` of `i128` Closes #17998 --- lib/std/math/big/int_test.zig | 3 --- src/arch/x86_64/CodeGen.zig | 10 +++++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/std/math/big/int_test.zig b/lib/std/math/big/int_test.zig index 273d373652..a925f2c4b2 100644 --- a/lib/std/math/big/int_test.zig +++ b/lib/std/math/big/int_test.zig @@ -1443,9 +1443,6 @@ test "big.int divFloor #11166" { } test "big.int gcd #10932" { - // TODO https://github.com/ziglang/zig/issues/17998 - if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; - var a = try Managed.init(testing.allocator); defer a.deinit(); diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index 2e3209f64a..822ff0ec2d 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -3235,6 +3235,7 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void { var callee_buf: ["__udiv?i3".len]u8 = undefined; const signed_div_floor_state: struct { frame_index: FrameIndex, + state: State, reloc: Mir.Inst.Index, } = if (signed and tag == .div_floor) state: { const frame_index = try self.allocFrameIndex(FrameAlloc.initType(Type.usize, mod)); @@ -3295,9 +3296,10 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void { tmp_reg, mat_rhs_mcv.register_pair[1], ); + const state = try self.saveState(); const reloc = try self.asmJccReloc(.ns, undefined); - break :state .{ .frame_index = frame_index, .reloc = reloc }; + break :state .{ .frame_index = frame_index, .state = state, .reloc = reloc }; } else undefined; const call_mcv = try self.genCall( .{ .lib = .{ @@ -3328,6 +3330,12 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void { .base = .{ .frame = signed_div_floor_state.frame_index }, .mod = .{ .rm = .{ .size = .byte } }, }); + try self.restoreState(signed_div_floor_state.state, &.{}, .{ + .emit_instructions = true, + .update_tracking = true, + .resurrect = true, + .close_scope = true, + }); try self.performReloc(signed_div_floor_state.reloc); const dst_mcv = try self.genCall( .{ .lib = .{