Bug 41396

Summary: missed space optimization related to basic block reorder
Product: gcc Reporter: Carrot <carrot>
Component: rtl-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: enhancement CC: carrot, dimhen, gabravier, gcc-bugs, icera-sdkteam-gnu, ktietz, pinskia, rguenth
Priority: P3 Keywords: missed-optimization
Version: 4.5.0   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40730
Host: i686-linux Target: arm-eabi
Build: i686-linux Known to work:
Known to fail: Last reconfirmed: 2009-09-18 08:44:20
Attachments: test case

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
.L7:
        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
.L3:
        add     r3, r3, #16
.L2:
        cmp     r3, r4
        bcc     .L7
        mov     r0, #0
        b       .L6      // -----------------END BLOCK A---------
.L9:
        mov     r0, #1
.L6:
        @ 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.
Comment 4 Richard Biener 2019-09-05 09:24:29 UTC
BB reordering is enabled at -Os now using the "simple" (non-STV) algorithm,
but for the testcase I don't see it's better now.