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
Created attachment 11059 [details] Original LAPACK source file
Reducing.
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.
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.
(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.
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.
Patch at http://gcc.gnu.org/ml/gcc-patches/2006-03/msg01435.html
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
Fixed.