public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/60181] New: constant folding of complex number incorrect
@ 2014-02-13 16:19 krebbel at gcc dot gnu.org
  2014-02-13 18:09 ` [Bug target/60181] " joseph at codesourcery dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: krebbel at gcc dot gnu.org @ 2014-02-13 16:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 60181
           Summary: constant folding of complex number incorrect
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: krebbel at gcc dot gnu.org

The following testcase fails on s390x and Power.  Constant folding and runtime
execution of a division of complex numbers produce different results.

The testcase works fine on x86 so it looks like S/390 and Power do something
different here.

It looks somewhat like:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30789

#include <complex.h>
#include <stdio.h>
#include <stdlib.h>

_Complex float __attribute__ ((noinline))
calc (_Complex float a, _Complex float b)
{
  return a / b;
}

int
main (int argc, char **argv)
{
  _Complex float a = calc (10 + 6 * I, 5 + 12 * I);
  _Complex float b = (10 + 6 * I) / (5 + 12 * I);

  printf ("%ap + %ap * i\n", creal (a), cimag (a));
  printf ("%ap + %ap * i\n", creal (b), cimag (b));

  if (a != b)
    abort ();

  return 0;
}

gcc -O0 t.c -o f

./f
0x1.719c08p-1p + -0x1.10a9a8p-1p * i
0x1.719c06p-1p + -0x1.10a9a8p-1p * i
Aborted


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

* [Bug target/60181] constant folding of complex number incorrect
  2014-02-13 16:19 [Bug target/60181] New: constant folding of complex number incorrect krebbel at gcc dot gnu.org
@ 2014-02-13 18:09 ` joseph at codesourcery dot com
  2014-02-14  9:37 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: joseph at codesourcery dot com @ 2014-02-13 18:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
There are no specified accuracy requirements for complex multiplication / 
division, even under Annex G (parts of which - imaginary types in 
particular - are not implemented in GCC at present), beyond certain 
requirements for special cases and avoiding certain cases of overflow from 
the simplest formulas.  Constant folding is correctly rounding, runtime 
complex multiplication / division isn't (and given complaints about 
slowness at present, I don't think users would want it to be even slower, 
though there may well be a case for defining a standard library interface 
for correctly rounding complex multiplication / division).

x86 probably benefits from excess precision being used implicitly by GCC 
when compiling the implementations of complex multiplication and division.


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

* [Bug target/60181] constant folding of complex number incorrect
  2014-02-13 16:19 [Bug target/60181] New: constant folding of complex number incorrect krebbel at gcc dot gnu.org
  2014-02-13 18:09 ` [Bug target/60181] " joseph at codesourcery dot com
@ 2014-02-14  9:37 ` rguenth at gcc dot gnu.org
  2014-02-14 11:59 ` krebbel at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-02-14  9:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think that it needs to be decided on a case-by-case basis whether the
runtime complex division routine is "precise enough".  But yes, you
generally cannot expect constant folding and runtime execution to produce
the exact same result.  This is FP after all ...

(I would expect it for operations that are specified to be rounded correctly
to 0.5ulp precision though)

Note that the goal we have instead is that cross-compiling from all hosts
produces the same constant folding results for a target (code generation
doesn't depend on the host).


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

* [Bug target/60181] constant folding of complex number incorrect
  2014-02-13 16:19 [Bug target/60181] New: constant folding of complex number incorrect krebbel at gcc dot gnu.org
  2014-02-13 18:09 ` [Bug target/60181] " joseph at codesourcery dot com
  2014-02-14  9:37 ` rguenth at gcc dot gnu.org
@ 2014-02-14 11:59 ` krebbel at gcc dot gnu.org
  2014-02-14 15:34 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: krebbel at gcc dot gnu.org @ 2014-02-14 11:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andreas Krebbel <krebbel at gcc dot gnu.org> ---
I'll keep the bugreport open with low prio.  If I find the time I will at least
try to understand what's going on before closing it.

