public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/46279] New: cmov not hoisted out of the loop
@ 2010-11-02 21:28 davidxl at gcc dot gnu.org
  2010-11-02 21:31 ` [Bug rtl-optimization/46279] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: davidxl at gcc dot gnu.org @ 2010-11-02 21:28 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: davidxl@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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-11-11  9:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-02 21:28 [Bug rtl-optimization/46279] New: cmov not hoisted out of the loop davidxl at gcc dot gnu.org
2010-11-02 21:31 ` [Bug rtl-optimization/46279] " pinskia at gcc dot gnu.org
2010-11-02 21:33 ` pinskia at gcc dot gnu.org
2010-11-02 21:33 ` xinliangli at gmail dot com
2010-11-02 21:45 ` jakub at gcc dot gnu.org
2010-11-02 21:46 ` pinskia at gcc dot gnu.org
2010-11-03 10:58 ` rguenth at gcc dot gnu.org
2021-07-20  0:45 ` pinskia at gcc dot gnu.org
2022-11-11  9:32 ` tnfchris at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).