2 ! { dg-options "-finline-matmul-limit=0 -fdump-tree-original -fdump-tree-optimized -Warray-temporaries -fbounds-check" }
8 integer, parameter :: nx
=3, ny
=4
9 integer, parameter, dimension(nx
,ny
) :: p
= &
10 & reshape ((/ (i
**2, i
=1,size(p
)) /), shape(p
))
11 integer, parameter, dimension(ny
,nx
) :: q
= &
12 & reshape ((/ (((nx
*(i
-1)+j
)**2, i
=1,ny
), j
=1,nx
) /), (/ ny
, nx
/))
14 integer, parameter, dimension(nx
,nx
) :: r
= &
15 & reshape ((/ (i
*i
, i
=1,size(r
)) /), shape(r
))
16 integer, parameter, dimension(nx
,nx
) :: s
= &
17 & reshape ((/ (((nx
*(i
-1)+j
)**2, i
=1,nx
), j
=1,nx
) /), (/ nx
, nx
/))
21 integer, dimension(nx
,ny
) :: a
, b
22 integer, dimension(ny
,nx
) :: c
23 integer, dimension(nx
,nx
) :: e
, f
, g
25 character(144) :: u
, v
30 if (any(c
/= q
)) STOP 1
32 write(u
,*) transpose(a
)
41 if (any(g
/= r
+ s
)) STOP 3
43 write(u
,*) transpose(e
+f
)
48 e
= transpose(e
) ! { dg-warning "Creating array temporary" }
49 if (any(e
/= s
)) STOP 5
51 write(u
,*) transpose(transpose(e
))
56 e
= transpose(e
+f
) ! { dg-warning "Creating array temporary" }
57 if (any(e
/= 2*r
)) STOP 7
59 write(u
,*) transpose(transpose(e
+f
))-f
65 if (any(a
/= p
+1)) STOP 9
67 write(u
,*) foo(transpose(c
)) ! { dg-warning "Creating array temporary" }
72 c
= transpose(foo(a
)) ! Unnecessary { dg-warning "Creating array temporary" }
73 if (any(c
/= q
+2)) STOP 11
75 write(u
,*) transpose(foo(a
)) ! { dg-warning "Creating array temporary" }
80 e
= foo(transpose(e
)) ! { dg-warning "Creating array temporary" }
81 if (any(e
/= 2*s
+1)) STOP 13
83 write(u
,*) transpose(foo(transpose(e
))-1) ! { dg-warning "Creating array temporary" }
88 e
= transpose(foo(e
)) ! { dg-warning "Creating array temporary" }
89 if (any(e
/= 2*r
+2)) STOP 15
91 write(u
,*) transpose(foo(transpose(e
)-1)) ! 2 temps { dg-warning "Creating array temporary" }
97 if (any(a
/= p
+4)) STOP 17
99 write(u
,*) bar(transpose(c
))
104 c
= transpose(bar(a
))
105 if (any(c
/= q
+6)) STOP 19
107 write(u
,*) transpose(bar(a
))
112 e
= bar(transpose(e
)) ! { dg-warning "Creating array temporary" }
113 if (any(e
/= 2*s
+4)) STOP 21
115 write(u
,*) transpose(bar(transpose(e
)))-2
120 e
= transpose(bar(e
)) ! { dg-warning "Creating array temporary" }
121 if (any(e
/= 2*r
+6)) STOP 23
123 write(u
,*) transpose(transpose(bar(e
))-2)
128 if (any(a
/= transpose(transpose(a
)))) STOP 25! optimized away
131 write(v
,*) transpose(transpose(a
))
137 if (any(transpose(a
+b
) /= transpose(a
)+transpose(b
))) STOP 27! optimized away
139 write(u
,*) transpose(a
+b
)
140 write(v
,*) transpose(a
) + transpose(b
)
144 if (any(transpose(matmul(a
,c
)) /= matmul(transpose(c
), transpose(a
)))) STOP 29! 2 temps { dg-warning "Creating array temporary" }
146 write(u
,*) transpose(matmul(a
,c
)) ! { dg-warning "Creating array temporary" }
147 write(v
,*) matmul(transpose(c
), transpose(a
)) ! { dg-warning "Creating array temporary" }
151 if (any(transpose(matmul(e
,a
)) /= matmul(transpose(a
), transpose(e
)))) STOP 31! 2 temps { dg-warning "Creating array temporary" }
153 write(u
,*) transpose(matmul(e
,a
)) ! { dg-warning "Creating array temporary" }
154 write(v
,*) matmul(transpose(a
), transpose(e
)) ! { dg-warning "Creating array temporary" }
158 call baz (transpose(a
))
161 call toto1 (a
, transpose (c
))
162 if (any (a
/= 2 * p
+ 12)) STOP 33
164 call toto1 (e
, transpose (e
)) ! { dg-warning "Creating array temporary" }
165 if (any (e
/= 4 * s
+ 12)) STOP 34
168 call toto2 (c
, transpose (a
))
169 if (any (c
/= 2 * q
+ 13)) STOP 35
171 call toto2 (e
, transpose(e
)) ! { dg-warning "Creating array temporary" }
172 if (any (e
/= 4 * r
+ 13)) STOP 36
174 call toto2 (e
, transpose(transpose(e
))) ! { dg-warning "Creating array temporary" }
175 if (any (e
/= 4 * r
+ 14)) STOP 37
178 call toto3 (e
, transpose(e
))
179 if (any (e
/= 4 * r
+ 14)) STOP 38
182 call titi (nx
, e
, transpose(e
)) ! { dg-warning "Creating array temporary" }
183 if (any (e
/= 4 * s
+ 17)) STOP 39
188 integer, intent(in
) :: x(:,:)
189 integer :: foo(size(x
,1), size(x
,2))
193 elemental
function bar (x
)
194 integer, intent(in
) :: x
200 integer, intent(in
) :: x(:,:)
203 elemental
subroutine toto1 (x
, y
)
204 integer, intent(out
) :: x
205 integer, intent(in
) :: y
209 subroutine toto2 (x
, y
)
210 integer, dimension(:,:), intent(out
) :: x
211 integer, dimension(:,:), intent(in
) :: y
215 subroutine toto3 (x
, y
)
216 integer, dimension(:,:), intent(in
) :: x
, y
221 subroutine titi (n
, x
, y
)
222 integer :: n
, x(n
,n
), y(n
,n
)
226 ! No call to transpose
227 ! { dg-final { scan-tree-dump-times "_gfortran_transpose" 0 "original" } }
230 ! { dg-final { scan-tree-dump-times "struct\[^\\n\]*atmp" 24 "original" } }
232 ! 2 tests optimized out
233 ! { dg-final { scan-tree-dump-times "_gfortran_stop" 39 "original" } }
234 ! { # Commented out as failing at -O0: dg-final { scan-tree-dump-times "_gfortran_stop" 37 "optimized" } }