public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/61563] New: better 387 code for float x == (int)x
@ 2014-06-19 15:47 jay.foad at gmail dot com
  2014-06-19 16:22 ` [Bug target/61563] " joseph at codesourcery dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: jay.foad at gmail dot com @ 2014-06-19 15:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 61563
           Summary: better 387 code for float x == (int)x
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jay.foad at gmail dot com

I get this with GCC 4.10.0 20140619 (experimental):

$ gcc -mno-sse -O3 -S -o - -x c - <<<"int f(float x) { return x == (int)x; }"
...
f:
    fnstcw    -2(%rsp)
    movzwl    -2(%rsp), %eax
    flds    8(%rsp)
    movl    $0, %edx
    orb    $12, %ah
    movw    %ax, -4(%rsp)
    xorl    %eax, %eax
    fldcw    -4(%rsp)
    fistl    -12(%rsp)
    fldcw    -2(%rsp)
    fildl    -12(%rsp)
    fucomip    %st(1), %st
    fstp    %st(0)
    setnp    %al
    cmovne    %edx, %eax
    ret

All the fnstcw and fldcw stuff is unnecessary, because when we convert x to
int, it doesn't matter what rounding mode we use; all that matters is whether
it is already an exact int value or not.

I think the x == (int)x pattern is fairly common, and it would be nice if GCC
generated better 387 code for it.


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

* [Bug target/61563] better 387 code for float x == (int)x
  2014-06-19 15:47 [Bug target/61563] New: better 387 code for float x == (int)x jay.foad at gmail dot com
@ 2014-06-19 16:22 ` joseph at codesourcery dot com
  2014-06-19 20:16 ` jay.foad at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: joseph at codesourcery dot com @ 2014-06-19 16:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
Note that it's only for certain pairs of floating-point and integer type 
that the rounding mode doesn't matter.  It's true for float and int, 
because the precision of float is small enough, compared to that of int, 
that values that are within range for int when converted rounding towards 
zero, but that might overflow and so cause a spurious "invalid" exception 
if converted in another rounding mode, can't be represented in float.  
But it's not true for double and int, for example (though maybe more cases 
are allowed by -fno-trapping-math).


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

* [Bug target/61563] better 387 code for float x == (int)x
  2014-06-19 15:47 [Bug target/61563] New: better 387 code for float x == (int)x jay.foad at gmail dot com
  2014-06-19 16:22 ` [Bug target/61563] " joseph at codesourcery dot com
@ 2014-06-19 20:16 ` jay.foad at gmail dot com
  2014-06-21  8:45 ` ubizjak at gmail dot com
  2021-08-02 20:08 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jay.foad at gmail dot com @ 2014-06-19 20:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jay Foad <jay.foad at gmail dot com> ---
I hadn't considered spurious "invalid" exceptions. I was only thinking about
the result of the whole expression, which I think is the same regardless of
rounding mode even for double and int.


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

* [Bug target/61563] better 387 code for float x == (int)x
  2014-06-19 15:47 [Bug target/61563] New: better 387 code for float x == (int)x jay.foad at gmail dot com
  2014-06-19 16:22 ` [Bug target/61563] " joseph at codesourcery dot com
  2014-06-19 20:16 ` jay.foad at gmail dot com
@ 2014-06-21  8:45 ` ubizjak at gmail dot com
  2021-08-02 20:08 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ubizjak at gmail dot com @ 2014-06-21  8:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Jay Foad from comment #0)

> I think the x == (int)x pattern is fairly common, and it would be nice if
> GCC generated better 387 code for it.

Please note that -msse3 will generate fistt insn that doesn't need control word
changes.
>From gcc-bugs-return-454633-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sat Jun 21 09:02:38 2014
Return-Path: <gcc-bugs-return-454633-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 19387 invoked by alias); 21 Jun 2014 09:02:37 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 19342 invoked by uid 48); 21 Jun 2014 09:02:31 -0000
From: "trippels at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/61506] [4.10 Regression] ICE triggered by solution to #61446
Date: Sat, 21 Jun 2014 09:02:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: target
X-Bugzilla-Version: 4.10.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: blocker
X-Bugzilla-Who: trippels at gcc dot gnu.org
X-Bugzilla-Status: WAITING
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.10.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on cc everconfirmed
Message-ID: <bug-61506-4-W06HB2u2J3@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-61506-4@http.gcc.gnu.org/bugzilla/>
References: <bug-61506-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-06/txt/msg01715.txt.bz2
Content-length: 634

https://gcc.gnu.org/bugzilla/show_bug.cgi?ida506

Markus Trippelsdorf <trippels at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2014-06-21
                 CC|                            |trippels at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #5 from Markus Trippelsdorf <trippels at gcc dot gnu.org> ---
Please provide a preprocessed file, see: https://gcc.gnu.org/bugs/ .


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

* [Bug target/61563] better 387 code for float x == (int)x
  2014-06-19 15:47 [Bug target/61563] New: better 387 code for float x == (int)x jay.foad at gmail dot com
                   ` (2 preceding siblings ...)
  2014-06-21  8:45 ` ubizjak at gmail dot com
@ 2021-08-02 20:08 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-02 20:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

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

end of thread, other threads:[~2021-08-02 20:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-19 15:47 [Bug target/61563] New: better 387 code for float x == (int)x jay.foad at gmail dot com
2014-06-19 16:22 ` [Bug target/61563] " joseph at codesourcery dot com
2014-06-19 20:16 ` jay.foad at gmail dot com
2014-06-21  8:45 ` ubizjak at gmail dot com
2021-08-02 20:08 ` pinskia 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).