Bug 71961 - [7 Regression] 178.galgel in SPEC CPU 2000 is miscompiled
Summary: [7 Regression] 178.galgel in SPEC CPU 2000 is miscompiled
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: 7.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2016-07-21 17:59 UTC by H.J. Lu
Modified: 2016-08-07 15:26 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2016-07-21 17:59:33 UTC
On x86-64, r238497 miscompiled 178.galgel in SPEC CPU 2000:

[hjl@gnu-ivb-1 00000002]$ cat galgel.out.mis 
0203:                 C1 = (  -0.3411    ,  0.2388    )
                      C1 = (  -0.3475    ,  0.2414    )
                                    ^
0268:      Parameter Mu            =  0.1048E+05
           Parameter Mu            =  0.1068E+05
                                               ^
0269:      Parameter Tau           = -0.1024E-01
           Parameter Tau           = -0.1041E-01
                                               ^
0270:      Floquet exponent        = -0.6821    
           Floquet exponent        = -0.6950    
                                           ^
[hjl@gnu-ivb-1 00000002]$
Comment 1 Thomas Koenig 2016-07-21 18:07:34 UTC
Reduced test case?
Comment 2 Renlin Li 2016-07-22 16:51:16 UTC
The miscompare of 178.galgel is observed in aarch64-linux as well.
Comment 3 H.J. Lu 2016-07-22 17:03:04 UTC
bifg21.f90 is miscompiled.
Comment 4 Thomas Koenig 2016-07-23 10:46:31 UTC
If there is a bug, it is likely an array dependence that
is mishandled.
Comment 5 Pat Haugen 2016-07-25 14:56:28 UTC
Also occurring on powerpc64.
Comment 6 Thomas Koenig 2016-07-26 21:15:16 UTC
Is anybody working on reducing this?

