https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125180
Bug ID: 125180
Summary: [16 Regression] Conditions based on volatile reads may
result in undersized accesses on x86
Product: gcc
Version: 16.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: leon.a at serenityos dot org
Target Milestone: ---
Conditions based on the result of a volatile read on x86 seem to
contract the read of the volatile and check starting in version 16,
this seems to loose the volatile semantics or otherwise fails to preserve the
size of the memory access.
Small reproducer:
```c
void foo();
void frobnicate(unsigned volatile* reg)
{
if (*reg & 1)
foo();
}
```
GCC 15.2 output:
```
frobnicate:
mov eax, DWORD PTR [rdi]
test al, 1
jne .L4
ret
.L4:
jmp foo
```
GCC 16.1 output:
```
"frobnicate":
test BYTE PTR [rdi], 1
jne .L4
ret
.L4:
jmp "foo"
```
Correct code after contraction
```
"frobnicate":
test DWORD PTR [rdi], 1
jne .L4
ret
.L4:
jmp "foo"
```
Godbolt link
<https://godbolt.org/z/onKcP361G>