Skip to content

Vector misscompilation under aarch64_be-linux in debug mode #24920

@GiuseppeCesarano

Description

@GiuseppeCesarano

Zig Version

0.15.0-dev.1599+cf90a5e45

Steps to Reproduce and Observed Behavior

When loading a variable vector from a memory chunk offsetted with a variable the operations on the resulting vector are broken under aarch64_be in debug mode. Take the following example:

const std = @import("std");

pub fn main() !void {
    const heystack = [_]u32{ 3, 101, 102, 4 };

    const v_len = 4;
    const V = @Vector(v_len, u32);
    const needle: V = @splat(102);

    var i: usize = 0;

    const block: V = heystack[i..][0..v_len].*;
    var variable = block == needle;
    const constant = block == needle;

    std.debug.print("{}\n{}\n", .{ std.simd.firstTrue(variable).?, std.simd.firstTrue(constant).? });
    std.debug.print("{any}\n", .{constant == variable});

    _ = &variable;
    _ = &i;
}

Here is it's output in debug and in release mode:

❯ zig build-exe main.zig -target aarch64_be-linux-gnu -ODebug && qemu-aarch64_be ./main
1
2
{ true, false, false, true }

❯ zig build-exe main.zig -target aarch64_be-linux-gnu -OReleaseFast && qemu-aarch64_be ./main
2
2
{ true, true, true, true

The constant vector always acts right, meanwhile the variable vector acts right only if the load has a constant starting offset, in that case if we make i constant everything works as expected.

Expected Behavior

Vectors should always behave in endian agnostic ways as it happens in release mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-aarch6464-bit ARMbackend-llvmThe LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behaviormiscompilationThe compiler reports success but produces semantically incorrect code.upstreamAn issue with a third party project that Zig uses.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions