http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49781
Summary: Unnecessary lea in x32 mode Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassig...@gcc.gnu.org ReportedBy: hjl.to...@gmail.com [hjl@gnu-6 pr47383]$ cat x.i static int heap[2*(256 +1+29)+1]; static int heap_len; static int heap_max; void __attribute__ ((noinline)) foo (int elems) { int n, m; int max_code = -1; int node = elems; heap_len = 0, heap_max = (2*(256 +1+29)+1); for (n = 0; n < elems; n++) heap[++heap_len] = max_code = n; do { n = heap[1]; heap[1] = heap[heap_len--]; m = heap[1]; heap[--heap_max] = n; heap[--heap_max] = m; } while (heap_len >= 2); } int main () { foo (286); return 0; } [hjl@gnu-6 pr47383]$ make x.s /export/build/gnu/gcc-x32/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/gcc-x32/build-x86_64-linux/gcc/ -S -o x.s -mx32 -O2 -fPIC x.i [hjl@gnu-6 pr47383]$ cat x.s .file "x.i" .text .p2align 4,,15 .globl foo .type foo, @function foo: .LFB0: .cfi_startproc xorl %eax, %eax testl %edi, %edi pushq %rbx .cfi_def_cfa_offset 16 .cfi_offset 3, -16 leal 4+heap(%rip), %ecx jle .L10 .p2align 4,,10 .p2align 3 .L7: leal (%rcx,%rax,4), %edx movl %eax, (%rdx) addl $1, %eax cmpl %edi, %eax jne .L7 leal -1(%rdi), %ecx .L3: leal -1(%rdi), %eax movl $573, %esi leal 2296+heap(%rip), %r11d leal 2292+heap(%rip), %r10d leal heap(%rip), %ebx jmp .L5 .p2align 4,,10 .p2align 3 .L11: leal (%rbx,%rax,4), %edx subl $1, %eax movl (%rdx), %ecx .L5: movl %eax, %edx movl 4+heap(%rip), %r9d subl $2, %esi subl %edi, %edx movl %ecx, 4+heap(%rip) sall $3, %edx leal (%r11,%rdx), %r8d addl %r10d, %edx cmpl $1, %eax movl %r9d, (%r8) movl %ecx, (%rdx) jg .L11 movl %eax, heap_len(%rip) movl %esi, heap_max(%rip) popq %rbx .cfi_remember_state .cfi_def_cfa_offset 8 ret .L10: .cfi_restore_state movl heap(%rip), %ecx xorl %edi, %edi jmp .L3 .cfi_endproc .LFE0: .size foo, .-foo .section .text.startup,"ax",@progbits .p2align 4,,15 .globl main .type main, @function main: .LFB1: .cfi_startproc subq $8, %rsp .cfi_def_cfa_offset 16 movl $286, %edi call foo@PLT xorl %eax, %eax addq $8, %rsp .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE1: .size main, .-main .local heap_len .comm heap_len,4,4 .local heap_max .comm heap_max,4,4 .local heap .comm heap,2292,32 .ident "GCC: (GNU) 4.7.0 20110718 (experimental)" .section .note.GNU-stack,"",@progbits [hjl@gnu-6 pr47383]$ Many lea insns can be combined with the load/store insn followed.