[Bug middle-end/42995] New: [4.3 regression] inline-small-functions does not inline simple delegation calls
matt at use dot net
gcc-bugzilla@gcc.gnu.org
Sun Feb 7 23:01:00 GMT 2010
Using gcc 4.4.1 under Ubuntu 9.10 on amd64:
main.c:
#include "database.h"
int main()
{
int my_id = 0;
int result_for_my_id = get_data_for(my_id);
switch (result_for_my_id)
{
case 0:
return 666;
default:
return -1;
}
}
database.h:
#include <stdlib.h>
int get_data_for(int id)
{
return rand();
}
Compiling with:
gcc -O2 main.c -o n
produces this code:
0000000000400380 <main>:
400380: 48 83 ec 08 sub rsp,0x8
400384: 31 ff xor edi,edi
400386: e8 e5 ff ff ff call 400370 <get_data_for>
40038b: 83 f8 01 cmp eax,0x1
40038e: 19 c0 sbb eax,eax
400390: 48 83 c4 08 add rsp,0x8
400394: 25 9b 02 00 00 and eax,0x29b
400399: 83 e8 01 sub eax,0x1
40039c: c3 ret
40039d: 0f 1f 00 nop DWORD PTR [rax]
Note the 3 bytes of padding after the return. I'm confused why
inline-small-functions does not inline get_data_for. I tried this experiment:
gcc -O2 -finline-functions --param max-inline-insns-auto=20 main.c -o n
which produces this code:
0000000000400380 <main>:
400380: 48 83 ec 08 sub rsp,0x8
400384: e8 27 02 00 00 call 4005b0 <rand@plt>
400389: 83 f8 01 cmp eax,0x1
40038c: 19 c0 sbb eax,eax
40038e: 48 83 c4 08 add rsp,0x8
400392: 25 9b 02 00 00 and eax,0x29b
400397: 83 e8 01 sub eax,0x1
40039a: c3 ret
40039b: 0f 1f 44 00 00 nop DWORD PTR [rax+rax*1+0x0]
The padding got larger, but the code is actually smaller. Shouldn't the
heuristic used for inline-small-functions have caused get_data_for() to be
inlined?
This does not appear to be a problem in GCC 4.5.20091228 or 4.3.4.
--
Summary: [4.3 regression] inline-small-functions does not inline
simple delegation calls
Product: gcc
Version: 4.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: matt at use dot net
GCC build triplet: x86_64-linux-unknown
GCC host triplet: x86_64-linux-unknown
GCC target triplet: x86_64-linux-unknown
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42995
More information about the Gcc-bugs
mailing list