public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/94083] inefficient soft-float x!=Inf code
       [not found] <bug-94083-4@http.gcc.gnu.org/bugzilla/>
@ 2020-11-07 21:22 ` wilson at gcc dot gnu.org
  2021-08-16 21:40 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: wilson at gcc dot gnu.org @ 2020-11-07 21:22 UTC (permalink / raw)
  To: gcc-bugs

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

The original bug report was apparently lost in the sourceware/gcc migration
back in the spring and I didn't notice until now.

This testcase

int foo(void) {
  volatile float f, g;
  int            n;
  f = __builtin_huge_valf();
  g = __builtin_huge_valf();
  n += 1 - (f != __builtin_huge_valf());
  return n;
}

compiled for soft-float with -O2, and looking at the original tree dump I see

  f =  Inf;
  g =  Inf;
  SAVE_EXPR <!(f u<= 3.4028234663852885981170418348451692544e+38)>;, n =
SAVE_EX
PR <!(f u<= 3.4028234663852885981170418348451692544e+38)> + n;;

So the C front end converted the f != Inf compare to a f u<=
<max-representable-float> compare, but the problem here is that the !=
operation is a single libcall, but u<= is two libcalls.  So code that should
have a single soft-float libcall ends up with two.  First a call to __unordsf2,
then a compare and branch, and then a call to __lesf2.  This is a
de-optimization.

Perhaps we can convert the f u<= <max-representable-float> back to f != Inf in
the optimization to get a single libcall.  Or maybe we can add unordered
soft-float libcalls like ulesf2.

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

* [Bug middle-end/94083] inefficient soft-float x!=Inf code
       [not found] <bug-94083-4@http.gcc.gnu.org/bugzilla/>
  2020-11-07 21:22 ` [Bug middle-end/94083] inefficient soft-float x!=Inf code wilson at gcc dot gnu.org
@ 2021-08-16 21:40 ` pinskia at gcc dot gnu.org
  2024-02-27 19:48 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-16 21:40 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
           Severity|minor                       |enhancement

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

* [Bug middle-end/94083] inefficient soft-float x!=Inf code
       [not found] <bug-94083-4@http.gcc.gnu.org/bugzilla/>
  2020-11-07 21:22 ` [Bug middle-end/94083] inefficient soft-float x!=Inf code wilson at gcc dot gnu.org
  2021-08-16 21:40 ` pinskia at gcc dot gnu.org
@ 2024-02-27 19:48 ` pinskia at gcc dot gnu.org
  2024-02-27 19:49 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-27 19:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |g.peterhoff@t-online.de

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 114131 has been marked as a duplicate of this bug. ***

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

* [Bug middle-end/94083] inefficient soft-float x!=Inf code
       [not found] <bug-94083-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2024-02-27 19:48 ` pinskia at gcc dot gnu.org
@ 2024-02-27 19:49 ` pinskia at gcc dot gnu.org
  2024-02-28  9:51 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-27 19:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-02-27
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. Also happens with _Float128 on x86_64 since that is a soft-float fp
type too.

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

* [Bug middle-end/94083] inefficient soft-float x!=Inf code
       [not found] <bug-94083-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2024-02-27 19:49 ` pinskia at gcc dot gnu.org
@ 2024-02-28  9:51 ` jakub at gcc dot gnu.org
  2024-02-28 10:24 ` harald at gigawatt dot nl
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-02-28  9:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Shall __builtin_isinf (x) or __builtin_isinf_sign (x) raise exception if x is a
sNaN?
Or never? Or it can but doesn't have to?
glibc's
        int64_t hx,lx;
        GET_LDOUBLE_WORDS64(hx,lx,x);
        lx |= (hx & 0x7fffffffffffffffLL) ^ 0x7fff000000000000LL;
        lx |= -lx;
        return ~(lx >> 63) & (hx >> 62);
doesn't, but I think when we lower __builtin_isinf to fabs (x) (which should
just clear the sign bit, not raise exception) u<= <max_representable_finite>,
it would.
If we wouldn't need to raise exception, I think fastest would be to pattern
recognize the fabs (x) <= <max_representable> and emit there the (lx | ((hx &
0x7fffffffffffffffLL) ^ 0x7fff000000000000LL)) != 0.
But __builtin_islessequal (__builtin_fabsf128 (x), __builtin_nextafterf128
(__builtin_inff128 (), 0.0f128)) I think should raise exception and those 2
will be indistinguishable, so maybe just recognize that case during expansion
if 2 libcalls would be needed and emit the equality comparison instead.
Or do both depending on if -fsignaling-nans is specified or not?

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

* [Bug middle-end/94083] inefficient soft-float x!=Inf code
       [not found] <bug-94083-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2024-02-28  9:51 ` jakub at gcc dot gnu.org
