https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114538
Bug ID: 114538
Summary: constant fold for (v + 1 == 0) == (v + 1 < v) fails
when v + 1 is stored in variable
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: goon.pri.low at gmail dot com
Target Milestone: ---
int unopt(unsigned v) {
unsigned n = v + 1;
return (n == 0) == (n < v);
}
int opt(unsigned v) {
return (v + 1 == 0) == (v + 1 < v);
}
unopt:
xor edx, edx
add edi, 1
setc dl
xor eax, eax
test edi, edi
setne al
xor eax, edx
ret
opt:
mov eax, 1
ret