Issue 176095
Summary [AArch64] Wrong code at -Os on aarch64-unknown-linux-musl
Labels backend:AArch64, miscompilation, generated by fuzzer
Assignees
Reporter XChy
    Reduced C testcase:
```c
#include <stdint.h>
#include <stdio.h>
#include <arm_neon.h>
#define BS_VEC(type, num) type __attribute__((vector_size(num * sizeof(type))))
#define BARRIER_v2u64(x) ((BS_VEC(uint64_t, 2))vqaddq_u64(x, (BS_VEC(uint64_t, 2)){}))
#define BARRIER_v16u8(x) ((BS_VEC(uint8_t, 16))vqaddq_u8(x, (uint8x16_t){}))
// BARRIER_xxxx(x) should be equivalent to x.
uint64_t func_1_a;
BS_VEC(uint64_t, 4) backsmith_snippet_997(int8_t BS_ARG_0)
{
 return __builtin_convertvector(
               (BS_VEC(int8_t, 4)){ BS_ARG_0, BS_ARG_0, BS_ARG_0 },
               BS_VEC(uint64_t, 4))
 * __builtin_convertvector(
               (BS_VEC(int8_t, 4)){ BS_ARG_0, BS_ARG_0, BS_ARG_0 },
               BS_VEC(uint64_t, 4));
}
uint64_t backsmith_pure_3(BS_VEC(int16_t, 16) BS_ARG_0,
 BS_VEC(uint8_t, 8) BS_ARG_1, uint32_t BS_ARG_2)
{
    int32_t BS_VAR_5[5] = {};
    if (backsmith_snippet_997(~BS_ARG_2)[2])
    {
        int8_t BS_TEMP_148 =
            BS_VAR_5[BARRIER_v2u64((BS_VEC(uint64_t, 2)){})[0]];
        BS_VEC(uint16_t, 4)
        BS_TEMP_149 = __builtin_convertvector(
            (BS_VEC(int8_t, 4)){ BS_TEMP_148, BS_TEMP_148, BS_TEMP_148 },
            BS_VEC(uint16_t, 4));
 return BS_ARG_1[5] ? __builtin_popcountg((uint16_t)BS_ARG_0[13])
 : BS_TEMP_149[0] | BS_TEMP_149[1] | BS_TEMP_149[2];
    }
 return 0;
}
int main()
{
    BS_VEC(uint64_t, 16) BS_VAR_0;
 BS_VEC(uint64_t, 16)
    BS_TEMP_334 = __builtin_convertvector(
 BARRIER_v16u8((BS_VEC(uint8_t, 16)){ 3 }), BS_VEC(uint64_t, 16));
 uint64_t BS_TEMP_338 = backsmith_pure_3(
        (BS_VEC(int16_t, 16)){}, (BS_VEC(uint8_t, 8)){ 0, 0, 0, 0, 0, 10 }, 0);
    if (func_1_a) return 0;
 BS_VAR_0 = (BS_VEC(uint64_t, 16)){ BS_TEMP_334[0], BS_TEMP_334[2] }
 * (BS_VEC(uint64_t, 16)){ BS_TEMP_338, BS_TEMP_338 };
    uint64_t BS_CHECKSUM = BS_VAR_0[0] ^ BS_VAR_0[1];
    printf("BackSmith Checksum = 0x%016llx\n", BS_CHECKSUM);
}
```

Reproducible commands:
qemu-aarch64 version 10.1.2
```bash
> clang --target=aarch64-unknown-linux-musl --gcc-toolchain=<toolchain> --sysroot=<sysroot> -static -Os a.c
> qemu-aarch64 a.out
BackSmith Checksum = 0x0000000000000024  # indeterministic result
> clang --target=aarch64-unknown-linux-musl --gcc-toolchain=<toolchain> --sysroot=<sysroot> -static -O0 a.c
> qemu-aarch64 a.out
BackSmith Checksum = 0x0000000000000000
```

Undefined behaviour check (replace BARRIER_xxx(x) with x): https://godbolt.org/z/ExeqdG4GP
The armv8-a clang 21.1.0 on godbolt cannot reproduce this miscompilation. It may relate to https://github.com/llvm/llvm-project/issues/176001.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to