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

             Bug #: 52256
           Summary: CSE the memory load from both branches of if statement
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: car...@google.com
            Target: arm-unknown-linux-gnueabi


In mcfutils.c of mcf from SPEC, function refresh_potential() contains following
code snippet

...
 85             if( node->orientation == UP )
 86                 node->potential = node->basic_arc->cost +
node->pred->potential;
 87             else /* == DOWN */
 88             {
 89                 node->potential = node->pred->potential -
node->basic_arc->cost;
 90                 checksum++;
 91             }
...


Compile it with options -march=armv7-a -mthumb -Os, gcc 4.7 generates

...
 71         ldr     r2, [r3, #4]
 72         ldr     r4, [r3, #12]
 73         cmp     r2, #1
 74         ldr     r2, [r3, #24]
 75         bne     .L8

 76         ldr     r5, [r2, #0]            //common memory load
 77         ldr     r2, [r4, #0]            //common memory load
 78         adds    r2, r5, r2
 79         str     r2, [r3, #0]
 80         b       .L9
 81 .L8:
 82         ldr     r4, [r4, #0]            //common memory load
 83         adds    r0, r0, #1
 84         ldr     r2, [r2, #0]            //common memory load
 85         subs    r2, r4, r2
 86         str     r2, [r3, #0]
 87 .L9:
...

The memory node->basic_arc->cost and node->pred->potential are loaded in both
branches of the if statement, so we can CSE them. But current gcc CSE only
node->basic_arc and node->pred.

Reply via email to