https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123122
Bug ID: 123122
Summary: missed optimization for branch merging
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: 652023330028 at smail dot nju.edu.cn
Target Milestone: ---
Hello, for the following code, GCC with -O3 -fwrapv appears to miss an
opportunity to merge branches.
Reduced code (from ABC project
https://github.com/berkeley-abc/abc/blob/94d0b0dbbb439022aaaa1da721f15a3ed70160f9/src/proof/cec/cecPat.c#L455):
https://godbolt.org/z/b1WzhvWWW
int c;
int d() {
int f;
for (f = 0; c++; f++)
;
return f;
}
GCC -O3 -fwrapv:
d():
movl c(%rip), %eax
testl %eax, %eax
je .L4
negl %eax
.L4:
movl $1, %edx
movl %edx, c(%rip)
ret
Expected:
d():
movl c(%rip), %eax
movl $1, c(%rip)
negl %eax
ret