On Fri, Oct 24, 2025 at 4:23 PM Georg-Johann Lay <[email protected]> wrote:
> Can it break volatile correctness or so?
I have done some smoke tests with the patched compiler with (gcc -O2):
--cut here--
volatile int m;
int foo (void)
{
int h = m;
int r = m;
asm volatile ("barrier" ::: "memory");
int p = m;
p = p + r;
return p - m;
}
--cut here--
The above code checked for:
- no unwanted DCE (load to dead variable "h")
- no unwanted CSE ("h" and "r", also "p" and direct read below "barrier")
- asm volatile blocking propagation of "r" over "barrier"
and gcc -O2 compiles to the expected code:
foo:
movl m(%rip), %eax
movl m(%rip), %eax
barrier
addl m(%rip), %eax
subl m(%rip), %eax
ret
while without patch:
foo:
movl m(%rip), %eax
movl m(%rip), %eax
barrier
movl m(%rip), %ecx
movl m(%rip), %edx
addl %ecx, %eax
subl %edx, %eax
ret
and for the reference, with "volatile" removed:
foo:
movl m(%rip), %eax
barrier
ret
Uros.