authorgravatar for abbix@riseup.netlg <abbix@riseup.net> 2026-08-16 04:06:29+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-16 04:06:29+02:00
log767d2526918192da548d77970f97028dd62cf9d1
tree1db67badbd3d012afe390355526063b733c4484d
parentf506a49142cdb8454c70acd662bf7e45289ddae2

llvm: don't scalarize bitcast vectors on LE (#36512)

`scalarize_bit_cast_vector_non_elementwise` was previously unconditionally enabled on both big-endian and little-endian targets, which led to suboptimal emitting of vector-to-integer bitcasts (https://zig.godbolt.org/z/qEG8zqfqn). This patch only enables it on big-endian targets as the little-endian semantics match the zig semantics. Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36512

1 files changed, 13 insertions(+), 10 deletions(-)

src/codegen/llvm.zig+13-10
...@@ -31,16 +31,19 @@ const bindings = if (build_options.have_llvm)...@@ -31,16 +31,19 @@ const bindings = if (build_options.have_llvm)
31else31else
32 @compileError("LLVM unavailable");32 @compileError("LLVM unavailable");
3333
34pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {34pub fn legalizeFeatures(target: *const std.Target) ?*const Air.Legalize.Features {
35 return comptime &.initMany(&.{35 return switch (target.cpu.arch.endian()) {
36 .expand_int_from_float_safe,36 inline else => |endian| comptime &.init(.{
37 .expand_int_from_float_optimized_safe,37 .expand_int_from_float_safe = true,
3838 .expand_int_from_float_optimized_safe = true,
39 .scalarize_bit_cast_array,39
40 // Needed because LLVM's `bitcast` on vectors is endian-specific unless the source and dest40 .scalarize_bit_cast_array = true,
41 // types are vectors with equal length (hence also with equal bits-per-element).41 // LLVM's `bitcast` on vectors places element 0 in the least significant bits on
42 .scalarize_bit_cast_vector_non_elementwise,42 // little-endian targets, which matches our semantics; but it does the opposite on
43 });43 // big-endian targets, so in that case we need to scalarize.
44 .scalarize_bit_cast_vector_non_elementwise = endian != .little,
45 }),
46 };
44}47}
4548
46fn subArchName(target: *const std.Target, comptime family: std.Target.Cpu.Arch.Family, mappings: anytype) ?[]const u8 {49fn subArchName(target: *const std.Target, comptime family: std.Target.Cpu.Arch.Family, mappings: anytype) ?[]const u8 {