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

* [Bug rtl-optimization/46279] cmov not hoisted out of the loop
  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 ` pinskia at gcc dot gnu.org
  2010-11-02 21:33 ` xinliangli at gmail dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2010-11-02 21:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-11-02 21:31:03 UTC ---
Try -O3.  -O3 enables -funswitch-loops which does this.


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

* [Bug rtl-optimization/46279] cmov not hoisted out of the loop
  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 ` xinliangli at gmail dot com
  2010-11-02 21:33 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: xinliangli at gmail dot com @ 2010-11-02 21:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from davidxl <xinliangli at gmail dot com> 2010-11-02 21:33:37 UTC ---
Hoisting cmov out of the loop is more efficient ( I tried O3 before filing
the bug).

David

On Tue, Nov 2, 2010 at 2:31 PM, pinskia at gcc dot gnu.org <
gcc-bugzilla@gcc.gnu.org> wrote:

> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46279
>
> --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-11-02
> 21:31:03 UTC ---
> Try -O3.  -O3 enables -funswitch-loops which does this.
>
> --
> Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug.
>


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

* [Bug rtl-optimization/46279] cmov not hoisted out of the loop
  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 ` xinliangli at gmail dot com
@ 2010-11-02 21:33 ` pinskia at gcc dot gnu.org
  2010-11-02 21:45 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2010-11-02 21:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-11-02 21:33:18 UTC ---
Though -O3 generates much larger code.  What needs to be done is that one thing
really:
      if (j < k)
        a[i] = 1;
      else
        a[i] = j;

Needs to be transformed into:
      if (j < k)
        tmp = 1;
      else
        tmp = j;
      a[i] = tmp;

And then it should work correctly.  I think there is already a bug about that.


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

* [Bug rtl-optimization/46279] cmov not hoisted out of the loop
  2010-11-02 21:28 [Bug rtl-optimization/46279] New: cmov not hoisted out of the loop davidxl at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2010-11-02 21:33 ` pinskia at gcc dot gnu.org
@ 2010-11-02 21:45 ` jakub at gcc dot gnu.org
  2010-11-02 21:46 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2010-11-02 21:45 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2010-11-02 21:44:57 UTC ---
PR46009 ?


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

* [Bug rtl-optimization/46279] cmov not hoisted out of the loop
  2010-11-02 21:28 [Bug rtl-optimization/46279] New: cmov not hoisted out of the loop davidxl at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2010-11-02 21:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-11-02 21:46:18 UTC ---
(In reply to comment #4)
> PR46009 ?

That one and I thought there was one more but of course I cannot find it.


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

* [Bug rtl-optimization/46279] cmov not hoisted out of the loop
  2010-11-02 21:28 [Bug rtl-optimization/46279] New: cmov not hoisted out of the loop davidxl at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2010-11-03 10:58 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2010.11.03 10:58:33
     Ever Confirmed|0                           |1

--- Comment #6 from Richard Guenther <rguenth at gcc dot gnu.org> 2010-11-03 10:58:33 UTC ---
Store sinking.


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

* [Bug rtl-optimization/46279] cmov not hoisted out of the loop
  2010-11-02 21:28 [Bug rtl-optimization/46279] New: cmov not hoisted out of the loop davidxl at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-20  0:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46279

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
         Depends on|                            |89430
   Target Milestone|---                         |8.0
             Status|NEW                         |RESOLVED

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed for GCC 8, by one of the patches to tree-ssa-phiopt.c
(cond_store_replacement).


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89430
[Bug 89430] A missing ifcvt optimization to generate csel

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

* [Bug rtl-optimization/46279] cmov not hoisted out of the loop
  2010-11-02 21:28 [Bug rtl-optimization/46279] New: cmov not hoisted out of the loop davidxl at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2021-07-20  0:45 ` pinskia at gcc dot gnu.org
@ 2022-11-11  9:32 ` tnfchris at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: tnfchris at gcc dot gnu.org @ 2022-11-11  9:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46279
Bug 46279 depends on bug 89430, which changed state.

Bug 89430 Summary: A missing ifcvt optimization to generate csel
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89430

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

^ 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 ` xinliangli at gmail dot com
2010-11-02 21:33 ` pinskia at gcc dot gnu.org
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).