https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123117
Bug ID: 123117
Summary: Loongarch: wrong code at -O1/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: ---
Testcase:
#include <stdint.h>
#include <stdio.h>
#define BS_VEC(type, num) type __attribute__((vector_size(num * sizeof(type))))
#define BARRIER_v4u32
#ifdef ARCH_LOONGARCH64
#include <lsxintrin.h>
#define BARRIER_v4u32(x)
\
(BS_VEC(uint32_t, 4)) __lsx_vadd_w((__m128i)x, (__m128i){})
#endif
uint64_t BS_CHECKSUM_ARR[10];
uint64_t g_6, g_326;
int32_t g_167[2][1][6];
void func_23(uint32_t, uint64_t, uint8_t, uint16_t, uint64_t)
{
BS_VEC(int64_t, 2) BS_VAR_0[9] = {};
uint64_t LOCAL_CHECKSUM = 0;
for (; g_326 <= 5; g_326 += 1)
{
for (uint32_t BS_TEMP_110 = 0; BS_TEMP_110 < 9; BS_TEMP_110++)
for (uint32_t BS_TEMP_111 = 0; BS_TEMP_111 < 2; BS_TEMP_111++)
LOCAL_CHECKSUM ^= BS_VAR_0[BS_TEMP_110][BS_TEMP_111];
BS_VAR_0[0] = __builtin_convertvector(
__builtin_shufflevector(
BARRIER_v4u32((BS_VEC(uint32_t, 4)){ 2655507415 }),
(BS_VEC(uint32_t, 4)){}, 0, 1),
BS_VEC(int64_t, 2));
}
BS_CHECKSUM_ARR[5] += LOCAL_CHECKSUM;
}
int main()
{
uint16_t l_41 = 2;
func_23(0, g_6, l_41, g_167[1][0][5], l_41);
uint64_t BS_CHECKSUM = 5;
for (uint32_t i = 0; i < 10; i++) BS_CHECKSUM ^= BS_CHECKSUM_ARR[i];
printf("BackSmith Checksum = 0x%016llx\n", BS_CHECKSUM);
}
Command:
> loongarch64-unknown-linux-musl-gcc -mlsx -DARCH_LOONGARCH64 -O0 -static a.c
> qemu-loongarch64 a.out
> BackSmith Checksum = 0xffffffff9e47d3d
Command:
> loongarch64-unknown-linux-musl-gcc -mlsx -DARCH_LOONGARCH64 -O1 -static a.c
> qemu-loongarch64 a.out
> BackSmith Checksum = 0x000000009e47d3d2
gcc version 16.0.0 20251212 (experimental) (crosstool-NG 1.28.0)
qemu-loongarch64 version 10.1.2