AFAIK, none of the gfortran developers has access to SPEC.
Comment 7 James Greenhalgh 2016-07-27 07:56:10 UTC
(In reply to Thomas Koenig from comment #6)
> Is anybody working on reducing this?
> 
> AFAIK, none of the gfortran developers has access to SPEC.

Reducing it would probably prove hard as the bug is a miscompile and therefore only shows at runtime in a >30 second test. H.J. has narrowed the miscompilation down to one file, would it be helpful for you if I generated some diffs of when the dumps first change, and the generated assembly for x86_64?
Comment 8 Joost VandeVondele 2016-07-27 08:17:44 UTC
also miscompiles CP2K, but haven't been able to narrow it down.
Comment 9 Thomas Koenig 2016-07-27 14:49:58 UTC
(In reply to James Greenhalgh from comment #7)

> Reducing it would probably prove hard as the bug is a miscompile and
> therefore only shows at runtime in a >30 second test. H.J. has narrowed the
> miscompilation down to one file, would it be helpful for you if I generated
> some diffs of when the dumps first change, and the generated assembly for
> x86_64?

Use -Warray-temporaries, using a compiler with and one without the patch.
The compiler with the patch should be missing a warning about creating
an array temporary.

Create a minimum test case containing just the offending line, plus
any declarations that are needed to make it valid.

Check if the two compilers still exhibit the difference with
-Warray-temporaries. Voila, minimum test case!

BTW, I will only have time to work on this in around two weeks.

With a test case, it would be OK with me if somebody reverted the
patch. I can then rework it to take care of that particular bug.
Comment 10 Joost VandeVondele 2016-07-27 15:44:43 UTC
(In reply to Thomas Koenig from comment #9)
> With a test case, it would be OK with me if somebody reverted the
> patch. I can then rework it to take care of that particular bug.

A revert would be good I think.. this is a small testcase showing the wrong results and the missing warning. I suspect it could be matmul specific.

> cat test.f90 
REAL, DIMENSION(:,:), POINTER :: a
REAL, DIMENSION(:,:), ALLOCATABLE :: b
ALLOCATE(a(4,4),b(4,2))
CALL RANDOM_NUMBER(a)
CALL RANDOM_NUMBER(b)
a(1:4,1:2)=MATMUL(a(1:4,1:4),b(1:4,1:2))
WRITE(6,*) a(1,1)
END

> gfortran -O0 -Warray-temporaries test.f90 ; ./a.out
test.f90:6:11:

 a(1:4,1:2)=MATMUL(a(1:4,1:4),b(1:4,1:2))
           1
Warning: Creating array temporary at (1) [-Warray-temporaries]
  0.770401359    

> gfortran -O1 -Warray-temporaries test.f90 ; ./a.out
  0.515214324
Comment 11 Joost VandeVondele 2016-07-27 16:18:16 UTC
This even gives wrong results at -O0 ... 

> cat test.f90 
INTEGER, DIMENSION(:,:), POINTER :: a
INTEGER, DIMENSION(:,:), ALLOCATABLE :: b
ALLOCATE(a(4,4),b(4,2))
a=1 ; b=2
a(:,1:2)=MATMUL(a(:,1:4),b(:,:))
write(6,*) a
IF (ANY(a.NE.RESHAPE((/8,8,8,8,8,8,8,8,1,1,1,1,1,1,1,1/),(/4,4/)))) &
    CALL ABORT
END

gives correct results with gcc 5.3
Comment 12 Pat Haugen 2016-07-27 19:00:30 UTC
Just for completeness sake, this is what I whittled bifg21.f90 down to. r238496 produces a warning, r238497 does not. I'll also note 178.galgel also failed at -O0, on powerpc64 at least.


      Subroutine BifG21 (G21, W11, W20, V, U, NS)

        Real*8, Dimension(1000,1000) ::  HtTim
        Integer  N, K
        Real*8, Allocatable, Dimension(:) :: POP2

           Np = Max0(N,K)
           Allocate( POP2(Np) )

           POP2(1:N) = MATMUL( HtTim(1:K,1:K), POP2(1:K) )

           Deallocate( POP2 )
       Return
      End


> gfortran -S -m64 junk.f90 -Warray-temporaries
junk.f90:10:23:

            POP2(1:N) = MATMUL( HtTim(1:K,1:K), POP2(1:K) )
                       1
Warning: Creating array temporary at (1) [-Warray-temporaries]
Comment 13 Thomas Koenig 2016-07-27 21:27:35 UTC
This looks OK.

A revert is pre-approved (if that is even needed), so
whowever can do so at the moment, feel free. Just make
sure to repoen PR 71902.
Comment 14 Renlin Li 2016-07-28 11:22:25 UTC
Author: renlin
Date: Thu Jul 28 11:21:53 2016
New Revision: 238815

URL: https://gcc.gnu.org/viewcvs?rev=238815&root=gcc&view=rev
Log:
[PATCH] Revert Revert r238497 because of PR 71961.

This patch reverts the change for PR 71902 since it causes 178.gagel
miscompile in spec2000 as reported in PR 71961 which was observed in
x86_64, aarch64, powerpc64.

gcc/fortran/ChangeLog:

2016-07-28  Renlin Li  <renlin.li@arm.com>

	Revert
	2016-07-19  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/71902
	* dependency.c (gfc_check_dependency): Use dep_ref.  Handle case
	if identical is true and two array element references differ.
	(gfc_dep_resovler):  Move most of the code to dep_ref.
	(dep_ref):  New function.
	* frontend-passes.c (realloc_string_callback):  Name temporary
	variable "realloc_string".

gcc/testsuite/ChangeLog:

2016-07-28  Renlin Li  <renlin.li@arm.com>

	Revert
	2016-07-19  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/71902
	* gfortran.dg/dependency_47.f90:  New test.


Removed:
    trunk/gcc/testsuite/gfortran.dg/dependency_47.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/dependency.c
    trunk/gcc/fortran/frontend-passes.c
    trunk/gcc/testsuite/ChangeLog
Comment 15 Renlin Li 2016-07-28 11:49:54 UTC
The change r238497 has been reverted as r238815.

I confirmed that, after the revert, the 178.gagel mis-compare
is fixed in aarch64-linux environment.

PR 71902 is reopend as well.
Comment 16 Thomas Koenig 2016-08-07 13:25:04 UTC
Author: tkoenig
Date: Sun Aug  7 13:24:32 2016
New Revision: 239220

URL: https://gcc.gnu.org/viewcvs?rev=239220&root=gcc&view=rev
Log:
2016-08-07  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/71961
	* gfortran.dg/matmul_10.f90:  New testcase.


Added:
    trunk/gcc/testsuite/gfortran.dg/matmul_10.f90
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 17 Thomas Koenig 2016-08-07 13:26:16 UTC
Test case committed, closing.
Comment 18 Thomas Koenig 2016-08-07 15:26:27 UTC
Author: tkoenig
Date: Sun Aug  7 15:25:56 2016
New Revision: 239221

URL: https://gcc.gnu.org/viewcvs?rev=239221&root=gcc&view=rev
Log:
2016-08-07  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/71961
	* gfortran.dg/pr70040.f90:  New testcase.


Added:
    trunk/gcc/testsuite/gfortran.dg/pr70040.f90
Modified:
    trunk/gcc/testsuite/ChangeLog