diff --git a/src/Air/Legalize.zig b/src/Air/Legalize.zig index 99dc64577b09583bcdf4f8a51b8efe9ff42c749c..5716615897a7fd445b36ba8d86fe502445a2c346 100644 --- a/src/Air/Legalize.zig +++ b/src/Air/Legalize.zig @@ -904,7 +904,7 @@ fn legalizeBody(l: *Legalize, body_start: usize, body_len: usize) Error!void { .splat => { const ty_op = l.air_instructions.items(.data)[@backingInt(inst)].ty_op; switch (ty_op.ty.zigTypeTag(zcu)) { - .vector => switch (ty_op.ty.vectorLen(zcu)) { + .vector => if (l.features.has(.splat_one_elem_to_bit_cast)) switch (ty_op.ty.vectorLen(zcu)) { 0 => unreachable, 1 => continue :inst l.replaceInst(inst, .bit_cast, .{ .ty_op = .{ .ty = ty_op.ty, diff --git a/test/behavior/splat.zig b/test/behavior/splat.zig index 859dfd8634e8ce9cd6d425194d182740b44d87ac..b440fcbd0aeae203291fc940d4916d1214cb048c 100644 --- a/test/behavior/splat.zig +++ b/test/behavior/splat.zig @@ -145,6 +145,16 @@ test "vector @splat" { try testForT(8 * 2, @as(f16, 3.1415)); try testForT(4 * 2, @as(f32, 3.1415)); try testForT(2 * 2, @as(f64, 3.1415)); + + // Splats into one-element vectors. + try testForT(1, @as(u8, 0xEE)); + try testForT(1, @as(u16, 0xBEEF)); + try testForT(1, @as(u32, 0xDEADBEEF)); + try testForT(1, @as(u64, 0xCAFEF00DDEADBEEF)); + + try testForT(1, @as(f16, 3.1415)); + try testForT(1, @as(f32, 3.1415)); + try testForT(1, @as(f64, 3.1415)); } }; try S.doTheTest();