Bug 41396 - missed space optimization related to basic block reorder
Summary: missed space optimization related to basic block reorder
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.5.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: missed-optimization
Depends on:
Reported: 2009-09-18 07:56 UTC by Carrot
Modified: 2014-06-11 21:04 UTC (History)
4 users (show)

See Also:
Host: i686-linux
Target: arm-eabi
Build: i686-linux
Known to work:
Known to fail:
Last reconfirmed: 2009-09-18 08:44:20

test case (321 bytes, text/x-csrc)
2009-09-18 07:57 UTC, Carrot

Note You need to log in before you can comment on or make changes to this bug.
Description Carrot 2009-09-18 07:56:08 UTC
Compile the attached source code with options -march=armv5te -mthumb -Os, I got

        push    {r4, lr}
        ldr     r4, [r0, #8]
        ldr     r3, [r0, #4]
        b       .L2
        ldr     r2, [r3, #8]
        ldr     r1, [r2]
        ldr     r2, [r3]
        add     r2, r1, r2
        ldr     r1, [r3, #4]
        ldr     r1, [r1]
        sub     r2, r2, r1
        ldr     r1, [r3, #12]
        cmp     r1, #1
        beq     .L4
        cmp     r1, #2
        bne     .L3
        b       .L12       // C
.L4:                       // ---------BEGIN BLOCK B
        ldr     r1, [r0]
        neg     r1, r1
        cmp     r2, r1
        bge     .L3
        b       .L9        // ----------END BLOCK B
.L12:                      // ---------------BEGIN BLOCK A-------
        ldr     r1, [r0]
        cmp     r2, r1
        bgt     .L9
        add     r3, r3, #16
        cmp     r3, r4
        bcc     .L7
        mov     r0, #0
        b       .L6      // -----------------END BLOCK A---------
        mov     r0, #1
        @ sp needed for prologue
        pop     {r4, pc}

If we change the order of block A and block B, we can remove 2 branch instructions, inst C and another inst at the end of block B.

Need new basic block reorder algorithm for code size optimization?
Comment 1 Carrot 2009-09-18 07:57:00 UTC
Created attachment 18602 [details]
test case
Comment 2 Andrew Pinski 2009-09-18 07:57:25 UTC
yes, currently at -Os basic block reordering is disabled :).
Comment 3 Richard Biener 2009-09-18 08:44:20 UTC
So, confirmed.