authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-10-03 23:26:21-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-10-03 23:26:21-04:00
log2700af2aeb804c332fe11c9c26116769e78c3dbd
tree02c94330df0500ebcc88b6583632dad76a3db891
parente6e93d82b0272ce34d12ee3c59428a3b83caf447

x86_64: fix bool vector init register clobber

Closes #25439

2 files changed, 42 insertions(+), 6 deletions(-)

src/arch/x86_64/CodeGen.zig+2
...@@ -184685,6 +184685,8 @@ fn airAggregateInit(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -184685,6 +184685,8 @@ fn airAggregateInit(self: *CodeGen, inst: Air.Inst.Index) !void {
184685 if (result_ty.isVector(zcu) and elem_ty.toIntern() == .bool_type) {184685 if (result_ty.isVector(zcu) and elem_ty.toIntern() == .bool_type) {
184686 const result_size: u32 = @intCast(result_ty.abiSize(zcu));184686 const result_size: u32 = @intCast(result_ty.abiSize(zcu));
184687 const dst_reg = try self.register_manager.allocReg(inst, abi.RegisterClass.gp);184687 const dst_reg = try self.register_manager.allocReg(inst, abi.RegisterClass.gp);
184688 const dst_lock = self.register_manager.lockRegAssumeUnused(dst_reg);
184689 defer self.register_manager.unlockReg(dst_lock);
184688 try self.asmRegisterRegister(184690 try self.asmRegisterRegister(
184689 .{ ._, .xor },184691 .{ ._, .xor },
184690 registerAlias(dst_reg, @min(result_size, 4)),184692 registerAlias(dst_reg, @min(result_size, 4)),
test/behavior/vector.zig+40-6
...@@ -7,16 +7,50 @@ const expect = std.testing.expect;...@@ -7,16 +7,50 @@ const expect = std.testing.expect;
7const expectEqual = std.testing.expectEqual;7const expectEqual = std.testing.expectEqual;
88
9test "implicit cast vector to array - bool" {9test "implicit cast vector to array - bool" {
10 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO10 if (builtin.cpu.arch == .aarch64_be and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest;
11 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO11 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
12 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO12 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
13 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
14
15 const S = struct {
16 fn doTheTest() !void {
17 {
18 var v: @Vector(4, bool) = undefined;
19 v = .{ true, false, true, false };
20 const a: [4]bool = v;
21 try expect(mem.eql(bool, &a, &.{ true, false, true, false }));
22 }
23 {
24 var v: @Vector(25, bool) = undefined;
25 v = .{ false, false, false, false, true, true, false, false, false, true, false, true, false, false, true, false, false, true, false, false, true, true, true, false, false };
26 const a: [25]bool = v;
27 try expect(mem.eql(bool, &a, &.{ false, false, false, false, true, true, false, false, false, true, false, true, false, false, true, false, false, true, false, false, true, true, true, false, false }));
28 }
29 }
30 };
31 try S.doTheTest();
32 try comptime S.doTheTest();
33}
34
35test "implicit cast array to vector - bool" {
36 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
13 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;37 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
38 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
1439
15 const S = struct {40 const S = struct {
16 fn doTheTest() !void {41 fn doTheTest() !void {
17 const a: @Vector(4, bool) = [_]bool{ true, false, true, false };42 {
18 const result_array: [4]bool = a;43 var a: [4]bool = undefined;
19 try expect(mem.eql(bool, &result_array, &[4]bool{ true, false, true, false }));44 a = .{ true, false, false, true };
45 const v: @Vector(4, bool) = a;
46 try expect(mem.eql(bool, &@as([4]bool, v), &.{ true, false, false, true }));
47 }
48 {
49 var a: [25]bool = undefined;
50 a = .{ true, false, false, true, false, false, false, false, false, true, true, true, true, false, false, false, false, true, false, false, false, true, true, true, false };
51 const v: @Vector(25, bool) = a;
52 try expect(mem.eql(bool, &@as([25]bool, v), &.{ true, false, false, true, false, false, false, false, false, true, true, true, true, false, false, false, false, true, false, false, false, true, true, true, false }));
53 }
20 }54 }
21 };55 };
22 try S.doTheTest();56 try S.doTheTest();