https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114145
Bug ID: 114145
Summary: Missed optimization of loop deletion
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 in the code below, looping is not necessary, but gcc
seems to have missed this optimization.
https://godbolt.org/z/sYqzh8M3c
int a, b;
void func(int c){
for(int i=0;i<700;i++){
b=c;
c=a;
}
}
GCC -O3:
func(int):
mov edx, DWORD PTR a[rip]
mov eax, 700
jmp .L2
.L3:
sub eax, 3
mov edi, edx
.L2:
cmp eax, 1
jne .L3
mov DWORD PTR b[rip], edi
ret
Expected code (Clang):
func(int): # @func(int)
mov eax, dword ptr [rip + a]
mov dword ptr [rip + b], eax
ret
Thank you very much for your time and effort! We look forward to hearing from
you.