Bug 42671 - Thumb2 generate more instructions than Thumb1 to load GOT address
Summary: Thumb2 generate more instructions than Thumb1 to load GOT address
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-01-09 11:23 UTC by Carrot
Modified: 2010-02-01 15:40 UTC (History)
2 users (show)

See Also:
Host: i686-linux
Target: arm-eabi
Build: i686-linux
Known to work:
Known to fail:
Last reconfirmed: 2010-01-11 14:30:01


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carrot 2010-01-09 11:23:55 UTC
The simple test case is:

extern int i;
void foo(int j)
{
  i = j;
}


Compile it with options -march=armv5te -mthumb -Os -fpic, gcc generates:

foo:
        ldr     r3, .L3
        ldr     r2, .L3+4
.LPIC0:
        add     r3, pc                // A
        ldr     r3, [r3, r2]
        @ sp needed for prologue
        str     r0, [r3]
        bx      lr
.L4:
        .align  2
.L3:
        .word   _GLOBAL_OFFSET_TABLE_-(.LPIC0+4)
        .word   i(GOT)


Compile it with options -march=armv7 -mthumb -Os -fpic, gcc generates:

foo:
        ldr     r3, .L3
        .align  2
.LPIC0:
        adr     r2, .LPIC0 + 4      // B
        adds    r3, r3, r2          // C
        ldr     r2, .L3+4
        ldr     r3, [r3, r2]
        str     r0, [r3, #0]
        bx      lr
.L4:
        .align  2
.L3:
        .word   _GLOBAL_OFFSET_TABLE_-(.LPIC0+4)
        .word   i(GOT)


The different instructions are marked with A and BC. It is caused by different codes for Thumb2 and Thumb1 in function arm_load_pic_register. Actually for Thumb2 we should generate similar codes as Thumb1.
Comment 1 Nick Clifton 2010-01-27 09:19:54 UTC
Subject: Bug 42671

Author: nickc
Date: Wed Jan 27 09:19:36 2010
New Revision: 156276

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156276
Log:
        PR target/42671
        * config/arm/arm.c (arm_load_pic_register): Use the same code
        sequence with Thumb2 as for Thumb1.
        * config/arm/arm.md (pic_add_dot_plus_four): Enable this pattern
        for all Thumb varieties.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/arm/arm.c
    trunk/gcc/config/arm/arm.md

Comment 2 Richard Earnshaw 2010-02-01 15:34:39 UTC
Fixed in trunk with http://gcc.gnu.org/ml/gcc-patches/2010-01/msg01403.html