From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10646 invoked by alias); 10 May 2009 18:08:58 -0000 Received: (qmail 10623 invoked by uid 48); 10 May 2009 18:08:46 -0000 Date: Sun, 10 May 2009 18:08:00 -0000 Message-ID: <20090510180846.10622.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug middle-end/40093] Optimization by functios reordering. In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "vvv at ru dot ru" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2009-05/txt/msg00857.txt.bz2 ------- Comment #3 from vvv at ru dot ru 2009-05-10 18:08 ------- (In reply to comment #2) > This should have been done already with cgraph order. Unfortunately, I can see inverse order only in separate source file. Inverse but not optimized. Example: // file order1.c #include main(int argc, char **argv) {int i,j,k,l; i=func1(); j=func2(); k=func3(); l=func4(); printf("%d %d %d %d\n",i,j,k,l); } ===================================== // file order2.c int func1(){ return(F(4));} int func2(){ return(F(3));} int func3(){ return(F(2));} int func4(){ return(F(1));} ===================================== // file order3.c int F(int x){ return(x);} # gcc --version gcc (GCC) 4.5.0 20090508 (experimental) # gcc -o order order3.c order2.c order1.c -O2 # objdump -d order 0000000000400520 : 400520: 89 f8 mov %edi,%eax 400522: c3 retq 0000000000400530 : 400530: bf 01 00 00 00 mov $0x1,%edi 400535: 31 c0 xor %eax,%eax 400537: e9 e4 ff ff ff jmpq 400520 0000000000400540 : 400540: bf 02 00 00 00 mov $0x2,%edi 400545: 31 c0 xor %eax,%eax 400547: e9 d4 ff ff ff jmpq 400520 0000000000400550 : 400550: bf 03 00 00 00 mov $0x3,%edi 400555: 31 c0 xor %eax,%eax 400557: e9 c4 ff ff ff jmpq 400520 0000000000400560 : 400560: bf 04 00 00 00 mov $0x4,%edi 400565: 31 c0 xor %eax,%eax 400567: e9 b4 ff ff ff jmpq 400520 0000000000400570
: 400570: 48 89 5c 24 e8 mov %rbx,-0x18(%rsp) 400575: 48 89 6c 24 f0 mov %rbp,-0x10(%rsp) 40057a: 31 c0 xor %eax,%eax 40057c: 4c 89 64 24 f8 mov %r12,-0x8(%rsp) 400581: 48 83 ec 18 sub $0x18,%rsp 400585: e8 d6 ff ff ff callq 400560 40058a: 89 c3 mov %eax,%ebx 40058c: 31 c0 xor %eax,%eax 40058e: e8 bd ff ff ff callq 400550 400593: 89 c5 mov %eax,%ebp 400595: 31 c0 xor %eax,%eax 400597: e8 a4 ff ff ff callq 400540 40059c: 41 89 c4 mov %eax,%r12d 40059f: 31 c0 xor %eax,%eax 4005a1: e8 8a ff ff ff callq 400530 4005a6: 44 89 e1 mov %r12d,%ecx 4005a9: 41 89 c0 mov %eax,%r8d 4005ac: 89 ea mov %ebp,%edx 4005ae: 89 de mov %ebx,%esi 4005b0: 48 8b 6c 24 08 mov 0x8(%rsp),%rbp 4005b5: 48 8b 1c 24 mov (%rsp),%rbx 4005b9: 4c 8b 64 24 10 mov 0x10(%rsp),%r12 4005be: bf bc 06 40 00 mov $0x4006bc,%edi 4005c3: 31 c0 xor %eax,%eax 4005c5: 48 83 c4 18 add $0x18,%rsp 4005c9: e9 42 fe ff ff jmpq 400410 ===================================== But optimal: 0000000000400520
: 400520: 48 89 5c 24 e8 mov %rbx,-0x18(%rsp) 400525: 48 89 6c 24 f0 mov %rbp,-0x10(%rsp) 40052a: 31 c0 xor %eax,%eax 40052c: 4c 89 64 24 f8 mov %r12,-0x8(%rsp) 400531: 48 83 ec 18 sub $0x18,%rsp 400535: e8 46 00 00 00 callq 400580 40053a: 89 c3 mov %eax,%ebx 40053c: 31 c0 xor %eax,%eax 40053e: e8 4d 00 00 00 callq 400590 400543: 89 c5 mov %eax,%ebp 400545: 31 c0 xor %eax,%eax 400547: e8 54 00 00 00 callq 4005a0 40054c: 41 89 c4 mov %eax,%r12d 40054f: 31 c0 xor %eax,%eax 400551: e8 5a 00 00 00 callq 4005b0 400556: 44 89 e1 mov %r12d,%ecx 400559: 41 89 c0 mov %eax,%r8d 40055c: 89 ea mov %ebp,%edx 40055e: 89 de mov %ebx,%esi 400560: 48 8b 6c 24 08 mov 0x8(%rsp),%rbp 400565: 48 8b 1c 24 mov (%rsp),%rbx 400569: 4c 8b 64 24 10 mov 0x10(%rsp),%r12 40056e: bf bc 06 40 00 mov $0x4006bc,%edi 400573: 31 c0 xor %eax,%eax 400575: 48 83 c4 18 add $0x18,%rsp 400579: e9 92 fe ff ff jmpq 400410 0000000000400580 : 400580: bf 01 00 00 00 mov $0x1,%edi 400585: 31 c0 xor %eax,%eax 400587: e9 34 00 00 00 jmpq 4005c0 0000000000400590 : 400590: bf 02 00 00 00 mov $0x2,%edi 400595: 31 c0 xor %eax,%eax 400597: e9 24 00 00 00 jmpq 4005c0 00000000004005a0 : 4005a0: bf 03 00 00 00 mov $0x3,%edi 4005a5: 31 c0 xor %eax,%eax 4005a7: e9 14 00 00 00 jmpq 4005c0 00000000004005b0 : 4005b0: bf 04 00 00 00 mov $0x4,%edi 4005b5: 31 c0 xor %eax,%eax 4005b7: e9 04 00 00 00 jmpq 4005c0 00000000004005c0 : 4005c0: 89 f8 mov %edi,%eax 4005c2: c3 retq =========== BTW, how about reordering idea for data? -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40093