http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46208
Summary: TARGET_PROMOTE_PROTOTYPES for SPARC V8 Product: gcc Version: 4.5.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassig...@gcc.gnu.org ReportedBy: jorge.pe...@invia.fr Based on Ian Taylor's recommendation (http://goo.gl/yAoL) ******************* Problem summary (http://goo.gl/Mcrm) When a caller function calls a callee function with short or char arguments, the arguments are casted twice: inside the caller function and inside the callee function, see the example. It is a waste of performance in code density and speed! Example: sparc-elf-gcc -o test.elf test.c -Os short somme(char a, short b){ int i; for (i=0; i<b; i++){ a+=a; } return a+b; } short somme2(char a, short b){ int i; for (i=0; i<b; i++){ a+=b; } return a+2*b; } int main(){ volatile short b=1; volatile char a=1, c=1; b=somme(a,b); b=somme(c,b); b=somme(a,c); b=somme2(a,b); b=somme2(c,b); b=somme2(a,c); return 0; } 0001024c <somme>: 1024c: 85 2a 60 10 sll %o1, 0x10, %g2 10250: 82 10 20 00 clr %g1 10254: 10 80 00 03 b 10260 <somme+0x14> 10258: 85 38 a0 10 sra %g2, 0x10, %g2 1025c: 82 00 60 01 inc %g1 10260: 80 a0 40 02 cmp %g1, %g2 10264: 26 bf ff fe bl,a 1025c <somme+0x10> 10268: 91 2a 20 01 sll %o0, 1, %o0 1026c: 91 2a 20 18 sll %o0, 0x18, %o0 10270: 91 3a 20 18 sra %o0, 0x18, %o0 10274: 81 c3 e0 08 retl 10278: 90 02 40 08 add %o1, %o0, %o0 000102b4 <main>: 102b4: 9d e3 bf 98 save %sp, -104, %sp 102b8: 82 10 20 01 mov 1, %g1 102bc: c2 37 bf fc sth %g1, [ %fp + -4 ] 102c0: c2 2f bf ff stb %g1, [ %fp + -1 ] 102c4: c2 2f bf fe stb %g1, [ %fp + -2 ] 102c8: d0 0f bf ff ldub [ %fp + -1 ], %o0 102cc: d2 17 bf fc lduh [ %fp + -4 ], %o1 102d0: 91 2a 20 18 sll %o0, 0x18, %o0 102d4: 93 2a 60 10 sll %o1, 0x10, %o1 102d8: 91 3a 20 18 sra %o0, 0x18, %o0 102dc: 7f ff ff dc call 1024c <somme> 102e0: 93 3a 60 10 sra %o1, 0x10, %o1 ... **************** Fix proposal (http://goo.gl/0mJ1) we modified the function *TARGET_PROMOTE_PROTOTYPES *(http://goo.gl/2pQQ) and set it to the default value which is FALSE. static bool sparc_promote_prototypes (const_tree fntype ATTRIBUTE_UNUSED) { return TARGET_ARCH32 ? true : false; } was replaced by static bool sparc_promote_prototypes (const_tree fntype ATTRIBUTE_UNUSED) { return false; } Then we re-compiled GCC 4.5.1 for SPARC V8 and the results for the previously mentioned test.c are short somme(char a, short b){ int i; for (i=0; i<b; i++){ a+=a; } return a+b; } short somme2(char a, short b){ int i; for (i=0; i<b; i++){ a+=b; } return a+2*b; } int main(){ volatile short b=1; volatile char a=1, c=1; b=somme(a,b); b=somme(c,b); b=somme(a,c); b=somme2(a,b); b=somme2(c,b); b=somme2(a,c); b=somme2(a,c*2); b=somme2(a,c*3); b=somme2(a,c*4); return 0; } 0001024c <somme>: 1024c: 85 2a 60 10 sll %o1, 0x10, %g2 10250: 82 10 20 00 clr %g1 10254: 10 80 00 03 b 10260 <somme+0x14> 10258: 85 38 a0 10 sra %g2, 0x10, %g2 1025c: 82 00 60 01 inc %g1 10260: 80 a0 40 02 cmp %g1, %g2 10264: 26 bf ff fe bl,a 1025c <somme+0x10> 10268: 91 2a 20 01 sll %o0, 1, %o0 1026c: 91 2a 20 18 sll %o0, 0x18, %o0 10270: 91 3a 20 18 sra %o0, 0x18, %o0 10274: 81 c3 e0 08 retl 10278: 90 02 00 09 add %o0, %o1, %o0 0001027c <somme2>: 1027c: 87 2a 60 10 sll %o1, 0x10, %g3 10280: 82 10 20 00 clr %g1 10284: 87 38 e0 10 sra %g3, 0x10, %g3 10288: 10 80 00 03 b 10294 <somme2+0x18> 1028c: 84 10 00 09 mov %o1, %g2 10290: 82 00 60 01 inc %g1 10294: 80 a0 40 03 cmp %g1, %g3 10298: 26 bf ff fe bl,a 10290 <somme2+0x14> 1029c: 90 02 00 02 add %o0, %g2, %o0 102a0: 93 2a 60 01 sll %o1, 1, %o1 102a4: 91 2a 20 18 sll %o0, 0x18, %o0 102a8: 91 3a 20 18 sra %o0, 0x18, %o0 102ac: 81 c3 e0 08 retl 102b0: 90 02 40 08 add %o1, %o0, %o0 000102b4 <main>: 102b4: 9d e3 bf 98 save %sp, -104, %sp 102b8: 82 10 20 01 mov 1, %g1 102bc: c2 37 bf fc sth %g1, [ %fp + -4 ] 102c0: c2 2f bf ff stb %g1, [ %fp + -1 ] 102c4: c2 2f bf fe stb %g1, [ %fp + -2 ] 102c8: d0 0f bf ff ldub [ %fp + -1 ], %o0 102cc: d2 17 bf fc lduh [ %fp + -4 ], %o1 102d0: 7f ff ff df call 1024c <somme> 102d4: 01 00 00 00 nop 102d8: d0 37 bf fc sth %o0, [ %fp + -4 ] 102dc: d0 0f bf fe ldub [ %fp + -2 ], %o0 102e0: d2 17 bf fc lduh [ %fp + -4 ], %o1 102e4: 7f ff ff da call 1024c <somme> 102e8: 01 00 00 00 nop 102ec: d0 37 bf fc sth %o0, [ %fp + -4 ] 102f0: d0 0f bf ff ldub [ %fp + -1 ], %o0 102f4: d2 0f bf fe ldub [ %fp + -2 ], %o1 102f8: 93 2a 60 18 sll %o1, 0x18, %o1 102fc: 7f ff ff d4 call 1024c <somme> 10300: 93 3a 60 18 sra %o1, 0x18, %o1 10304: d0 37 bf fc sth %o0, [ %fp + -4 ] 10308: d0 0f bf ff ldub [ %fp + -1 ], %o0 1030c: d2 17 bf fc lduh [ %fp + -4 ], %o1 10310: 7f ff ff db call 1027c <somme2> 10314: 01 00 00 00 nop 10318: d0 37 bf fc sth %o0, [ %fp + -4 ] 1031c: d0 0f bf fe ldub [ %fp + -2 ], %o0 10320: d2 17 bf fc lduh [ %fp + -4 ], %o1 10324: 7f ff ff d6 call 1027c <somme2> 10328: 01 00 00 00 nop 1032c: d0 37 bf fc sth %o0, [ %fp + -4 ] 10330: d0 0f bf ff ldub [ %fp + -1 ], %o0 10334: d2 0f bf fe ldub [ %fp + -2 ], %o1 10338: 93 2a 60 18 sll %o1, 0x18, %o1 1033c: 7f ff ff d0 call 1027c <somme2> 10340: 93 3a 60 18 sra %o1, 0x18, %o1 10344: d0 37 bf fc sth %o0, [ %fp + -4 ] 10348: d0 0f bf ff ldub [ %fp + -1 ], %o0 1034c: d2 0f bf fe ldub [ %fp + -2 ], %o1 10350: 93 2a 60 18 sll %o1, 0x18, %o1 10354: 7f ff ff ca call 1027c <somme2> 10358: 93 3a 60 17 sra %o1, 0x17, %o1 1035c: d0 37 bf fc sth %o0, [ %fp + -4 ] 10360: d0 0f bf ff ldub [ %fp + -1 ], %o0 10364: c2 0f bf fe ldub [ %fp + -2 ], %g1 10368: 83 28 60 18 sll %g1, 0x18, %g1 1036c: 83 38 60 18 sra %g1, 0x18, %g1 10370: 93 28 60 01 sll %g1, 1, %o1 10374: 7f ff ff c2 call 1027c <somme2> 10378: 92 02 40 01 add %o1, %g1, %o1 1037c: b0 10 20 00 clr %i0 10380: d0 37 bf fc sth %o0, [ %fp + -4 ] 10384: d0 0f bf ff ldub [ %fp + -1 ], %o0 10388: d2 0f bf fe ldub [ %fp + -2 ], %o1 1038c: 93 2a 60 18 sll %o1, 0x18, %o1 10390: 7f ff ff bb call 1027c <somme2> 10394: 93 3a 60 16 sra %o1, 0x16, %o1 10398: d0 37 bf fc sth %o0, [ %fp + -4 ] 1039c: 81 c7 e0 08 ret 103a0: 81 e8 00 00 restore this reduced the size of the main by 96 bytes which is huge taking into account that this is a dummy example. Thanks for your help, Best regards, Jorge Perez