https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123231

            Bug ID: 123231
           Summary: [Trunk] AArch64: Miscompile at -O2/O3
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xxs_chy at outlook dot com
  Target Milestone: ---

gcc version 16.0.0 20251218 (experimental) (crosstool-NG 1.28.0_rc1)
qemu-aarch64 version 10.1.2

Testcase:
#include <stdint.h>
#include <stdio.h>
#define BS_VEC(type, num) type __attribute__((vector_size(num * sizeof(type))))
uint64_t BS_CHECKSUM;
#define safe_mod_func_uint16_t_u_u(_ui1, _ui2)                                
\
    ({                                                                        
\
        uint16_t ui1;                                                         
\
        uint16_t ui2 = _ui2;                                                  
\
        ui2 ?: ui1 % ui2;                                                     
\
    })
volatile int func_39_BS_COND_54;
int32_t *func_39(int32_t *p_40)
{
    BS_VEC(uint64_t, 16) BS_VAR_0 = { 9 };
    uint64_t LOCAL_CHECKSUM = 0;
    int32_t l_82;
    int32_t l_77 = -1;
BS_LABEL_3:
    l_77 = safe_mod_func_uint16_t_u_u(, l_82 = l_77) > l_77;
    if (func_39_BS_COND_54) goto BS_LABEL_3;
    int32_t BS_TEMP_516 = l_82;
    BS_VAR_0[BS_TEMP_516 < 0] = 0;
    for (uint32_t BS_TEMP_517 = 0; BS_TEMP_517 < 6; BS_TEMP_517++)
        LOCAL_CHECKSUM ^= BS_VAR_0[BS_TEMP_517];
    BS_CHECKSUM += LOCAL_CHECKSUM;
    return p_40;
}
int main()
{
    func_39(0);
    printf("BackSmith Checksum = 0x%016llx\n", BS_CHECKSUM);
}

Command:
> aarch64-unknown-linux-musl-gcc -O1 -march=armv9-a+sve -static a.c
> qemu-aarch64 a.out
BackSmith Checksum = 0x0000000000000009

> aarch64-unknown-linux-musl-gcc -O2 -march=armv9-a+sve -static a.c
> qemu-aarch64 a.out
BackSmith Checksum = 0x0000000000000000

Reply via email to