Compile the attached test case with options -Os -mthumb, gcc generates
following code to destruct the array of objects:

__tcf_0:
        .fnstart
.LFB1:
        .save   {r3, r4, r5, lr}
        push    {r3, r4, r5, lr}
.LCFI0:
        ldr     r5, .L5
        mov     r4, r5
        add     r4, r4, #36
        sub     r5, r5, #12
.L2:
        mov     r0, r4
        sub     r4, r4, #12
        bl      _ZN1AD1Ev
        cmp     r4, r5
        bne     .L2
        @ sp needed for prologue
        pop     {r3, r4, r5, pc}
.L6:
        .align  2
.L5:
        .word   .LANCHOR0

It uses a loop to call the destructor of each element of the array. Actually we
can call function __cxa_vec_dtor to destruct the array of objects. So we can
reduce several instructions and the result will be:

        push    {r3, r4, r5, lr}
        ldr     r0, .L5
        mov     r1, 4
        mov     r2, #12
        ldr     r3, .L5+4
        bl      __cxa_vec_dtor
        @ sp needed for prologue
        pop     {r3, r4, r5, pc}
.L6:
        .align  2
.L5:
        .word   .LANCHOR0
        .word   ZN1AD1Ev


-- 
           Summary: use __cxa_vec_dtor instead of loop to reduce code size
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: carrot at google dot com
 GCC build triplet: i686-linux
  GCC host triplet: i686-linux
GCC target triplet: arm-eabi


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42161

Reply via email to