[Bug tree-optimization/90567] GCC bad optimization on recursive functions
msmaldi at hotmail dot com
gcc-bugzilla@gcc.gnu.org
Tue May 21 23:26:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90567
--- Comment #4 from msmaldi <msmaldi at hotmail dot com> ---
-O2 generate better results, but gcc 7 continue faster
gcc-7 with -O3
real 0m3,143s
user 0m3,119s
sys 0m0,008s
gcc-8 with -O2
real 0m4,802s
user 0m4,793s
sys 0m0,009s
gcc 7 assembly generated:
fibo:
push r15
lea eax, [rdi-1]
push r14
push r13
push r12
push rbp
push rbx
sub rsp, 104
cmp eax, 1
mov DWORD PTR [rsp+68], 0
jbe .L2
mov edx, edi
lea ecx, [rdi-4]
lea eax, [rdi-2]
sub edx, 3
and edx, -2
sub ecx, edx
mov DWORD PTR [rsp+88], ecx
.L19:
cmp eax, 1
jbe .L21
lea ecx, [rax-3]
lea edx, [rax-1]
sub eax, 2
mov DWORD PTR [rsp+80], eax
and eax, -2
mov DWORD PTR [rsp+72], 0
sub ecx, eax
mov DWORD PTR [rsp+92], ecx
.L18:
cmp edx, 1
jbe .L22
lea eax, [rdx-2]
lea esi, [rdx-3]
lea ecx, [rdx-1]
mov DWORD PTR [rsp+60], 0
mov DWORD PTR [rsp+84], eax
and eax, -2
sub esi, eax
mov DWORD PTR [rsp+76], esi
.L17:
cmp ecx, 1
jbe .L23
lea eax, [rcx-2]
lea esi, [rcx-3]
lea edx, [rcx-1]
mov DWORD PTR [rsp+52], 0
mov DWORD PTR [rsp+64], eax
and eax, -2
sub esi, eax
mov DWORD PTR [rsp+56], esi
.L16:
cmp edx, 1
jbe .L24
lea eax, [rdx-2]
lea esi, [rdx-3]
lea ecx, [rdx-1]
mov DWORD PTR [rsp+40], 0
mov DWORD PTR [rsp+48], eax
and eax, -2
sub esi, eax
mov DWORD PTR [rsp+44], esi
.L15:
cmp ecx, 1
jbe .L25
lea eax, [rcx-2]
lea esi, [rcx-3]
lea edx, [rcx-1]
mov DWORD PTR [rsp+28], 0
mov DWORD PTR [rsp+36], eax
and eax, -2
sub esi, eax
mov DWORD PTR [rsp+32], esi
.L14:
cmp edx, 1
jbe .L26
lea eax, [rdx-2]
lea ecx, [rdx-3]
lea r13d, [rdx-1]
mov DWORD PTR [rsp+16], 0
mov DWORD PTR [rsp+24], eax
and eax, -2
sub ecx, eax
mov DWORD PTR [rsp+20], ecx
.L13:
cmp r13d, 1
jbe .L27
lea eax, [r13-2]
lea edx, [r13-1]
lea r15d, [r13-3]
xor ebp, ebp
mov DWORD PTR [rsp+12], eax
and eax, -2
mov ebx, edx
sub r15d, eax
.L12:
cmp ebx, 1
jbe .L28
lea r13d, [rbx-2]
xor r14d, r14d
mov r12d, r13d
and r12d, 1
.L11:
mov edi, ebx
sub ebx, 2
call fibo
add r14d, eax
cmp r12d, ebx
jne .L11
add r14d, 1
.L10:
add ebp, r14d
cmp r15d, r13d
mov ebx, r13d
jne .L12
mov r13d, DWORD PTR [rsp+12]
add ebp, 1
.L9:
add DWORD PTR [rsp+16], ebp
cmp DWORD PTR [rsp+20], r13d
jne .L13
mov eax, DWORD PTR [rsp+16]
mov edx, DWORD PTR [rsp+24]
add eax, 1
.L8:
add DWORD PTR [rsp+28], eax
cmp DWORD PTR [rsp+32], edx
jne .L14
mov eax, DWORD PTR [rsp+28]
mov ecx, DWORD PTR [rsp+36]
add eax, 1
.L7:
add DWORD PTR [rsp+40], eax
cmp DWORD PTR [rsp+44], ecx
jne .L15
mov eax, DWORD PTR [rsp+40]
mov edx, DWORD PTR [rsp+48]
add eax, 1
.L6:
add DWORD PTR [rsp+52], eax
cmp DWORD PTR [rsp+56], edx
jne .L16
mov eax, DWORD PTR [rsp+52]
mov ecx, DWORD PTR [rsp+64]
add eax, 1
.L5:
add DWORD PTR [rsp+60], eax
cmp DWORD PTR [rsp+76], ecx
jne .L17
mov eax, DWORD PTR [rsp+60]
mov edx, DWORD PTR [rsp+84]
add eax, 1
.L4:
add DWORD PTR [rsp+72], eax
cmp DWORD PTR [rsp+92], edx
jne .L18
mov edx, DWORD PTR [rsp+72]
mov eax, DWORD PTR [rsp+80]
add edx, 1
.L3:
add DWORD PTR [rsp+68], edx
cmp DWORD PTR [rsp+88], eax
jne .L19
.L2:
mov eax, DWORD PTR [rsp+68]
add rsp, 104
pop rbx
pop rbp
add eax, 1
pop r12
pop r13
pop r14
pop r15
ret
.L28:
mov r14d, 1
lea r13d, [rbx-2]
jmp .L10
.L27:
lea eax, [r13-2]
mov ebp, 1
mov DWORD PTR [rsp+12], eax
mov r13d, eax
jmp .L9
.L26:
lea esi, [rdx-2]
mov eax, 1
mov DWORD PTR [rsp+24], esi
mov edx, esi
jmp .L8
.L25:
sub ecx, 2
mov eax, 1
mov DWORD PTR [rsp+36], ecx
jmp .L7
.L24:
lea ecx, [rdx-2]
mov eax, 1
mov DWORD PTR [rsp+48], ecx
mov edx, ecx
jmp .L6
.L23:
sub ecx, 2
mov eax, 1
mov DWORD PTR [rsp+64], ecx
jmp .L5
.L22:
lea ecx, [rdx-2]
mov eax, 1
mov DWORD PTR [rsp+84], ecx
mov edx, ecx
jmp .L4
.L21:
sub eax, 2
mov edx, 1
mov DWORD PTR [rsp+80], eax
jmp .L3
gcc 8 assembly:
fibo:
push rbp
push rbx
sub rsp, 8
lea ebx, [rdi-1]
mov eax, 1
cmp ebx, 1
jbe .L1
xor ebp, ebp
.L3:
mov edi, ebx
call fibo
add ebp, eax
sub ebx, 2
cmp ebx, 1
ja .L3
lea eax, [rbp+1]
.L1:
add rsp, 8
pop rbx
pop rbp
ret
More information about the Gcc-bugs
mailing list