authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-09-12 00:30:20-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-09-20 18:33:01-07:00
log5144f10ec90bda7109cdc1b4fad621defe8b2aaa
treea1d50c7fbb79d3eae1d9788824b5c22990c6652c
parent60cdacaff2bc7a4ff32cb440591ddaf4bdfdd0af

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 },
......@@ -8031,6 +8023,7 @@ pub fn layout(
80318023 while (save_index < saves.len) {
80328024 if (save_index + 2 <= saves.len and saves[save_index + 1].needs_restore and
80338025 saves[save_index + 0].class == saves[save_index + 1].class and
8026 saves[save_index + 0].size == saves[save_index + 1].size and
80348027 saves[save_index + 0].offset + saves[save_index + 0].size == saves[save_index + 1].offset)
80358028 {
80368029 try isel.emit(.ldp(
......@@ -8337,7 +8330,7 @@ fn elemPtr(
83378330 }),
83388331 2 => {
83398332 const shift: u6 = @intCast(@ctz(elem_size));
8340 const temp_ra = temp_ra: switch (op) {
8333 const temp_ra, const free_temp_ra = temp_ra: switch (op) {
83418334 .add => switch (base_ra) {
83428335 else => {
83438336 const temp_ra = try isel.allocIntReg();
......@@ -8346,7 +8339,7 @@ fn elemPtr(
83468339 .register = temp_ra.x(),
83478340 .shift = .{ .lsl = shift },
83488341 } }));
8349 break :temp_ra temp_ra;
8342 break :temp_ra .{ temp_ra, true };
83508343 },
83518344 .zr => {
83528345 if (shift > 0) try isel.emit(.ubfm(elem_ptr_ra.x(), elem_ptr_ra.x(), .{
......@@ -8354,7 +8347,7 @@ fn elemPtr(
83548347 .immr = -%shift,
83558348 .imms = ~shift,
83568349 }));
8357 break :temp_ra elem_ptr_ra;
8350 break :temp_ra .{ elem_ptr_ra, false };
83588351 },
83598352 },
83608353 .sub => {
......@@ -8364,10 +8357,10 @@ fn elemPtr(
83648357 .register = temp_ra.x(),
83658358 .shift = .{ .lsl = shift },
83668359 } }));
8367 break :temp_ra temp_ra;
8360 break :temp_ra .{ temp_ra, true };
83688361 },
83698362 };
8370 defer if (temp_ra != elem_ptr_ra) isel.freeReg(temp_ra);
8363 defer if (free_temp_ra) isel.freeReg(temp_ra);
83718364 try isel.emit(.add(temp_ra.x(), index_mat.ra.x(), .{ .shifted_register = .{
83728365 .register = index_mat.ra.x(),
83738366 .shift = .{ .lsl = @intCast(63 - @clz(elem_size) - shift) },
......@@ -9296,7 +9289,14 @@ pub const Value = struct {
92969289 part_offset -= part_size;
92979290 var wrapped_res_part_it = res_vi.field(ty, part_offset, part_size);
92989291 const wrapped_res_part_vi = try wrapped_res_part_it.only(isel);
9299 const wrapped_res_part_ra = try wrapped_res_part_vi.?.defReg(isel) orelse if (need_carry) .zr else continue;
9292 const wrapped_res_part_ra = wrapped_res_part_ra: {
9293 const overflow_ra_lock: RegLock = switch (opts.overflow) {
9294 .ra => |ra| isel.lockReg(ra),
9295 else => .empty,
9296 };
9297 defer overflow_ra_lock.unlock(isel);
9298 break :wrapped_res_part_ra try wrapped_res_part_vi.?.defReg(isel) orelse if (need_carry) .zr else continue;
9299 };
93009300 const unwrapped_res_part_ra = unwrapped_res_part_ra: {
93019301 if (!need_wrap) break :unwrapped_res_part_ra wrapped_res_part_ra;
93029302 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;