[llvm-bugs] [Bug 31233] New: [ARM] redundant CP entries

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 1 16:35:53 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=31233

            Bug ID: 31233
           Summary: [ARM] redundant CP entries
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: weimingz at codeaurora.org
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

for test.c:

int g;

void foo() {
  ++g;
}

void bar() {
  --g;
}

clang -mcpu=cortex-m3 -target armv7m-linux-gnueabi -c -Os test.c -o test.llvm.o

it generates:

@ BB#0:                                 @ %entry
    movw    r0, :lower16:g
    movt    r0, :upper16:g
    ldr    r1, [r0]
    adds    r1, #1
    str    r1, [r0]
    bx    lr
.Lfunc_end0:
    .size    foo, .Lfunc_end0-foo
    .cantunwind
    .fnend

    .globl    bar
    .p2align    1
    .type    bar,%function
    .code    16                      @ @bar
    .thumb_func
bar:
    .fnstart
@ BB#0:                                 @ %entry
    movw    r0, :lower16:g
    movt    r0, :upper16:g
    ldr    r1, [r0]
    subs    r1, #1
    str    r1, [r0]
    bx    lr
.Lfunc_end1:
    .size    bar, .Lfunc_end1-bar
    .cantunwind
    .fnend

First, it use movw/movt for each GV access. 

By using "-mno-movt", it generates one "ldr" plus one CP entry.

However, for every function, it generates one CP entry for each gv it uses:

@ BB#0:                                 @ %entry
    ldr    r0, .LCPI0_0
    ldr    r1, [r0]
    adds    r1, #1
    str    r1, [r0]
    bx    lr
    .p2align    2
@ BB#1:
.LCPI0_0:
    .long    g
.Lfunc_end0:
    .size    foo, .Lfunc_end0-foo
    .cantunwind
    .fnend

    .globl    bar
    .p2align    2
    .type    bar,%function
    .code    16                      @ @bar
    .thumb_func
bar:
    .fnstart
@ BB#0:                                 @ %entry
    ldr    r0, .LCPI1_0
    ldr    r1, [r0]
    subs    r1, #1
    str    r1, [r0]
    bx    lr
    .p2align    2
@ BB#1:
.LCPI1_0:                   ================> redundent CP entry here
    .long    g


For a module where each functions access a lot of GVs, a lot of space are
wasted.

Ideally, they should share the same cp.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20161202/fea015cd/attachment.html>


More information about the llvm-bugs mailing list