public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/33187]  New: Missed cmove opportunity
@ 2007-08-25 10:34 ubizjak at gmail dot com
  2007-08-25 12:39 ` [Bug middle-end/33187] " ubizjak at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: ubizjak at gmail dot com @ 2007-08-25 10:34 UTC (permalink / raw)
  To: gcc-bugs

This testcase:

--cut-here--
double sgn (double __x) {
  return __x >= 0.0 ? 1.0 : -1.0;
}
--cut here--

shold compile using -m32 -O2 -march=i686 flags into the code using cmove
instruction, but it doesn't due to interference with float-extension of SFmode
constant into DFmode. Gcc figures out that 1.0 can be loaded as SFmode
constant, float-extended to DFmode. The RTL sequence in each arm then looks
like:

--cut here--
(insn 17 16 18 4 cmov.c:2 (set (reg:SF 64)
        (mem/u/c/i:SF (symbol_ref/u:SI ("*.LC2") [flags 0x2]) [3 S4 A32])) 90
{*
movsf_1} (expr_list:REG_EQUAL (const_double:SF 1.0e+0 [0x0.8p+1])
        (nil)))

(insn 18 17 19 4 cmov.c:2 (set (reg:DF 58 [ D.1658 ])
        (float_extend:DF (reg:SF 64))) 127 {*extendsfdf2_i387}
(expr_list:REG_DE
AD (reg:SF 64)
        (expr_list:REG_EQUAL (const_double:DF 1.0e+0 [0x0.8p+1])
            (nil))))
--cut here--

This effectivelly blocks ifcvt from generating conditional move in this case.

cmov instruction is generated if 1.0 and -1.0 constants are changed to (i.e.)
1.1 and -1.1, in order to disable automatic float-extend functionality:

sgn:
        fldl    .LC1
        fldz
        fldl    4(%esp)
        fucomip %st(1), %st
        fstp    %st(0)
        fldl    .LC2
        fcmovb  %st(1), %st
        fstp    %st(1)
        ret

This is a middle-end bug, as the problem with float-extend should be solved in
ifcvt.c


-- 
           Summary: Missed cmove opportunity
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ubizjak at gmail dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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

* [Bug middle-end/33187] Missed cmove opportunity
  2007-08-25 10:34 [Bug middle-end/33187] New: Missed cmove opportunity ubizjak at gmail dot com
@ 2007-08-25 12:39 ` ubizjak at gmail dot com
  2007-08-25 13:25 ` rguenth at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ubizjak at gmail dot com @ 2007-08-25 12:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from ubizjak at gmail dot com  2007-08-25 12:39 -------
There is a small problem in combine. It tries to combine insn 17 and 18, but:

Failed to match this instruction:
(set (reg:DF 58 [ D.1658 ])
    (const_double:DF -1.0e+0 [-0x0.8p+1]))
Failed to match this instruction:
(set (reg:DF 58 [ D.1658 ])
    (const_double:DF -1.0e+0 [-0x0.8p+1]))

It looks to me, that in the second case combine "over-optimizes" the combined
instruction, failing to check for:

(set (reg:DF 58 [ D.1658 ])
        (float_extend:DF (mem/u/c/i:SF (symbol_ref/u:SI ("*.LC2")))))

which just happens to be valid insn for i387 and as such also appropriate for
ifcvt cmove transformation in the second ifcvt pass (after combine).


-- 


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


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

* [Bug middle-end/33187] Missed cmove opportunity
  2007-08-25 10:34 [Bug middle-end/33187] New: Missed cmove opportunity ubizjak at gmail dot com
  2007-08-25 12:39 ` [Bug middle-end/33187] " ubizjak at gmail dot com
@ 2007-08-25 13:25 ` rguenth at gcc dot gnu dot org
  2007-08-27 20:23 ` ubizjak at gmail dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-08-25 13:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2007-08-25 13:25 -------
Confirmed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-08-25 13:25:44
               date|                            |


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


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

* [Bug middle-end/33187] Missed cmove opportunity
  2007-08-25 10:34 [Bug middle-end/33187] New: Missed cmove opportunity ubizjak at gmail dot com
  2007-08-25 12:39 ` [Bug middle-end/33187] " ubizjak at gmail dot com
  2007-08-25 13:25 ` rguenth at gcc dot gnu dot org
@ 2007-08-27 20:23 ` ubizjak at gmail dot com
  2007-09-04 10:07 ` uros at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ubizjak at gmail dot com @ 2007-08-27 20:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from ubizjak at gmail dot com  2007-08-27 20:22 -------
Patch and the description of the problem at
http://gcc.gnu.org/ml/gcc-patches/2007-08/msg01880.html.


-- 

ubizjak at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |ubizjak at gmail dot com
                   |dot org                     |
                URL|                            |http://gcc.gnu.org/ml/gcc-
                   |                            |patches/2007-
                   |                            |08/msg01880.html
             Status|NEW                         |ASSIGNED
           Keywords|                            |patch
   Last reconfirmed|2007-08-25 13:25:44         |2007-08-27 20:22:49
               date|                            |


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


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

* [Bug middle-end/33187] Missed cmove opportunity
  2007-08-25 10:34 [Bug middle-end/33187] New: Missed cmove opportunity ubizjak at gmail dot com
                   ` (2 preceding siblings ...)
  2007-08-27 20:23 ` ubizjak at gmail dot com
