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: unassignedb...@nondot.org
          Reporter: weimi...@codeaurora.org
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to