[Bug tree-optimization/19939] New: -finline-functions inhibits tail recursion accumulation optimization
falk at debian dot org
gcc-bugzilla@gcc.gnu.org
Mon Feb 14 00:35:00 GMT 2005
falk@juist:/tmp% cat test.c
unsigned long ipow(unsigned long a, unsigned long b) {
if (b == 0)
return 1;
else
return a * ipow(a, b - 1);
}
falk@juist:/tmp% gcc -c -O2 test.c && objdump -d test.o
test.o: file format elf64-alpha
Disassembly of section .text:
0000000000000000 <ipow>:
0: 01 00 1f 20 lda v0,1
4: 05 00 20 e6 beq a1,1c <ipow+0x1c>
8: 1f 04 ff 47 nop
c: 00 00 fe 2f unop
10: ff ff 31 22 lda a1,-1(a1)
14: 00 04 10 4c mulq v0,a0,v0
18: fd ff 3f f6 bne a1,10 <ipow+0x10>
1c: 01 80 fa 6b ret
The recursion was nicely transformed to a branch.
falk@juist:/tmp% gcc -c -O2 test.c -finline-functions && objdump -d test.o
test.o: file format elf64-alpha
Disassembly of section .text:
0000000000000000 <ipow>:
0: 00 00 bb 27 ldah gp,0(t12)
4: 00 00 bd 23 lda gp,0(gp)
8: f0 ff de 23 lda sp,-16(sp)
c: 01 00 1f 20 lda v0,1
10: 08 00 3e b5 stq s0,8(sp)
14: 00 00 5e b7 stq ra,0(sp)
18: 09 04 f0 47 mov a0,s0
1c: 1c 00 20 e6 beq a1,90 <ipow+0x90>
20: a1 35 20 42 cmpeq a1,0x1,t0
24: 19 00 20 f4 bne t0,8c <ipow+0x8c>
28: a1 55 20 42 cmpeq a1,0x2,t0
2c: 01 00 5f 20 lda t1,1
30: 15 00 20 f4 bne t0,88 <ipow+0x88>
34: a1 75 20 42 cmpeq a1,0x3,t0
38: 12 00 20 f4 bne t0,84 <ipow+0x84>
3c: a1 95 20 42 cmpeq a1,0x4,t0
40: 0f 00 20 f4 bne t0,80 <ipow+0x80>
44: a1 b5 20 42 cmpeq a1,0x5,t0
48: 0c 00 20 f4 bne t0,7c <ipow+0x7c>
4c: a1 d5 20 42 cmpeq a1,0x6,t0
50: 09 00 20 f4 bne t0,78 <ipow+0x78>
54: a1 f5 20 42 cmpeq a1,0x7,t0
58: 06 00 20 f4 bne t0,74 <ipow+0x74>
5c: a1 15 21 42 cmpeq a1,0x8,t0
60: 03 00 20 f4 bne t0,70 <ipow+0x70>
64: f7 ff 31 22 lda a1,-9(a1)
68: 00 00 40 d3 bsr ra,6c <ipow+0x6c>
6c: 02 04 20 4d mulq s0,v0,t1
70: 02 04 49 4c mulq t1,s0,t1
74: 02 04 49 4c mulq t1,s0,t1
78: 02 04 49 4c mulq t1,s0,t1
7c: 02 04 49 4c mulq t1,s0,t1
80: 02 04 49 4c mulq t1,s0,t1
84: 02 04 49 4c mulq t1,s0,t1
88: 00 04 49 4c mulq t1,s0,v0
8c: 00 04 09 4c mulq v0,s0,v0
90: 00 00 5e a7 ldq ra,0(sp)
94: 08 00 3e a5 ldq s0,8(sp)
98: 10 00 de 23 lda sp,16(sp)
9c: 01 80 fa 6b ret
But here the recursion is back. It looks like the function was inlined into
itself too early.
--
Summary: -finline-functions inhibits tail recursion accumulation
optimization
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P2
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: falk at debian dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: alphaev68-unknown-linux-gnu
GCC host triplet: alphaev68-unknown-linux-gnu
GCC target triplet: alphaev68-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19939
More information about the Gcc-bugs
mailing list