authorgravatar for me@brianferri.devBrian Ferri <me@brianferri.dev> 2026-10-02 08:57:33+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-06 04:18:23+02:00
log3c8e94f7e7e8814f0c19f5fa54efd7a865841e7b
treed66e080a82c6a8f8747fa290e726445d6574fbd9
parent98b5def297f6a660da53c97bfd83453b06c24412
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

Legalize: gate the one-element splat bitcast on its feature


2 files changed, 11 insertions(+), 1 deletions(-)

src/Air/Legalize.zig+1-1
...@@ -904,7 +904,7 @@ fn legalizeBody(l: *Legalize, body_start: usize, body_len: usize) Error!void {...@@ -904,7 +904,7 @@ fn legalizeBody(l: *Legalize, body_start: usize, body_len: usize) Error!void {
904 .splat => {904 .splat => {
905 const ty_op = l.air_instructions.items(.data)[@backingInt(inst)].ty_op;905 const ty_op = l.air_instructions.items(.data)[@backingInt(inst)].ty_op;
906 switch (ty_op.ty.zigTypeTag(zcu)) {906 switch (ty_op.ty.zigTypeTag(zcu)) {
907 .vector => switch (ty_op.ty.vectorLen(zcu)) {907 .vector => if (l.features.has(.splat_one_elem_to_bit_cast)) switch (ty_op.ty.vectorLen(zcu)) {
908 0 => unreachable,908 0 => unreachable,
909 1 => continue :inst l.replaceInst(inst, .bit_cast, .{ .ty_op = .{909 1 => continue :inst l.replaceInst(inst, .bit_cast, .{ .ty_op = .{
910 .ty = ty_op.ty,910 .ty = ty_op.ty,
test/behavior/splat.zig+10
...@@ -145,6 +145,16 @@ test "vector @splat" {...@@ -145,6 +145,16 @@ test "vector @splat" {
145 try testForT(8 * 2, @as(f16, 3.1415));145 try testForT(8 * 2, @as(f16, 3.1415));
146 try testForT(4 * 2, @as(f32, 3.1415));146 try testForT(4 * 2, @as(f32, 3.1415));
147 try testForT(2 * 2, @as(f64, 3.1415));147 try testForT(2 * 2, @as(f64, 3.1415));
148
149 // Splats into one-element vectors.
150 try testForT(1, @as(u8, 0xEE));
151 try testForT(1, @as(u16, 0xBEEF));
152 try testForT(1, @as(u32, 0xDEADBEEF));
153 try testForT(1, @as(u64, 0xCAFEF00DDEADBEEF));
154
155 try testForT(1, @as(f16, 3.1415));
156 try testForT(1, @as(f32, 3.1415));
157 try testForT(1, @as(f64, 3.1415));
148 }158 }
149 };159 };
150 try S.doTheTest();160 try S.doTheTest();