Bug 26717 - [4.2 Regression] complex/complex gives a REAL_CST
Summary: [4.2 Regression] complex/complex gives a REAL_CST
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 4.2.0
Assignee: Uroš Bizjak
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2006-03-16 15:43 UTC by Harald Anlauf
Modified: 2006-03-25 21:58 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-03-23 10:33:46


Attachments
Original LAPACK source file (2.46 KB, text/plain)
2006-03-16 15:45 UTC, Harald Anlauf
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Harald Anlauf 2006-03-16 15:43:38 UTC
Hi,

compiling LAPACK with -O -ffast-math leads to an ICE
in LAPACK's csptri.f and csytri.f:

% gfortran -O -ffast-math -c csptri.f
csptri.f: In function 'csptri':
csptri.f:1: internal compiler error: in find_lattice_value, at tree-complex.c:133

The same error is encountered in the other file.

Cheers,
-ha
Comment 1 Harald Anlauf 2006-03-16 15:45:06 UTC
Created attachment 11059 [details]
Original LAPACK source file
Comment 2 Andrew Pinski 2006-03-16 15:59:02 UTC
Reducing.
Comment 3 Andrew Pinski 2006-03-16 16:21:05 UTC
Reduced C testcase:
_Complex float f(_Complex float a, _Complex float b)
{
  _Complex float c = a/a;
  return c/ b;
}
------
The problem is that fold is folding a/a to 1.0 but not the complex version.
Comment 4 kargls 2006-03-16 18:58:29 UTC
It looks like Andrew has found your problem.  I will, however,
suggest that you reconsider using --fast-math with gfortran.
One of my codes works correctly without --fast-math, but it
will generate NaN's with it.  I have not tracked down the problem,
nor have I files a bug report because the code is fairly large
and complicated.
Comment 5 Harald Anlauf 2006-03-17 08:06:41 UTC
(In reply to comment #4)
> I will, however, suggest that you reconsider using --fast-math with gfortran.
> One of my codes works correctly without --fast-math, but it
> will generate NaN's with it.  I have not tracked down the problem,

A fairly well-known case is complex division, where -ffast-math
assumes a reduced range of the variables so that no overflow
can occur.  See the gcc option -fno-cx-limited-range for more
details.

Here's an example where -fno-cx-limited-range does not counter
the effect of -ffast-math and produces an NaN:

% cat gfc_complex_div.f90
program gfc_complex_div
  implicit none
  complex, parameter :: a = 1.e-30 * (1.0, 1.0)

  print *, cx_div (a, a)

contains

  function cx_div (a, b)
    complex :: cx_div, a, b

    cx_div = a / b
  end function cx_div

end program gfc_complex_div
% gfc gfc_complex_div.f90 -O && ./a.out
 (  1.000000    ,  0.000000    )
% gfc gfc_complex_div.f90 -O -ffast-math && ./a.out
 (           NaN,           NaN)
% gfc gfc_complex_div.f90 -O -ffast-math -fno-cx-limited-range && ./a.out
 (           NaN,           NaN)

I think this used to work (with g77?), but it appears not to work any
longer.
Comment 6 Andrew Pinski 2006-03-22 03:14:37 UTC
The problem is here:
8910              tree r = build_real (TREE_TYPE (arg0), dconst1);
in fold-const.c

And this was caused by:
2005-11-21  Uros Bizjak  <uros@kss-loka.si>

        * fold-const.c (fold_binary) <RDIV_EXPR>: Optimize A / A to 1.0
        if we don't care about NaNs or Infinities.
Comment 7 Uroš Bizjak 2006-03-23 10:33:46 UTC
Patch at http://gcc.gnu.org/ml/gcc-patches/2006-03/msg01435.html
Comment 8 uros 2006-03-25 17:32:38 UTC
Subject: Bug 26717

Author: uros
Date: Sat Mar 25 17:32:34 2006
New Revision: 112379

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=112379
Log:
	PR middle-end/26717
	* fold-const.c (fold_binary) [RDIV_EXPR]: Do not optimize A / A
	to 1.0 for non-real operands. Implement A / A optimization for
	complex operands.


Added:
    trunk/gcc/testsuite/gcc.dg/pr26717.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog

Comment 9 Andrew Pinski 2006-03-25 21:58:18 UTC
Fixed.