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

             Bug #: 51111
           Summary: Optimization bug with array
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: vova7...@mail.ru


Have array like void *__sys_switab_addres[65536];
this array containing pointers to functions.

 │.text:000008FC main 
 │.text:000008FC 
 │.text:000008FC var_3C          = -0x3C                      
 │.text:000008FC                                              
 │.text:000008FC                 STMFD   SP!, {R4,R5,LR}
 │.text:00000900                 LDR     R4, =__sys_switab_addres
 │.text:00000904                 SUB     SP, SP, #0x34
 │.text:00000908                 LDR     R3, [R4]
 │.text:0000090C                 LDR     R5, =_ZL7MAINCSM    
 │.text:00000910                 LDR     R3, [R3,#0x518]
 │.text:00000914                 BLX     R3
 │.text:00000918                 LDR     R3, [R4]       ;duplicate
 │.text:0000091C                 LDR     R1, =aNatalarm      
 │.text:00000920                 LDR     R3, [R3,#0x490]      
 │.text:00000924                 ADD     R0, R5, #0x28        
 │.text:00000928                 BLX     R3 
 │.text:0000092C                 LDR     R3, [R4]       ;duplicate
 │.text:00000930                 ADD     R1, SP, #0x40+var_3C
 │.text:00000934                 MOV     R2, #0
 │.text:00000938                 LDR     R3, [R3,#0x41C]
 │.text:0000093C                 MOV     R0, R5
 │.text:00000940                 BLX     R3
 │.text:00000944                 LDR     R3, [R4]       ;duplicate
 │.text:00000948                 LDR     R3, [R3,#0x51C]
 │.text:0000094C                 BLX     R3
 │.text:00000950                 MOV     R0, #0
 │.text:00000954                 ADD     SP, SP, #0x34
 │.text:00000958                 LDMFD   SP!, {R4,R5,PC}

can be smaller with construction like this:

LDR     R4, =__sys_switab_addres
LDR     R4, [R4]
...
LDR     R3, [R4,#0x518]
...
LDR     R3, [R4,#0x490]  
...
LDR     R3, [R4,#0x490]   
...
LDR     R3, [R4,#0x41C]
...
LDR     R3, [R4,#0x51C]

Reply via email to