GCC is inefficient when loading constant strings.

The sample code is:
  printf( "\nMCF SPEC CPU2006 version 1.10\n" );

GCC places the constant string a a read-only data section. If compiled with
-fpic, gcc places the string's offset(relative to GOT entry) in GOT table.
To address the string, gcc needs to

load the GOT relative base address
Compute GOT absolute base address
load the string's GOT offset
compute the string's absolute address

gcc emits 4 instructions to get the address of the first string, and 2
instructions for following strings (because the GOT absolute address is the
same for them).

ARM RVCT is more efficient. RVCT places constant string right after the
function in the code section. It only uses one instruction ADR to get the
string address.

000098  a03c              ADR      r0,|L1.396|
00009a  f7fffffe          BL       printf
...
                 |L1.396|
<string constant "\nMCF SPEC CPU2006 version 1.10\n" >


Placing constant strings in global data section enables sharing the strings.
But usually, there is little sharing for long strings. For short strings, the
overhead of loading the short strings through GOT table almost overcome the
savings of sharing the short strings.

Shall we change the placement of constant strings? We can use an option to
choose where to put constant strings. For ARM with -fpic, I think the benefit
of placing constant strings in local constant pool is bigger than the cost.

Any suggestion?


-- 
           Summary: Place constant strings in local constant pool
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jingyu at google dot com
 GCC build triplet: i686-linux-gnu, x86_64-pc-linux-gnu
  GCC host triplet: i686-linux-gnu, x86_64-pc-linux-gnu
GCC target triplet: arm-unknown-eabi


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42962

Reply via email to