Bug 35944 - [4.3 Regression] wrong result for MOD with kind=10 for some array argument values
Summary: [4.3 Regression] wrong result for MOD with kind=10 for some array argument va...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.3.1
Assignee: Uroš Bizjak
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2008-04-15 13:57 UTC by Dick Hendrickson
Modified: 2008-04-17 07:10 UTC (History)
2 users (show)

See Also:
Host:
Target: i686-pc-linux-gnu
Build:
Known to work: 4.2.3
Known to fail:
Last reconfirmed: 2008-04-16 11:28:36


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dick Hendrickson 2008-04-15 13:57:37 UTC
The following program gives the wrong answers when the 
MOD arguments have kind = 10 and one is an array.  It
works when the kind is 4 or 8.

      program FA2083

! fails on Windows XP
! gcc version 4.4.0 20080312 (experimental) [trunk revision 133139]

      implicit none
      integer j1,k
      parameter (k=10)              !fails
!      parameter (k=8)              !works
!      parameter (k=4)              !works
      REAL(k) QDA1(10)
      REAL(k) QDA(10), qval

      print *, 'kind = ',k

      qda = (/ 1,2,3,4,5,6,7,8,9,10 /)

      QDA1 = MOD ( 1.1_k*( QDA(1) -5.0_k), P=( QDA -2.5_k))

      DO J1 = 1,10
      QVAL = MOD(1.1_k*(QDA(1)-5.0_k),P=(QDA(J1)-2.5_k))
      print '(i3, 3f10.2)', j1, qda1(j1), qval, qval-qda1(j1)
      ENDDO

      END

c:\gfortran:gfortran fa2083.f

c:\gfortran:a
 kind =           10
  1     -1.40     -1.40      0.00
  2     -0.40     -0.40      0.00
  3     -0.40     -0.40      0.00
  4     -0.40     -1.40     -1.00
  5     -0.40     -1.90     -1.50
  6     -0.40     -0.90     -0.50
  7     -0.40     -4.40     -4.00
  8     -0.40     -4.40     -4.00
  9     -0.40     -4.40     -4.00
 10     -0.40     -4.40     -4.00

c:\gfortran:gfortran fa2083.f

c:\gfortran:a
 kind =            8
  1     -1.40     -1.40      0.00
  2     -0.40     -0.40      0.00
  3     -0.40     -0.40      0.00
  4     -1.40     -1.40      0.00
  5     -1.90     -1.90      0.00
  6     -0.90     -0.90      0.00
  7     -4.40     -4.40      0.00
  8     -4.40     -4.40      0.00
  9     -4.40     -4.40      0.00
 10     -4.40     -4.40      0.00

c:\gfortran:gfortran fa2083.f

c:\gfortran:a
 kind =            4
  1     -1.40     -1.40      0.00
  2     -0.40     -0.40      0.00
  3     -0.40     -0.40      0.00
  4     -1.40     -1.40      0.00
  5     -1.90     -1.90      0.00
  6     -0.90     -0.90      0.00
  7     -4.40     -4.40      0.00
  8     -4.40     -4.40      0.00
  9     -4.40     -4.40      0.00
 10     -4.40     -4.40      0.00
Comment 1 Thomas Koenig 2008-04-15 21:02:35 UTC
Confirmed, this used to work for 4.2.

$ gfortran-4.2 foo.f90 
$ ./a.out
 kind =           10
  1     -1.40     -1.40      0.00
  2     -0.40     -0.40      0.00
  3     -0.40     -0.40      0.00
  4     -1.40     -1.40      0.00
  5     -1.90     -1.90      0.00
  6     -0.90     -0.90      0.00
  7     -4.40     -4.40      0.00
  8     -4.40     -4.40      0.00
  9     -4.40     -4.40      0.00
 10     -4.40     -4.40      0.00
$ gfortran-4.2 -v         
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --disable-libmudflap --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.2.3 (Debian 4.2.3-3)
$ gfortran-4.3 foo.f90 
$ ./a.out
 kind =           10
  1      0.00     -1.40     -1.40
  2     -0.00     -0.40       NaN
  3     -0.40     -0.40      0.00
  4     -0.40     -1.40     -1.00
  5     -0.40     -1.90     -1.50
  6     -0.40     -0.90     -0.50
  7     -0.40     -4.40     -4.00
  8     -0.40     -4.40     -4.00
  9     -0.40     -4.40     -4.00
 10     -0.40     -4.40     -4.00
$ gfortran-4.3 -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure linux gnu
Thread model: posix
gcc version 4.3.1 20080309 (prerelease) (Debian 4.3.0-1) 
Comment 2 Jerry DeLisle 2008-04-16 03:51:57 UTC
The tree dump for the kind=8 and kind=10 are exactly identical except for the call to __builtin_fmodl for kind=10 and __builtin_fmod for kind=8.

It looks like fmodl is broken.

