authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-09-12 00:30:20-04:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-09-21 21:08:52+02:00
log80eacd60034b71a4eaa580fe83822d80d2e09360
treee0ba54a47188f399d21e971ba0078c2c76d48dc3
parent798acd932e8a6aaad452f038e8c5b68efc79a8f5
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

aarch64: fix behavior failures


3 files changed, 28 insertions(+), 31 deletions(-)

src/codegen/aarch64/Select.zig+28-28
......@@ -5821,29 +5821,21 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
58215821 if (air.next()) |next_air_tag| continue :air_tag next_air_tag;
58225822 },
58235823 .unwrap_errunion_err_ptr => {
5824 if (isel.live_values.fetchRemove(air.inst_index)) |error_ptr_vi| unused: {
5825 defer error_ptr_vi.value.deref(isel);
5824 if (isel.live_values.fetchRemove(air.inst_index)) |error_vi| {
5825 defer error_vi.value.deref(isel);
58265826 const ty_op = air.data(air.inst_index).ty_op;
5827 switch (codegen.errUnionErrorOffset(
5828 isel.air.typeOf(ty_op.operand, ip).childType(zcu).errorUnionPayload(zcu),
5829 zcu,
5830 )) {
5831 0 => try error_ptr_vi.value.move(isel, ty_op.operand),
5832 else => |error_offset| {
5833 const error_ptr_ra = try error_ptr_vi.value.defReg(isel) orelse break :unused;
5834 const error_union_ptr_vi = try isel.use(ty_op.operand);
5835 const error_union_ptr_mat = try error_union_ptr_vi.matReg(isel);
5836 const lo12: u12 = @truncate(error_offset >> 0);
5837 const hi12: u12 = @intCast(error_offset >> 12);
5838 if (hi12 > 0) try isel.emit(.add(
5839 error_ptr_ra.x(),
5840 if (lo12 > 0) error_ptr_ra.x() else error_union_ptr_mat.ra.x(),
5841 .{ .shifted_immediate = .{ .immediate = hi12, .lsl = .@"12" } },
5842 ));
5843 if (lo12 > 0) try isel.emit(.add(error_ptr_ra.x(), error_union_ptr_mat.ra.x(), .{ .immediate = lo12 }));
5844 try error_union_ptr_mat.finish(isel);
5845 },
5846 }
5827 const error_union_ptr_ty = isel.air.typeOf(ty_op.operand, ip);
5828 const error_union_ptr_info = error_union_ptr_ty.ptrInfo(zcu);
5829 const error_union_ptr_vi = try isel.use(ty_op.operand);
5830 const error_union_ptr_mat = try error_union_ptr_vi.matReg(isel);
5831 _ = try error_vi.value.load(isel, ty_op.ty.toType(), error_union_ptr_mat.ra, .{
5832 .offset = codegen.errUnionErrorOffset(
5833 ZigType.fromInterned(error_union_ptr_info.child).errorUnionPayload(zcu),
5834 zcu,
5835 ),
5836 .@"volatile" = error_union_ptr_info.flags.is_volatile,
5837 });
5838 try error_union_ptr_mat.finish(isel);
58475839 }
58485840 if (air.next()) |next_air_tag| continue :air_tag next_air_tag;
58495841 },
......@@ -8011,6 +8003,7 @@ pub fn layout(
80118003 while (save_index < saves.len) {
80128004 if (save_index + 2 <= saves.len and saves[save_index + 1].needs_restore and
80138005 saves[save_index + 0].class == saves[save_index + 1].class and
8006 saves[save_index + 0].size == saves[save_index + 1].size and
80148007 saves[save_index + 0].offset + saves[save_index + 0].size == saves[save_index + 1].offset)
80158008 {
80168009 try isel.emit(.ldp(
......@@ -8317,7 +8310,7 @@ fn elemPtr(
83178310 }),
83188311 2 => {
83198312 const shift: u6 = @intCast(@ctz(elem_size));
8320 const temp_ra = temp_ra: switch (op) {
8313 const temp_ra, const free_temp_ra = temp_ra: switch (op) {
83218314 .add => switch (base_ra) {
83228315 else => {
83238316 const temp_ra = try isel.allocIntReg();
......@@ -8326,7 +8319,7 @@ fn elemPtr(
83268319 .register = temp_ra.x(),
83278320 .shift = .{ .lsl = shift },
83288321 } }));
8329 break :temp_ra temp_ra;
8322 break :temp_ra .{ temp_ra, true };
83308323 },
83318324 .zr => {
83328325 if (shift > 0) try isel.emit(.ubfm(elem_ptr_ra.x(), elem_ptr_ra.x(), .{
......@@ -8334,7 +8327,7 @@ fn elemPtr(
83348327 .immr = -%shift,
83358328 .imms = ~shift,
83368329 }));
8337 break :temp_ra elem_ptr_ra;
8330 break :temp_ra .{ elem_ptr_ra, false };
83388331 },
83398332 },
83408333 .sub => {
......@@ -8344,10 +8337,10 @@ fn elemPtr(
83448337 .register = temp_ra.x(),
83458338 .shift = .{ .lsl = shift },
83468339 } }));
8347 break :temp_ra temp_ra;
8340 break :temp_ra .{ temp_ra, true };
83488341 },
83498342 };
8350 defer if (temp_ra != elem_ptr_ra) isel.freeReg(temp_ra);
8343 defer if (free_temp_ra) isel.freeReg(temp_ra);
83518344 try isel.emit(.add(temp_ra.x(), index_mat.ra.x(), .{ .shifted_register = .{
83528345 .register = index_mat.ra.x(),
83538346 .shift = .{ .lsl = @intCast(63 - @clz(elem_size) - shift) },
......@@ -9276,7 +9269,14 @@ pub const Value = struct {
92769269 part_offset -= part_size;
92779270 var wrapped_res_part_it = res_vi.field(ty, part_offset, part_size);
92789271 const wrapped_res_part_vi = try wrapped_res_part_it.only(isel);
9279 const wrapped_res_part_ra = try wrapped_res_part_vi.?.defReg(isel) orelse if (need_carry) .zr else continue;
9272 const wrapped_res_part_ra = wrapped_res_part_ra: {
9273 const overflow_ra_lock: RegLock = switch (opts.overflow) {
9274 .ra => |ra| isel.lockReg(ra),
9275 else => .empty,
9276 };
9277 defer overflow_ra_lock.unlock(isel);
9278 break :wrapped_res_part_ra try wrapped_res_part_vi.?.defReg(isel) orelse if (need_carry) .zr else continue;
9279 };
92809280 const unwrapped_res_part_ra = unwrapped_res_part_ra: {
92819281 if (!need_wrap) break :unwrapped_res_part_ra wrapped_res_part_ra;
92829282 if (int_info.bits % 32 == 0) {
test/behavior/switch_on_captured_error.zig-1
......@@ -300,7 +300,6 @@ test "switch on error union catch capture" {
300300}
301301
302302test "switch on error union if else capture" {
303 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
304303 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
305304 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
306305
test/behavior/try.zig-2
......@@ -122,7 +122,6 @@ test "'return try' through conditional" {
122122}
123123
124124test "try ptr propagation const" {
125 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
126125 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
127126 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
128127 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
......@@ -155,7 +154,6 @@ test "try ptr propagation const" {
155154}
156155
157156test "try ptr propagation mutate" {
158 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
159157 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
160158 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
161159 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;