The testcase is extracted from gcc/testsuite/go.test/test/ken/cplx2.go which
fails due to this problem currently on s390.


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

* [Bug target/60181] constant folding of complex number incorrect
  2014-02-13 16:19 [Bug target/60181] New: constant folding of complex number incorrect krebbel at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2014-02-14 11:59 ` krebbel at gcc dot gnu.org
@ 2014-02-14 15:34 ` pinskia at gcc dot gnu.org
  2014-10-02 14:52 ` boger at us dot ibm.com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-02-14 15:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Could this because of the use of fma for s390 and PPC inside the division code?


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

* [Bug target/60181] constant folding of complex number incorrect
  2014-02-13 16:19 [Bug target/60181] New: constant folding of complex number incorrect krebbel at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2014-02-14 15:34 ` pinskia at gcc dot gnu.org
@ 2014-10-02 14:52 ` boger at us dot ibm.com
  2014-10-02 15:38 ` boger at us dot ibm.com
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: boger at us dot ibm.com @ 2014-10-02 14:52 UTC (permalink / raw)
  To: gcc-bugs

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

boger at us dot ibm.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |boger at us dot ibm.com

--- Comment #5 from boger at us dot ibm.com ---
*** Bug 63172 has been marked as a duplicate of this bug. ***


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

* [Bug target/60181] constant folding of complex number incorrect
  2014-02-13 16:19 [Bug target/60181] New: constant folding of complex number incorrect krebbel at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2014-10-02 14:52 ` boger at us dot ibm.com
@ 2014-10-02 15:38 ` boger at us dot ibm.com
  2014-10-02 15:47 ` dje at gcc dot gnu.org
  2014-10-02 16:10 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: boger at us dot ibm.com @ 2014-10-02 15:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from boger at us dot ibm.com ---
If the last comment is true, does that mean the fold_const.c file in gcc should
be built in a way so that it doesn't use the fma, like using some kind of
option during the build of gcc at least for this file on the s390 and Power?


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

* [Bug target/60181] constant folding of complex number incorrect
  2014-02-13 16:19 [Bug target/60181] New: constant folding of complex number incorrect krebbel at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2014-10-02 15:38 ` boger at us dot ibm.com
@ 2014-10-02 15:47 ` dje at gcc dot gnu.org
  2014-10-02 16:10 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: dje at gcc dot gnu.org @ 2014-10-02 15:47 UTC (permalink / raw)
  To: gcc-bugs

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

David Edelsohn <dje at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|ppc64-ibm-linux,            |s390x-ibm-linux,
                   |s390x-ibm-linux             |powerpc*-*-*
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-10-02
                 CC|                            |dje at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #7 from David Edelsohn <dje at gcc dot gnu.org> ---
confirmed.


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

* [Bug target/60181] constant folding of complex number incorrect
  2014-02-13 16:19 [Bug target/60181] New: constant folding of complex number incorrect krebbel at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2014-10-02 15:47 ` dje at gcc dot gnu.org
@ 2014-10-02 16:10 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-10-02 16:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to boger from comment #6)
> If the last comment is true, does that mean the fold_const.c file in gcc
> should be built in a way so that it doesn't use the fma, like using some
> kind of option during the build of gcc at least for this file on the s390
> and Power?

No it is fma usage in the runtime sources and not in the fold-const case.


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

end of thread, other threads:[~2014-10-02 16:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-13 16:19 [Bug target/60181] New: constant folding of complex number incorrect krebbel at gcc dot gnu.org
2014-02-13 18:09 ` [Bug target/60181] " joseph at codesourcery dot com
2014-02-14  9:37 ` rguenth at gcc dot gnu.org
2014-02-14 11:59 ` krebbel at gcc dot gnu.org
2014-02-14 15:34 ` pinskia at gcc dot gnu.org
2014-10-02 14:52 ` boger at us dot ibm.com
2014-10-02 15:38 ` boger at us dot ibm.com
2014-10-02 15:47 ` dje at gcc dot gnu.org
2014-10-02 16:10 ` 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).