[llvm-bugs] [Bug 36539] New: Code-size improvement possibilities for loop lowering

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Feb 27 07:16:13 PST 2018


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

            Bug ID: 36539
           Summary: Code-size improvement possibilities for loop lowering
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: gaborb at inf.u-szeged.hu
                CC: llvm-bugs at lists.llvm.org

GCC (with -Os) produces smaller code than LLVM (with -Oz) when lowering loops
with indexes known at compile-time.

Examples:
(Note: these have been generated for ARM targets but the same happens when
targeting x86_64)

* Loops that known at compile-time to be only executed once
** GCC eliminates the loop altogether

Source:
  void func() 
  {
    for (int i = 9; i < 10; i++) {
      putchar(251);
    }
  }

GCC generated assembly code:
  func: 
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        push    {r4, lr}
        movs    r0, #251
        bl      putchar
        @ sp needed
        pop     {r4, pc}

LLVM generated assembly code:
  func: 
        .fnstart
        .save   {r4, r6, r7, lr}
        push    {r4, r6, r7, lr}
        .setfp  r7, sp, #8
        add     r7, sp, #8
        movs    r4, #1
        b       .LBB0_2
  .LBB0_1:
        movs    r0, #251
        bl      putchar
        subs    r4, r4, #1
  .LBB0_2:
        cmp     r4, #0
        bne     .LBB0_1
        pop     {r4, r6, r7, pc}

######################################################

* Loops with condition variables known at compile-time
* (These are guaranteed to be executed at least once)
** GCC can eliminate one jump instruction

Source:
  void func() 
  {
    int i = 0;
    while (i < 10) {
      putchar(251);
      i++;
    }
  }

GCC generated assembly code:
  func: 
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        push    {r4, lr}
        movs    r4, #10
  .L2:
        movs    r0, #251
        subs    r4, r4, #1
        bl      putchar
        cmp     r4, #0
        bne     .L2
        @ sp needed
        pop     {r4, pc}

LLVM generated assembly code:
  func: 
        .fnstart
        .save   {r4, r6, r7, lr}
        push    {r4, r6, r7, lr}
        .setfp  r7, sp, #8
        add     r7, sp, #8
        movs    r4, #10
        b       .LBB0_2
  .LBB0_1:
        movs    r0, #251
        bl      putchar
        subs    r4, r4, #1
  .LBB0_2:
        cmp     r4, #0
        bne     .LBB0_1
        pop     {r4, r6, r7, pc}

-- 
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/20180227/e6b0e3e0/attachment.html>


More information about the llvm-bugs mailing list