2015-05-06 Thomas Koenig <tkoenig@gcc.gnu.org>
[official-gcc.git] / gcc / testsuite / gfortran.dg / inline_matmul_4.f90
blobb2253b14daa66803b65f02e92f643ab89ba07adb
1 ! { dg-do run }
2 ! { dg-options "-O3 -finline-matmul-limit=10 -fdump-tree-optimized -fdump-tree-original" }
3 ! PR 37131 - all calls to matmul should be optimized away with -O3
4 ! and the high limit.
5 program main
6 real, dimension(3,2) :: a
7 real, dimension(2,4) :: b
8 real, dimension(3,4) :: c
9 real, dimension(3,4) :: cres
10 real, dimension(:,:), allocatable :: calloc
11 integer :: a1 = size(a,1), a2 = size(a,2)
12 integer :: b1 = size(b,1), b2 = size(b,2)
13 integer :: c1 = size(c,1), c2 = size(c,2)
15 data a / 2., -3., 5., -7., 11., -13./
16 data b /17., -23., 29., -31., 37., -39., 41., -47./
17 data cres /195., -304., 384., 275., -428., 548., 347., -540., 692., 411., -640., 816./
18 c = matmul(a,b)
19 if (sum(c-cres)>1e-4) call abort
21 calloc = matmul(a,b)
22 if (sum(calloc-cres)>1e-4) call abort
23 if (any([size(calloc,1), size(calloc,2)] /= [3,4])) call abort
24 deallocate(calloc)
26 allocate(calloc(4,4))
27 calloc = matmul(a,b)
28 if (sum(calloc-cres)>1e-4) call abort
29 if (any([size(calloc,1), size(calloc,2)] /= [3,4])) call abort
30 deallocate(calloc)
32 allocate(calloc(3,3))
33 calloc = matmul(a,b)
34 if (sum(calloc-cres)>1e-4) call abort
35 if (any([size(calloc,1), size(calloc,2)] /= [3,4])) call abort
36 deallocate(calloc)
38 block
39 real :: aa(a1, a2), bb(b1, b2), cc(c1, c2)
40 aa = a
41 bb = b
43 cc = matmul(aa,bb)
44 if (sum(cc-cres)>1e-4) call abort
45 calloc = matmul(aa,bb)
46 if (sum(calloc-cres)>1e-4) call abort
47 if (any([size(calloc,1), size(calloc,2)] /= [3,4])) call abort
48 calloc = 42.
49 deallocate(calloc)
51 allocate(calloc(4,4))
52 calloc = matmul(aa,bb)
53 if (sum(calloc-cres)>1e-4) call abort
54 if (any([size(calloc,1), size(calloc,2)] /= [3,4])) call abort
55 deallocate(calloc)
57 allocate(calloc(3,3))
58 calloc = matmul(aa,bb)
59 if (sum(calloc-cres)>1e-4) call abort
60 if (any([size(calloc,1), size(calloc,2)] /= [3,4])) call abort
61 deallocate(calloc)
62 end block
64 end program main
65 ! { dg-final { scan-tree-dump-times "_gfortran_matmul" 4 "original" } }
66 ! { dg-final { scan-tree-dump-times "_gfortran_matmul" 0 "optimized" } }
67 ! { dg-final { cleanup-tree-dump "original" } }
68 ! { dg-final { cleanup-tree-dump "optimized" } }