This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Committed] PR26524: ICE building LAPACK with -O2 -ffast-math


The following patch should resolve PR tree-optimization/26524 which
is a gcc 4.1 regression building lapack's clatm5.f with -ffast-math.
The problematic code is also on mainline, but is currently latent
due to recent type checking improvements in fold-const.c.

The cause of the problem is that scalar evolution code encounters
the expression -z and attempts to analyze this as the equivalent
-1*z.  The catch is that in this case, z has a complex type, and
the use of build_int_cst_type to create (const_int (complex_type) -1)
wreaks havoc in the middle-end.  The solution is to instead use
fold_const in this routine, which will DTRT for integer, real and
complex types.

I believe Andrew Pinski is investigating adding an assertion to
build_int_cst_type to confirm there are no other instances of this
problem.  build_int_cst_type is a fairly high traffic routine, so
it might be preferrable to just file PRs for any current failures.


The following patch has been tested on x86_64-unknown-linux-gnu with
a full "make bootstrap", all default languages, and regression tested
with a top-level "make -k check" with no new failures.  It's also
been tested against the gcc-4_1-branch, wih the same results, to
confirm that the new testcase fails on an unpatched tree, but passes
with this fix.

Committed to mainline as revision 111676.  There is no such thing
as a truly safe backport, so I'll wait a few days before applying
this change to the gcc-4_1-branch.



2006-03-03  Roger Sayle  <roger@eyesopen.com>

	PR tree-optimization/26524
	* tree-scalar-evolution.c (interpret_rhs_modify_expr): Use
	fold_convert to create a constant of the appropriate type.

	* gfortran.dg/pr26524.f: New test case.


Index: tree-scalar-evolution.c
===================================================================
*** tree-scalar-evolution.c	(revision 111646)
--- tree-scalar-evolution.c	(working copy)
*************** interpret_rhs_modify_expr (struct loop *
*** 1647,1655 ****
        opnd10 = TREE_OPERAND (opnd1, 0);
        chrec10 = analyze_scalar_evolution (loop, opnd10);
        chrec10 = chrec_convert (type, chrec10, at_stmt);
!       res = chrec_fold_multiply (type, chrec10, SCALAR_FLOAT_TYPE_P (type)
! 				  ? build_real (type, dconstm1)
! 				  : build_int_cst_type (type, -1));
        break;

      case MULT_EXPR:
--- 1647,1655 ----
        opnd10 = TREE_OPERAND (opnd1, 0);
        chrec10 = analyze_scalar_evolution (loop, opnd10);
        chrec10 = chrec_convert (type, chrec10, at_stmt);
!       /* TYPE may be integer, real or complex, so use fold_convert.  */
!       res = chrec_fold_multiply (type, chrec10,
! 				 fold_convert (type, integer_minus_one_node));
        break;

      case MULT_EXPR:


C PR tree-optimization/26524
C { dg-do compile }
C { dg-options "-O2 -ffast-math" }
      SUBROUTINE CLATM5( PRTYPE, M, N, A, LDA, B, LDB, C, LDC, D, LDD,
     $                   E, LDE, F, LDF, R, LDR, L, LDL, ALPHA, QBLCKA,
     $                   QBLCKB )
      COMPLEX            A( LDA, * ), B( LDB, * ), C( LDC, * ),
     $                   L( LDL, * ), R( LDR, * )
      COMPLEX            IMEPS, REEPS
         DO 240 I = 1, M
               IF( MOD( I, 2 ).NE.0 .AND. I.LT.M ) THEN
                  A( I, I-1 ) = -IMEPS*2
               END IF
  240    CONTINUE
      END


Roger
--


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]