@ 2024-02-28 10:24 ` harald at gigawatt dot nl
  2024-02-28 10:33 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: harald at gigawatt dot nl @ 2024-02-28 10:24 UTC (permalink / raw)
  To: gcc-bugs

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

Harald van Dijk <harald at gigawatt dot nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |harald at gigawatt dot nl

--- Comment #4 from Harald van Dijk <harald at gigawatt dot nl> ---
(In reply to Jakub Jelinek from comment #3)
> Shall __builtin_isinf (x) or __builtin_isinf_sign (x) raise exception if x
> is a sNaN?
> Or never? Or it can but doesn't have to?

Never.

See also bug #66462 which also has a not-quite-right patch that was committed
and reverted, and the fixed patch posted but never committed and then
forgotten. I'm not 100% sure of the impact of that patch on soft-float but at a
quick glance it seems to use bitwise integer arithmetic which should avoid
libcalls entirely.

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

* [Bug middle-end/94083] inefficient soft-float x!=Inf code
       [not found] <bug-94083-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2024-02-28 10:24 ` harald at gigawatt dot nl
@ 2024-02-28 10:33 ` jakub at gcc dot gnu.org
  2024-02-28 11:42 ` jsm28 at gcc dot gnu.org
  2024-02-28 22:19 ` harald at gigawatt dot nl
  8 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-02-28 10:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Ah, ok.  So then expansion should just concentrate on the fabs (x) <= nextafter
(inf, 0) case for soft-float case and defer the rest to PR66462 which would
handle that much earlier.

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

* [Bug middle-end/94083] inefficient soft-float x!=Inf code
       [not found] <bug-94083-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2024-02-28 10:33 ` jakub at gcc dot gnu.org
@ 2024-02-28 11:42 ` jsm28 at gcc dot gnu.org
  2024-02-28 22:19 ` harald at gigawatt dot nl
  8 siblings, 0 replies; 9+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2024-02-28 11:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Joseph S. Myers <jsm28 at gcc dot gnu.org> ---
Contrary to what was claimed in bug 66462, I don't think there ever was a fixed
patch. Note that in bug 66462 comment 19, "June" is June 2017 but "November" is
November 2016 - the "November" one is the *older* one.

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

* [Bug middle-end/94083] inefficient soft-float x!=Inf code
       [not found] <bug-94083-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2024-02-28 11:42 ` jsm28 at gcc dot gnu.org
@ 2024-02-28 22:19 ` harald at gigawatt dot nl
  8 siblings, 0 replies; 9+ messages in thread
From: harald at gigawatt dot nl @ 2024-02-28 22:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Harald van Dijk <harald at gigawatt dot nl> ---
(In reply to Joseph S. Myers from comment #6)
> Contrary to what was claimed in bug 66462, I don't think there ever was a
> fixed patch. Note that in bug 66462 comment 19, "June" is June 2017 but
> "November" is November 2016 - the "November" one is the *older* one.

Ah, sorry, I misunderstood the situation. According to
<https://gcc.gnu.org/legacy-ml/gcc-patches/2017-08/msg01630.html> the earlier
version of that patch (the November 2016 one) was the one that did not have the
problems that caused it to be reverted. In response to review of that, big
changes were requested and in the process bugs were introduced. The buggy
version was then committed and reverted. The original version that did not have
those bugs could still be committed if a re-review, taking into account the
bugs that the rework introduced, would now see it as acceptable.

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

end of thread, other threads:[~2024-02-28 22:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-94083-4@http.gcc.gnu.org/bugzilla/>
2020-11-07 21:22 ` [Bug middle-end/94083] inefficient soft-float x!=Inf code wilson at gcc dot gnu.org
2021-08-16 21:40 ` pinskia at gcc dot gnu.org
2024-02-27 19:48 ` pinskia at gcc dot gnu.org
2024-02-27 19:49 ` pinskia at gcc dot gnu.org
2024-02-28  9:51 ` jakub at gcc dot gnu.org
2024-02-28 10:24 ` harald at gigawatt dot nl
2024-02-28 10:33 ` jakub at gcc dot gnu.org
2024-02-28 11:42 ` jsm28 at gcc dot gnu.org
2024-02-28 22:19 ` harald at gigawatt dot nl

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).