public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/22568] New: Should use cmov in some stituations
@ 2005-07-20 14:21 arndt at jjj dot de
  2005-07-20 14:27 ` [Bug c++/22568] " matz at suse dot de
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: arndt at jjj dot de @ 2005-07-20 14:21 UTC (permalink / raw)
  To: gcc-bugs

With (ulong a, ulong b) and code like
if ( a<b )  { ulong t=a; a=b; b=t; }
gcc should (if a and b are in registers already)
not emit a conditional jump but code like
MOV a, t;
CMP a, b;
CMOVcc b, a;
CMOVcc t, b;

Other such examples are easily found.  If I got it correctly, gcc
emits CMOVcc in just one situation, the conditional assignment.

Machine is AMD64, OS is SuSE Linux 9.3
gcc (GCC) 3.3.5 20050117 (prerelease) (SUSE Linux)

-- 
           Summary: Should use cmov in some stituations
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: arndt at jjj dot de
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/22568] Should use cmov in some stituations
  2005-07-20 14:21 [Bug c++/22568] New: Should use cmov in some stituations arndt at jjj dot de
@ 2005-07-20 14:27 ` matz at suse dot de
  2005-07-20 15:14 ` [Bug rtl-optimization/22568] " pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: matz at suse dot de @ 2005-07-20 14:27 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From matz at suse dot de  2005-07-20 14:20 -------
This still happens with 4.1.  I also can't make it use two cmovs, by changing 
the source a bit, e.g. like: 
 
typedef unsigned long ulong; 
extern ulong use (ulong, ulong); 
ulong f(ulong a, ulong b) 
{ 
  ulong tmp = a; 
  if (a < b) { 
    a = b; 
    b = tmp; 
  } 
  return use (a, b); 
} 
 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |matz at suse dot de


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


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

* [Bug rtl-optimization/22568] Should use cmov in some stituations
  2005-07-20 14:21 [Bug c++/22568] New: Should use cmov in some stituations arndt at jjj dot de
  2005-07-20 14:27 ` [Bug c++/22568] " matz at suse dot de
@ 2005-07-20 15:14 ` pinskia at gcc dot gnu dot org
  2005-08-31  9:42 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-20 15:14 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-07-20 15:11 -------
IIRC ifcvt is not smart enough to do this.

Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
          Component|c++                         |rtl-optimization
     Ever Confirmed|                            |1
           Keywords|                            |missed-optimization
   Last reconfirmed|0000-00-00 00:00:00         |2005-07-20 15:11:41
               date|                            |


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


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

* [Bug rtl-optimization/22568] Should use cmov in some stituations
  2005-07-20 14:21 [Bug c++/22568] New: Should use cmov in some stituations arndt at jjj dot de
  2005-07-20 14:27 ` [Bug c++/22568] " matz at suse dot de
  2005-07-20 15:14 ` [Bug rtl-optimization/22568] " pinskia at gcc dot gnu dot org
@ 2005-08-31  9:42 ` rguenth at gcc dot gnu dot org
  2005-09-01 12:38 ` rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2005-08-31  9:42 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rguenth at gcc dot gnu dot org  2005-08-31 09:40 -------
With new tree-codes instead of using COND_EXPR we may use the tree-vectorizers
if-conversion and make expand preserve the conditional moves.

Also it shouldn't be too hard to hack rtl if-conversion to handle the case of
exactly two set's in the then/else block, too, and that may turn out to be
profitable always.  Is there any arch whose conditional move will kill
condition codes?  RTL is not my best friend (yet), but ifcvt doens't look too bad
either ;)

-- 


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


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

* [Bug rtl-optimization/22568] Should use cmov in some stituations
  2005-07-20 14:21 [Bug c++/22568] New: Should use cmov in some stituations arndt at jjj dot de
                   ` (2 preceding siblings ...)
  2005-08-31  9:42 ` rguenth at gcc dot gnu dot org
@ 2005-09-01 12:38 ` rguenth at gcc dot gnu dot org
  2005-09-02  9:47 ` bonzini at gcc dot gnu dot org
  2005-09-02  9:54 ` rguenth at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2005-09-01 12:38 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rguenth at gcc dot gnu dot org  2005-09-01 12:38 -------
I have a patch that for

int a,b;
void foo(void)
{
  int x;
  if (a<b) x=a,a=b,b=x;
}

produces

bar:
        movl    a, %eax
        movl    b, %edx
        cmpl    %edx, %eax
        movl    %eax, %ecx
        cmovl   %edx, %ecx
        cmovge  b, %eax
        movl    %ecx, a
        movl    %eax, b
        ret

but it produces horrible code if the stuff is not available in pseudos
already.  (i.e. we miss load/store sinking)

-- 


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


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

* [Bug rtl-optimization/22568] Should use cmov in some stituations
  2005-07-20 14:21 [Bug c++/22568] New: Should use cmov in some stituations arndt at jjj dot de
                   ` (3 preceding siblings ...)
  2005-09-01 12:38 ` rguenth at gcc dot gnu dot org
@ 2005-09-02  9:47 ` bonzini at gcc dot gnu dot org
  2005-09-02  9:54 ` rguenth at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: bonzini at gcc dot gnu dot org @ 2005-09-02  9:47 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bonzini at gcc dot gnu dot org  2005-09-02 09:47 -------
Richard, can you write a case where it produces awful code?

-- 


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


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

* [Bug rtl-optimization/22568] Should use cmov in some stituations
  2005-07-20 14:21 [Bug c++/22568] New: Should use cmov in some stituations arndt at jjj dot de
                   ` (4 preceding siblings ...)
  2005-09-02  9:47 ` bonzini at gcc dot gnu dot org
@ 2005-09-02  9:54 ` rguenth at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2005-09-02  9:54 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rguenth at gcc dot gnu dot org  2005-09-02 09:54 -------
Blindly applying ifcvt to something like

int a,b;
void foo(int flag)
{
  int x;
  if (flag)
    x=a,a=b,b=x;
}

because we're presented with

  if (flag)
  {
    int reg_a = a;
    x = reg_a;
    int reg_b = b;
    a = reg_b;
    b = x;
  }

and we get cmovs for loading a,b into pseudos instead of
loading them unconditionally.  F.i.

int a,b;
void foobar(int flag)
{
  if (flag)
    a = b;
}

will become

foobar:
        movl    4(%esp), %eax   # flag, flag
        testl   %eax, %eax      # flag
        cmovne  b, %edx # b,, b
        movl    a, %eax # a, tmp61
        cmovne  %edx, %eax      # b,, tmp61
        movl    %eax, a # tmp61, a
        ret

notice how we special-cased the _store_ to use a temporary.  I'll
try applying the same for loads.

-- 


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


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

end of thread, other threads:[~2005-09-02  9:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-20 14:21 [Bug c++/22568] New: Should use cmov in some stituations arndt at jjj dot de
2005-07-20 14:27 ` [Bug c++/22568] " matz at suse dot de
2005-07-20 15:14 ` [Bug rtl-optimization/22568] " pinskia at gcc dot gnu dot org
2005-08-31  9:42 ` rguenth at gcc dot gnu dot org
2005-09-01 12:38 ` rguenth at gcc dot gnu dot org
2005-09-02  9:47 ` bonzini at gcc dot gnu dot org
2005-09-02  9:54 ` rguenth at gcc dot gnu dot 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).