Bug 22504 - [4.1 Regression] benchmark - galgel fails at runtime with miscompare output
Summary: [4.1 Regression] benchmark - galgel fails at runtime with miscompare output
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.1.0
Assignee: Steven Bosscher
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-07-15 18:26 UTC by Uttam Pawar
Modified: 2005-07-26 22:11 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-07-19 21:45:01


Attachments
Fortran 90 code to compute spherical bessel functions (543 bytes, text/plain)
2005-07-19 18:29 UTC, kargls
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Uttam Pawar 2005-07-15 18:26:24 UTC
With the recent change went in tree-complex.c causing the galgel's runtime
failure with miscompare output.

http://gcc.gnu.org/ml/gcc-cvs/2005-06/msg00767.html
Comment 1 Steven Bosscher 2005-07-16 09:46:20 UTC
It fails everywhere, not just on ppc. 
 
Comment 2 Giovanni Bajo 2005-07-16 09:52:07 UTC
I guess a reduced testcase might help.
Comment 3 Steven Bosscher 2005-07-16 10:22:35 UTC
I think that bifgel.f90 is being miscompiled. 
Comment 4 kargls 2005-07-19 18:29:51 UTC
Created attachment 9306 [details]
Fortran 90 code to compute spherical bessel functions

The attached code computes the spherical bessel functions with a 
complex argument.  Complex arithmetic has been broken.	Here's
the results of compiling the code 


The 3rd and 4th columns should be the same.
	
troutmask:sgk[207] gfc -o z zy.f90
troutmask:sgk[208] ./z
 0   2.2900E+01 -3.4445E-02 -3.4445E-02  0.0000E+00
 1   2.2900E+01  2.5337E-02  2.5337E-02  0.0000E+00
 2   2.2900E+01  3.7765E-02  3.7765E-02  0.0000E+00
 3   2.2900E+01 -1.7091E-02 -1.7091E-02  0.0000E+00   
 4   2.2900E+01 -4.2989E-02 -4.2989E-02  0.0000E+00
troutmask:sgk[209] gfc -o z -O zy.f90
troutmask:sgk[211] ./z
 0   2.2900E+01 -3.4445E-02 -3.4445E-02  0.0000E+00
 1   2.2900E+01  2.5337E-02  3.9638E-02  0.0000E+00
 2   2.2900E+01  3.7765E-02 -5.0710E-02  0.0000E+00
 3   2.2900E+01 -1.7091E-02  7.3035E-02  0.0000E+00
 4   2.2900E+01 -4.2989E-02 -1.2032E-01  0.0000E+00
troutmask:sgk[213] gfc --version
GNU Fortran 95 (GCC 4.1.0 20050712 (experimental))
Comment 5 Volker Reichelt 2005-07-20 00:25:41 UTC
Reduced testcase. The program should print
  6.00E+00  0.00E+00
but prints
  4.00E+00  0.00E+00
when compiled with -O:

=========================
program FOO
   integer i
   complex a, b, c
   b = 2
   c = 0
   do i = 1, 2
      a = 2 * b - c
      c = b
      b = a
   end do
   print '(2ES10.2)', a
end program FOO
=========================
Comment 6 Richard Henderson 2005-07-20 05:27:13 UTC
Thanks for the reduction; I see the problem clearly now.  For the record,

  b$real_193 = CR.53_187;
  b$imag_194 = CI.54_188;
  c$real_195 = b$real_193;
  c$imag_196 = b$imag_194;

we had a ring of copies to perform, and they came out in the wrong order.
I'll have to give this some thought...
Comment 7 GCC Commits 2005-07-22 00:33:56 UTC
Subject: Bug 22504

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rth@gcc.gnu.org	2005-07-22 00:33:48

Modified files:
	gcc            : ChangeLog tree-complex.c 

Log message:
	PR tree-opt/22504
	* tree-complex.c (complex_ssa_name_components): New.
	(cvc_lookup): Allow entry not found.
	(create_components): Remove.
	(create_one_component_var, get_component_var): New.
	(get_component_ssa_name, set_component_ssa_name): New.
	(extract_component): Use get_component_ssa_name.
	(update_complex_components): Use set_component_ssa_name.
	(update_complex_components_on_edge): Likewise.
	(update_phi_components): Create new PHI nodes directly, instead
	of adding insns to edges.
	(tree_lower_complex): Allocate and free complex_variable_components
	and complex_ssa_name_components here.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9507&r2=2.9508
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-complex.c.diff?cvsroot=gcc&r1=2.36&r2=2.37

Comment 8 Volker Reichelt 2005-07-22 11:19:27 UTC
Richard, are you going to add a testcase for this?

