2014-04-15 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gfortran.dg / matmul_3.f90
blob65290feccaa1a6e87f01913b1d2206bc4b286a11
1 ! { dg-do run }
2 ! Check the fix for PR28005, in which the mechanism for dealing
3 ! with matmul (transpose (a), b) would cause wrong results for
4 ! matmul (a(i, 1:n), b(1:n, 1:n)).
6 ! Based on the original testcase contributed by
7 ! Tobias Burnus <tobias.burnus@physik.fu-berlin.de>
8 !
9 implicit none
10 integer, parameter :: nmax = 3
11 integer :: i, n = 2
12 integer, dimension(nmax,nmax) :: iB=0 , iC=1
13 integer, dimension(nmax,nmax) :: iX1=99, iX2=99, iChk
14 iChk = reshape((/30,66,102,36,81,126,42,96,150/),(/3,3/))
16 ! This would give 3, 3, 99
17 iB = reshape((/1 ,3 ,0 ,2 ,5 ,0 ,0 ,0 ,0 /),(/3,3/))
18 iX1(1:n,1) = matmul( iB(2,1:n),iC(1:n,1:n) )
20 ! This would give 4, 4, 99
21 ib(3,1) = 1
22 iX2(1:n,1) = matmul( iB(2,1:n),iC(1:n,1:n) )
24 ! Whereas, we should have 8, 8, 99
25 if (any (iX1(1:n,1) .ne. (/8, 8, 99/))) call abort ()
26 if (any (iX1 .ne. iX2)) call abort ()
28 ! Make sure that the fix does not break transpose temporaries.
29 iB = reshape((/(i, i = 1, 9)/),(/3,3/))
30 ic = transpose (iB)
31 iX1 = transpose (iB)
32 iX1 = matmul (iX1, iC)
33 iX2 = matmul (transpose (iB), iC)
34 if (any (iX1 .ne. iX2)) call abort ()
35 if (any (iX1 .ne. iChk)) call abort ()
36 end