https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113434
Bug ID: 113434
Summary: [13/14 Regression] Missed optimization for Loop
Unswitch
Product: gcc
Version: 14.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, we noticed that maybe there is a missed optimization for Loop Unswitch.
In the following code, if(a) is actually always true.
https://godbolt.org/z/rr5M77sEG
int a, b;
void test() {
a = 0;
for (int c = 0; c < 100; c += 1) {
a += 2;
if (a)
b += 3;
}
}
But GCC (trunk) -O3 -fwrapv:
test():
mov edx, DWORD PTR b[rip]
mov eax, 2
.L3:
test eax, eax
jne .L2
mov eax, 2
.L2:
add eax, 2
add edx, 3
cmp eax, 202
jne .L3
mov DWORD PTR a[rip], 200
mov DWORD PTR b[rip], edx
ret
Expected code (GCC-12.3 -O3 -fwrapv):
test():
mov edx, DWORD PTR b[rip]
xor eax, eax
.L2:
add eax, 2
add edx, 3
cmp eax, 200
jne .L2
mov DWORD PTR a[rip], 200
mov DWORD PTR b[rip], edx
ret
Thank you very much for your time and effort! We look forward to hearing from
you.