Can somebody confirm that the benchmark testcase is fixed, too?
Comment 9 Steven Bosscher 2005-07-22 20:55:13 UTC
galgel still fails for me even with the patch. 
 
Comment 10 Steven Bosscher 2005-07-26 00:30:50 UTC
This is miscompiled: 
 
       SUBROUTINE foo (A, B) 
          IMPLICIT NONE 
          COMPLEX*16 A, Im1 
          REAL*8 B 
          Im1 = Dcmplx(0.D0, 1.D0) 
          A = A + Im1 * B 
          RETURN 
       END SUBROUTINE foo 
 
 
t.f90.t35.ch: 
;; Function foo (foo_) 
 
foo (a, b) 
{ 
  complex8 im1; 
  complex8 D.808; 
  complex8 D.807; 
  complex8 D.806; 
  real8 D.805; 
  complex8 D.804; 
 
<bb 0>: 
  D.804_3 = *a_2; 
  D.805_5 = *b_4; 
  D.806_6 = COMPLEX_EXPR <D.805_5, 0.0>; 
  D.807_7 = D.806_6 * __complex__ (0.0, 1.0e+0); 
  D.808_8 = D.804_3 + D.807_7; 
  *a_2 = D.808_8; 
  return; 
 
} 
 
 
t.f90.t37.cplxlower: 
foo (a, b) 
{ 
  real8 CI.14; 
  real8 D.834; 
  real8 CI.13; 
  real8 CR.12; 
  real8 D.831; 
  real8 D.830; 
  complex8 im1; 
  complex8 D.808; 
  complex8 D.807; 
  complex8 D.806; 
  real8 D.805; 
  complex8 D.804; 
 
<bb 0>: 
  D.830_15 = REALPART_EXPR <*a_2>; 
  D.831_16 = IMAGPART_EXPR <*a_2>; 
  D.804_3 = COMPLEX_EXPR <D.830_15, D.831_16>; 
  CR.12_12 = D.830_15; 
  CI.13_13 = D.831_16; 
  D.805_5 = *b_4; 
  D.806_6 = COMPLEX_EXPR <D.805_5, 0.0>; 
  D.807_7 = COMPLEX_EXPR <0.0, D.805_5>; 
  D.834_17 = CI.13_13 - D.805_5; 
  D.808_8 = COMPLEX_EXPR <CR.12_12, D.834_17>; 
  CI.14_14 = D.834_17; 
  REALPART_EXPR <*a_2> = CR.12_12; 
  IMAGPART_EXPR <*a_2> = CI.14_14; 
  return; 
 
} 
 
Comment 11 Steven Bosscher 2005-07-26 08:26:46 UTC
These are the only bugs I could find in expand_complex_addition: 
 
Index: tree-complex.c 
=================================================================== 
RCS file: /cvs/gcc/gcc/gcc/tree-complex.c,v 
retrieving revision 2.39 
diff -u -3 -p -r2.39 tree-complex.c 
--- tree-complex.c      25 Jul 2005 23:04:33 -0000      2.39 
+++ tree-complex.c      26 Jul 2005 08:26:07 -0000 
@@ -844,7 +844,7 @@ expand_complex_addition (block_stmt_iter 
 
     case PAIR (VARYING, ONLY_IMAG): 
       rr = ar; 
-      ri = gimplify_build2 (bsi, MINUS_EXPR, inner_type, ai, bi); 
+      ri = gimplify_build2 (bsi, code, inner_type, ai, bi); 
       break; 
 
     case PAIR (ONLY_REAL, VARYING): 
@@ -858,7 +858,7 @@ expand_complex_addition (block_stmt_iter 
       if (code == MINUS_EXPR) 
        goto general; 
       rr = br; 
-      ri = gimplify_build2 (bsi, MINUS_EXPR, inner_type, ai, bi); 
+      ri = gimplify_build2 (bsi, code, inner_type, ai, bi); 
       break; 
 
 
Comment 12 Uttam Pawar 2005-07-26 17:27:10 UTC
Steven's patch has fixed the galgel failure. I've verified it on Powerpc.
Comment 13 GCC Commits 2005-07-26 21:38:56 UTC
Subject: Bug 22504

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	steven@gcc.gnu.org	2005-07-26 21:38:46

Modified files:
	gcc            : ChangeLog tree-complex.c 

Log message:
	PR tree-optimization/22504
	* tree-complex.c (expand_complex_addition): Use 'code' instead
	of MINUS_EXPR for (VARYING, ONLY_IMAG) and (ONLY_IMAG, VARYING).

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9556&r2=2.9557
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-complex.c.diff?cvsroot=gcc&r1=2.39&r2=2.40

Comment 14 Steven Bosscher 2005-07-26 22:11:47 UTC
The bug is fixed.  I still have to add test cases.