https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128119
Bug ID: 128119
Summary: [17 Regression] volatile and atomic loads removed at
-O2 on x86_64
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: yuki.tanaka at defaultcase dot de
Target Milestone: ---
typedef double v2df __attribute__ ((vector_size (16)));
unsigned long a(volatile unsigned long *p, v2df m)
{
unsigned long c = (unsigned long) __builtin_ia32_comisdeq(m, m) | 1;
unsigned long v = *p;
return ((unsigned __int128) v * c) >> 64;
}
unsigned long b(unsigned long *p, v2df m)
{
unsigned long c = (unsigned long) __builtin_ia32_comisdeq(m, m) | 1;
unsigned long v = __atomic_load_n(p, __ATOMIC_RELAXED);
return ((unsigned __int128) v * c) >> 64;
}
At -O2 GCC 17 removes the volatile load of *p in a and the atomic load in b.
GCC 16.2 keeps both.
Compiler Explorer, -O2 (GCC 16.2 vs. GCC 17):
x86-64 GCC 16.2:
"a":
mov eax, 1
mul QWORD PTR [rdi]
mov rax, rdx
ret
"b":
mov eax, 1
mul QWORD PTR [rdi]
mov rax, rdx
ret
x86-64 GCC 17.0.0:
"a":
xor eax, eax
ret
"b":
xor eax, eax
ret