public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bruck.michael at googlemail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/64774] New: [ARM/thumb] missed optimization: pc relative ldr used when constant can be derived from register
Date: Sat, 24 Jan 2015 16:00:00 -0000	[thread overview]
Message-ID: <bug-64774-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64774

            Bug ID: 64774
           Summary: [ARM/thumb] missed optimization: pc relative ldr used
                    when constant can be derived from register
           Product: gcc
           Version: 4.9.3
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bruck.michael at googlemail dot com

In the example the second write address of each function can either be
generated using 'str' with an immediate offset or using an adds with an
immediate addend.

The compiler does this for test1-3. For test4-6 it emits a pc-relative ldr
instruction and a 32bit constant. This increases size and likely impacts
execution speed.

cat test.c
void test1()
{
    *(unsigned *)4 = 0x666;
    *(unsigned *)(4 + 4) = 0x666;
}


void test2()
{
    *(unsigned *)4 = 0x666;
    *(unsigned *)(4 + 128) = 0x666;
}

void test3()
{
    *(unsigned *)0x444 = 0x666;
    *(unsigned *)(0x444 + 4) = 0x666;
}


void test4()
{
    *(unsigned *)0x444 = 0x666;
    *(unsigned *)(0x444 + 128) = 0x666;
}

void test5()
{
    *(unsigned *)0x44444444 = 0x666;
    *(unsigned *)(0x44444444 + 4) = 0x666;
}


void test6()
{
    *(unsigned *)0x44444444 = 0x666;
    *(unsigned *)(0x44444444 + 128) = 0x666;
}

arm-none-eabi-gcc -c test.c -mthumb -mcpu=cortex-m0 -mtune=cortex-m0 -Ofast -o
test.o

00000000 <test1>:
   0:    2204          movs    r2, #4
   2:    4b02          ldr    r3, [pc, #8]    ; (c <test1+0xc>)
   4:    6013          str    r3, [r2, #0]
   6:    6053          str    r3, [r2, #4]
   8:    4770          bx    lr
   a:    46c0          nop            ; (mov r8, r8)
   c:    00000666     .word    0x00000666

00000010 <test2>:
  10:    2204          movs    r2, #4
  12:    4b02          ldr    r3, [pc, #8]    ; (1c <test2+0xc>)
  14:    6013          str    r3, [r2, #0]
  16:    3280          adds    r2, #128    ; 0x80
  18:    6013          str    r3, [r2, #0]
  1a:    4770          bx    lr
  1c:    00000666     .word    0x00000666

00000020 <test3>:
  20:    4b02          ldr    r3, [pc, #8]    ; (2c <test3+0xc>)
  22:    4a03          ldr    r2, [pc, #12]    ; (30 <test3+0x10>)
  24:    6013          str    r3, [r2, #0]
  26:    6053          str    r3, [r2, #4]
  28:    4770          bx    lr
  2a:    46c0          nop            ; (mov r8, r8)
  2c:    00000666     .word    0x00000666
  30:    00000444     .word    0x00000444

00000034 <test4>:
  34:    4b02          ldr    r3, [pc, #8]    ; (40 <test4+0xc>)
  36:    4a03          ldr    r2, [pc, #12]    ; (44 <test4+0x10>)
  38:    6013          str    r3, [r2, #0]
  3a:    4a03          ldr    r2, [pc, #12]    ; (48 <test4+0x14>)
  3c:    6013          str    r3, [r2, #0]
  3e:    4770          bx    lr
  40:    00000666     .word    0x00000666
  44:    00000444     .word    0x00000444
  48:    000004c4     .word    0x000004c4

0000004c <test5>:
  4c:    4b02          ldr    r3, [pc, #8]    ; (58 <test5+0xc>)
  4e:    4a03          ldr    r2, [pc, #12]    ; (5c <test5+0x10>)
  50:    6013          str    r3, [r2, #0]
  52:    4a03          ldr    r2, [pc, #12]    ; (60 <test5+0x14>)
  54:    6013          str    r3, [r2, #0]
  56:    4770          bx    lr
  58:    00000666     .word    0x00000666
  5c:    44444444     .word    0x44444444
  60:    44444448     .word    0x44444448

00000064 <test6>:
  64:    4b02          ldr    r3, [pc, #8]    ; (70 <test6+0xc>)
  66:    4a03          ldr    r2, [pc, #12]    ; (74 <test6+0x10>)
  68:    6013          str    r3, [r2, #0]
  6a:    4a03          ldr    r2, [pc, #12]    ; (78 <test6+0x14>)
  6c:    6013          str    r3, [r2, #0]
  6e:    4770          bx    lr
  70:    00000666     .word    0x00000666
  74:    44444444     .word    0x44444444
  78:    444444c4     .word    0x444444c4


Compiled using:
https://launchpad.net/gcc-arm-embedded/4.9/4.9-2014-q4-major/+download/gcc-arm-none-eabi-4_9-2014q4-20141203-win32.exe


             reply	other threads:[~2015-01-24 16:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-24 16:00 bruck.michael at googlemail dot com [this message]
2015-01-28 16:14 ` [Bug target/64774] " rearnsha at gcc dot gnu.org
2015-01-29  2:03 ` bruck.michael at googlemail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-64774-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).