Bug 19779 - IBM 128bit long double format is not constant folded.
Summary: IBM 128bit long double format is not constant folded.
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.0
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
: 105578 107745 (view as bug list)
Depends on:
Blocks: 26374 88204
  Show dependency treegraph
 
Reported: 2005-02-03 15:47 UTC by Andrew Pinski
Modified: 2024-02-19 19:21 UTC (History)
9 users (show)

See Also:
Host:
Target: powerpc-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-07-01 00:46:50


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2005-02-03 15:47:58 UTC
This is the new bug for PR 19405. Keeping track of that we no longer constant fold long doubles in the 
IBM 128bit long double format.
Comment 1 Jonathan Wakely 2022-03-09 17:53:36 UTC
I think this should be rejects-valid not a missed-optimization enhancement. For C++20 we reject valid code:

#include <limits>
constexpr long double x = 1.0L + std::numeric_limits<long double>::epsilon();

<stdin>:1:32: error: ‘(1.0e+0l + 4.94065645841246544176568792868221e-324l)’ is not a constant expression


The code reduces to:

constexpr long double x = 1.0L + __LDBL_EPSILON__;
Comment 2 Jakub Jelinek 2022-03-09 18:05:17 UTC
We do fold it with -ffast-math or -funsafe-math-optimizations.
PR19405 explains the reasons why we can't fold those results that aren't exactly representable in double double.
Comment 3 Jonathan Wakely 2022-03-09 18:14:00 UTC
Yeah, I'm not asking for it to be fixed, just noting here that it affects C++ constant expressions.
Comment 4 Andrew Pinski 2022-05-12 09:27:03 UTC
*** Bug 105578 has been marked as a duplicate of this bug. ***
Comment 5 Andrew Pinski 2022-11-18 09:14:09 UTC
*** Bug 107745 has been marked as a duplicate of this bug. ***
Comment 6 Sergey Fedorov 2024-02-19 10:08:47 UTC
(In reply to Andrew Pinski from comment #0)
> This is the new bug for PR 19405. Keeping track of that we no longer
> constant fold long doubles in the 
> IBM 128bit long double format.

What is the current status of the issue?
Comment 7 Jakub Jelinek 2024-02-19 10:12:40 UTC
Unlikely to be ever fixed, at least Linux has migrated to IEEE quad long double on powerpc64le.
Comment 8 Andrew Pinski 2024-02-19 10:13:39 UTC
(In reply to Sergey Fedorov from comment #6)
> (In reply to Andrew Pinski from comment #0)
> > This is the new bug for PR 19405. Keeping track of that we no longer
> > constant fold long doubles in the 
> > IBM 128bit long double format.
> 
> What is the current status of the issue?

Nothing has changed here that much. Though powerpc64 le is heading towards doing IEEE 128bit FP by default so this might be much much less of an issue for most people which means this is more likely never get fixed.
Comment 9 Iain Sandoe 2024-02-19 10:18:29 UTC
(In reply to Andrew Pinski from comment #8)
> (In reply to Sergey Fedorov from comment #6)
> > (In reply to Andrew Pinski from comment #0)
> > > This is the new bug for PR 19405. Keeping track of that we no longer
> > > constant fold long doubles in the 
> > > IBM 128bit long double format.
> > 
> > What is the current status of the issue?
> 
> Nothing has changed here that much. Though powerpc64 le is heading towards
> doing IEEE 128bit FP by default so this might be much much less of an issue
> for most people which means this is more likely never get fixed.

it occasionally causes grief, but so far there's been a work-around; I guess if someone really wanted to make a patch - they'd have to use MPFR et. al. to do the work.
Comment 10 Jakub Jelinek 2024-02-19 10:32:59 UTC
(In reply to Iain Sandoe from comment #9)
> (In reply to Andrew Pinski from comment #8)
> > (In reply to Sergey Fedorov from comment #6)
> > > (In reply to Andrew Pinski from comment #0)
> > > > This is the new bug for PR 19405. Keeping track of that we no longer
> > > > constant fold long doubles in the 
> > > > IBM 128bit long double format.
> > > 
> > > What is the current status of the issue?
> > 
> > Nothing has changed here that much. Though powerpc64 le is heading towards
> > doing IEEE 128bit FP by default so this might be much much less of an issue
> > for most people which means this is more likely never get fixed.
> 
> it occasionally causes grief, but so far there's been a work-around; I guess
> if someone really wanted to make a patch - they'd have to use MPFR et. al.
> to do the work.

MPFR won't really help, after all, it doesn't have any double double arithmetic support at all.
The problem is that real.cc pretends that IBM double double is a sane floating point format with 106bit precision, which is not the case.
In GCC, basic floating point operations are performed by performing stuff in the GCC internal format, which is something with sufficient precision and exponent range to cover all the sane supported formats including some extra precision bits and then converting that to the appropriate mode.
That doesn't work for double double, which has precision between 53 to some thousands bits of precision, so in order to emulate in the compiler basic floating point, it would need to be handled like it is actually at runtime, which is hold the REAL_CST/CONST_DOUBLE double double values as a pair of DFmode values rather than a single real_internal_format value (because the latter can't express all the double double values), perform whatever __gcc_qadd/__gcc_qsub/__gcc_qmul/__gcc_qdiv etc. perform at runtime on the DFmode values, etc.  And then there is a question what to do about emulation of libm functions - how to map that e.g. to mpfr operations, because what libm actually does for those is sometimes quite weird and hard to define.
Comment 11 Sergey Fedorov 2024-02-19 19:11:58 UTC
(In reply to Jakub Jelinek from comment #7)
> Unlikely to be ever fixed, at least Linux has migrated to IEEE quad long
> double on powerpc64le.

Perhaps several *BSDs and AIX are using IBM format though.
Comment 12 Jonathan Wakely 2024-02-19 19:19:32 UTC
Then the maintainers or users of those targets should consider contributing a fix.
Comment 13 Jakub Jelinek 2024-02-19 19:21:22 UTC
Nobody is blocking proper double double evaluation support.  But somebody needs to do the work, spend a few weeks on it and submit that.  I'm just saying that is highly unlikely.  If somebody was really bothered about that there wouldn't be 19 years of it being unfixed.  More so in the years when it was the typical long double on Linux powerpc64le as well.  It is still the usually supported long double on Linux powerpc64 and powerpc, but those are rarely used these days.