Comment 3 Uroš Bizjak 2008-04-16 06:21:36 UTC
(In reply to comment #2)
> The tree dump for the kind=8 and kind=10 are exactly identical except for the
> call to __builtin_fmodl for kind=10 and __builtin_fmod for kind=8.
> 
> It looks like fmodl is broken.

Can somebody provide equivalent c testcase? I will look into this problem.
Comment 4 Uroš Bizjak 2008-04-16 11:28:36 UTC
(In reply to comment #3)

> Can somebody provide equivalent c testcase? I will look into this problem.

I have a patch in testing.


Comment 5 uros 2008-04-16 15:54:39 UTC
Subject: Bug 35944

Author: uros
Date: Wed Apr 16 15:53:59 2008
New Revision: 134348

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134348
Log:
        PR target/35944
        * config/i386/i386.md (fmodxf3): Copy operand 1 and operand 2 into
        temporary registers.  Change operand predicate to general_operand.
        (remainderxf3): Ditto.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.md

Comment 6 Uroš Bizjak 2008-04-16 16:05:08 UTC
Fixed in mainline. I'm not a fortran person; can someone please construct a testcase from the example in the description to be committed to SVN?
Comment 7 uros 2008-04-16 18:39:57 UTC
Subject: Bug 35944

Author: uros
Date: Wed Apr 16 18:39:08 2008
New Revision: 134359

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134359
Log:
        PR target/35944
        * gfortran.dg/pr35944-1.f90: New test.
        * gfortran.dg/pr35944-2.f90: Ditto.


Added:
    trunk/gcc/testsuite/gfortran.dg/pr35944-1.f90
    trunk/gcc/testsuite/gfortran.dg/pr35944-2.f90
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 8 uros 2008-04-17 07:08:29 UTC
Subject: Bug 35944

Author: uros
Date: Thu Apr 17 07:07:45 2008
New Revision: 134381

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134381
Log:
	Backport from mainline:
	2008-04-16  Uros Bizjak  <ubizjak@gmail.com>

	PR target/35944
	* config/i386/i386.md (fmodxf3): Copy operand 1 and operand 2 into
	temporary registers.  Change operand predicate to general_operand.
	(remainderxf3): Ditto.

testsuite/ChangeLog:

	Backport from mainline:
	2008-04-16  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>

	PR target/35944
	* gfortran.dg/pr35944-1.f90: New test.
	* gfortran.dg/pr35944-2.f90: Ditto.


Added:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/pr35944-1.f90
      - copied unchanged from r134359, trunk/gcc/testsuite/gfortran.dg/pr35944-1.f90
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/pr35944-2.f90
      - copied unchanged from r134359, trunk/gcc/testsuite/gfortran.dg/pr35944-2.f90
Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/config/i386/i386.md
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 9 Uroš Bizjak 2008-04-17 07:10:45 UTC
Fixed.
Comment 10 Paul Thomas 2008-04-19 21:56:17 UTC
Subject: Bug 35944

Author: pault
Date: Sat Apr 19 21:55:24 2008
New Revision: 134472

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134472
Log:
2008-04-19  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/35944
	PR fortran/35946
	PR fortran/35947
	* trans_array.c (gfc_trans_array_constructor): Temporarily
	realign loop, if loop->from is not zero, before creating
	the temporary array and provide an offset.

	PR fortran/35959
	* trans-decl.c (gfc_init_default_dt): Add gfc_ prefix to name
	and allow for NULL body.  Change all references from
	init_default_dt to gfc_init_default_dt.
	* trans.h : Add prototype for gfc_init_default_dt.
	* trans-array.c (gfc_trans_deferred_vars): After nullification
	call gfc_init_default_dt for derived types with allocatable
	components.

2008-04-19  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/35944
	PR fortran/35946
	PR fortran/35947
	* gfortran.dg/array_constructor_23.f: New test.

	PR fortran/35959
	* gfortran.dg/alloc_comp_default_init_2.f90: New test.
	* gfortran.dg/alloc_comp_basics_1.f90: Change occurrences of
	"builtin_free" to 27.
	* gfortran.dg/alloc_comp_constructor_1.f90: Change occurrences
	of "builtin_free" to 21.

Added:
    trunk/gcc/testsuite/gfortran.dg/alloc_comp_default_init_2.f90
    trunk/gcc/testsuite/gfortran.dg/array_constructor_23.f
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/fortran/trans.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/alloc_comp_basics_1.f90
    trunk/gcc/testsuite/gfortran.dg/alloc_comp_constructor_1.f90

Comment 11 Paul Thomas 2008-04-19 22:31:02 UTC
Subject: Bug 35944

Author: pault
Date: Sat Apr 19 22:30:03 2008
New Revision: 134475

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134475
Log:
2008-04-19  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/35944
	PR fortran/35946
	PR fortran/35947
	* trans_array.c (gfc_trans_array_constructor): Temporarily
	realign loop, if loop->from is not zero, before creating
	the temporary array and provide an offset.

	PR fortran/35959
	* trans-decl.c (gfc_init_default_dt): Add gfc_ prefix to name
	and allow for NULL body.  Change all references from
	init_default_dt to gfc_init_default_dt.
	* trans.h : Add prototype for gfc_init_default_dt.
	* trans-array.c (gfc_trans_deferred_vars): After nullification
	call gfc_init_default_dt for derived types with allocatable
	components.

2008-04-19  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/35944
	PR fortran/35946
	PR fortran/35947
	* gfortran.dg/array_constructor_23.f: New test.

	PR fortran/35959
	* gfortran.dg/alloc_comp_default_init_2.f90: New test.
	* gfortran.dg/alloc_comp_basics_1.f90: Change occurrences of
	"builtin_free" to 27.
	* gfortran.dg/alloc_comp_constructor_1.f90: Change occurrences
	of "builtin_free" to 21.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/alloc_comp_default_init_2.f90
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/array_constructor_23.f
Modified:
    branches/gcc-4_3-branch/gcc/fortran/ChangeLog
    branches/gcc-4_3-branch/gcc/fortran/trans-array.c
    branches/gcc-4_3-branch/gcc/fortran/trans-decl.c
    branches/gcc-4_3-branch/gcc/fortran/trans.h
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/alloc_comp_basics_1.f90
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/alloc_comp_constructor_1.f90