http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46279
Summary: cmov not hoisted out of the loop Product: gcc Version: 4.6.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: rtl-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: davi...@gcc.gnu.org Simple test case: extern int gen_int(int); extern void ref_int_p(int*); void kernel3 () { int i; int j; int k; int l; int m; int a[200]; j = gen_int (0); k = gen_int (0); for (i = 0; i < 200; i++) { if (j < k) a[i] = 1; else a[i] = j; } ref_int_p (&a[0]); return; } Code generated by trunk gcc at O2: kernel3: .LFB0: .cfi_startproc pushq %rbx .cfi_def_cfa_offset 16 .cfi_offset 3, -16 xorl %edi, %edi subq $800, %rsp .cfi_def_cfa_offset 816 call gen_int xorl %edi, %edi movl %eax, %ebx call gen_int movq %rsp, %rdx leaq 800(%rsp), %rdi movl $1, %esi .p2align 4,,10 .p2align 3 .L4: cmpl %eax, %ebx movl %esi, %ecx cmovge %ebx, %ecx movl %ecx, (%rdx) addq $4, %rdx cmpq %rdi, %rdx jne .L4 movq %rsp, %rdi call ref_int_p addq $800, %rsp .cfi_def_cfa_offset 16 popq %rbx .cfi_def_cfa_offset 8 ret The loop header is L4. LLVM generates: .Leh_func_begin0: pushq %rbx .Ltmp0: subq $800, %rsp .Ltmp1: xorl %edi, %edi callq gen_int movl %eax, %ebx xorl %edi, %edi callq gen_int cmpl %eax, %ebx movl $1, %eax cmovgel %ebx, %eax xorl %ecx, %ecx .align 16, 0x90 .LBB0_1: movl %eax, (%rsp,%rcx,4) incq %rcx cmpq $200, %rcx jne .LBB0_1 leaq (%rsp), %rdi callq ref_int_p addq $800, %rsp popq %rbx The loop (LBB0_1) is much tighter. David