http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46236
Summary: Local aggregate not eliminated Product: gcc Version: 4.6.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: davi...@gcc.gnu.org CC: xinlian...@gmail.com Simple Test case: struct A { int a[100]; }; const struct A aa = {1,1,1}; int foo(int i) { int s = 0; struct A a; a = aa; s = a.a[i]; if (i > 5) s+=a.a[i]; return s; } // Trunk gcc generates: (O2) foo: .LFB0: .cfi_startproc subq $280, %rsp .cfi_def_cfa_offset 288 movl %edi, %edx xorl %eax, %eax leaq -120(%rsp), %rdi cmpl $6, %edx movl $50, %ecx rep stosq movl $1, -120(%rsp) movl $1, -116(%rsp) movl $1, -112(%rsp) movslq %edx, %rax movl -120(%rsp,%rax,4), %eax leal (%rax,%rax), %ecx cmovge %ecx, %eax addq $280, %rsp .cfi_def_cfa_offset 8 ret // Trunk LLVM generates: (O2) foo: .Leh_func_begin0: movslq %edi, %rcx movl aa(,%rcx,4), %eax cmpl $6, %ecx jl .LBB0_2 addl %eax, %eax .LBB0_2: ret