@ 2007-09-04 10:07 ` uros at gcc dot gnu dot org
  2007-09-04 10:10 ` ubizjak at gmail dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: uros at gcc dot gnu dot org @ 2007-09-04 10:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from uros at gcc dot gnu dot org  2007-09-04 10:07 -------
Subject: Bug 33187

Author: uros
Date: Tue Sep  4 10:07:19 2007
New Revision: 128072

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128072
Log:
       PR middle-end/33187
       * combine.c (subst): Do not try to simplify X if it represents load
       of FP constant from the constant pool via float extension.

testsuite/ChangeLog:

       PR middle-end/33187
       * gcc.target/i386/cmov7.c: New file.

Added:
    trunk/gcc/testsuite/gcc.target/i386/cmov7.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/combine.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug middle-end/33187] Missed cmove opportunity
  2007-08-25 10:34 [Bug middle-end/33187] New: Missed cmove opportunity ubizjak at gmail dot com
                   ` (3 preceding siblings ...)
  2007-09-04 10:07 ` uros at gcc dot gnu dot org
@ 2007-09-04 10:10 ` ubizjak at gmail dot com
  2008-01-09 18:44 ` ghazi at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ubizjak at gmail dot com @ 2007-09-04 10:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from ubizjak at gmail dot com  2007-09-04 10:10 -------
Fixed.


-- 

ubizjak at gmail dot com changed:

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


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


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

* [Bug middle-end/33187] Missed cmove opportunity
  2007-08-25 10:34 [Bug middle-end/33187] New: Missed cmove opportunity ubizjak at gmail dot com
                   ` (4 preceding siblings ...)
  2007-09-04 10:10 ` ubizjak at gmail dot com
@ 2008-01-09 18:44 ` ghazi at gcc dot gnu dot org
  2008-01-10 14:08 ` ubizjak at gmail dot com
  2008-01-11  4:38 ` ghazi at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2008-01-09 18:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from ghazi at gcc dot gnu dot org  2008-01-09 18:25 -------
Uros, the testcase (gcc.target/i386/cmov7.c) fails on x86 with -fpic/-fPIC. 
Real bug, or skip with pic?

http://gcc.gnu.org/ml/gcc-testresults/2008-01/msg00366.html


-- 

ghazi at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ghazi at gcc dot gnu dot org


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


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

* [Bug middle-end/33187] Missed cmove opportunity
  2007-08-25 10:34 [Bug middle-end/33187] New: Missed cmove opportunity ubizjak at gmail dot com
                   ` (5 preceding siblings ...)
  2008-01-09 18:44 ` ghazi at gcc dot gnu dot org
@ 2008-01-10 14:08 ` ubizjak at gmail dot com
  2008-01-11  4:38 ` ghazi at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: ubizjak at gmail dot com @ 2008-01-10 14:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from ubizjak at gmail dot com  2008-01-10 07:01 -------
(In reply to comment #6)
> Uros, the testcase (gcc.target/i386/cmov7.c) fails on x86 with -fpic/-fPIC. 
> Real bug, or skip with pic?

No, but insn RTX costs is slightly increased for -fpic. From ix86_rtx_cost():

--cut here--
    case SYMBOL_REF:
      if (TARGET_64BIT && !x86_64_immediate_operand (x, VOIDmode))
        *total = 3;
      else if (TARGET_64BIT && !x86_64_zext_immediate_operand (x, VOIDmode))
        *total = 2;
      else if (flag_pic && SYMBOLIC_CONST (x)
               && (!TARGET_64BIT
                   || (!GET_CODE (x) != LABEL_REF
                       && (GET_CODE (x) != SYMBOL_REF
                           || !SYMBOL_REF_LOCAL_P (x)))))
        *total = 1;
      else
        *total = 0;
      return true;
--cut here--

Adding -mbranch-cost=5 to dg-options would remove this failure.


-- 

ubizjak at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|4.2.0 4.3.0                 |4.2.0


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


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

* [Bug middle-end/33187] Missed cmove opportunity
  2007-08-25 10:34 [Bug middle-end/33187] New: Missed cmove opportunity ubizjak at gmail dot com
                   ` (6 preceding siblings ...)
  2008-01-10 14:08 ` ubizjak at gmail dot com
@ 2008-01-11  4:38 ` ghazi at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2008-01-11  4:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from ghazi at gcc dot gnu dot org  2008-01-11 03:58 -------
Thanks Uros, patch posted here:
http://gcc.gnu.org/ml/gcc-patches/2008-01/msg00445.html


-- 


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


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

end of thread, other threads:[~2008-01-11  3:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-25 10:34 [Bug middle-end/33187] New: Missed cmove opportunity ubizjak at gmail dot com
2007-08-25 12:39 ` [Bug middle-end/33187] " ubizjak at gmail dot com
2007-08-25 13:25 ` rguenth at gcc dot gnu dot org
2007-08-27 20:23 ` ubizjak at gmail dot com
2007-09-04 10:07 ` uros at gcc dot gnu dot org
2007-09-04 10:10 ` ubizjak at gmail dot com
2008-01-09 18:44 ` ghazi at gcc dot gnu dot org
2008-01-10 14:08 ` ubizjak at gmail dot com
2008-01-11  4:38 ` ghazi 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).