https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112117
Bug ID: 112117
Summary: Missed optimization of LICM that might need to be
combined with partial loop unrolling
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 found some optimizations (regarding LICM) that GCC may have missed.
We would greatly appreicate if you can take a look and let us know what you
think.
Given the following code:
https://godbolt.org/z/sGYhMKrzK
int a, b, c, d;
int m,n;
void test() {
for (int i = 0; i < 1000; i += 1) {
d += c + a;
a = c;
}
}
We can notice that the value of c+a is unchanged except when entering the loop
for the first time.
But GCC -O3 -fwrapv generates code that looks inefficient:
test():
mov esi, DWORD PTR c[rip]
mov eax, DWORD PTR a[rip]
mov edx, 1000
mov ecx, DWORD PTR d[rip]
jmp .L2
.L3:
mov eax, esi
.L2:
add eax, esi
add ecx, eax
sub edx, 1
jne .L3
mov DWORD PTR d[rip], ecx
mov DWORD PTR a[rip], esi
ret
Our analysis of LLVM shows that this problem may be solved by partial loop
unrolling followed by LICM.
Thank you very much for your time and effort! We look forward to hearing from
you.