Debian Codegraph @

gcc/testsuite/gfortran.dg/minmaxloc_19.f90

raw
1 ! { dg-do compile }
2 ! { dg-additional-options "-O -fdump-tree-original" }
3 ! { dg-final { scan-tree-dump-not "gfortran_\[sm\]?minloc" "original" } }
4 ! { dg-final { scan-tree-dump-not "gfortran_\[sm\]?maxloc" "original" } }
5 !
6 ! PR fortran/90608
7 ! Check that all MINLOC and MAXLOC calls are inlined with optimizations,
8 ! when ARRAY is of integral type, DIM is a constant, and MASK is absent.
9
10 subroutine check_maxloc
11 implicit none
12 integer, parameter :: data60(*) = (/ 2, 5, 4, 6, 0, 9, 3, 5, 4, 4, &
13 1, 7, 3, 2, 1, 2, 5, 4, 6, 0, &
14 9, 3, 5, 4, 4, 1, 7, 3, 2, 1, &
15 2, 5, 4, 6, 0, 9, 3, 5, 4, 4, &
16 1, 7, 3, 2, 1, 2, 5, 4, 6, 0, &
17 9, 3, 5, 4, 4, 1, 7, 3, 2, 1 /)
18 integer, parameter :: data1(*) = (/ 2, 3, 2, 3, &
19 1, 2, 3, 2, &
20 3, 1, 2, 3, &
21 2, 3, 1, 2, &
22 3, 2, 3, 1 /)
23 integer, parameter :: data2(*) = (/ 2, 1, 2, &
24 3, 2, 3, &
25 4, 3, 4, &
26 2, 1, 2, &
27 1, 2, 1 /)
28 integer, parameter :: data3(*) = (/ 5, 1, 5, &
29 1, 2, 1, &
30 2, 1, 2, &
31 3, 2, 3 /)
32 call check_int_const_shape_rank_3
33 call check_int_const_shape_empty_4
34 call check_int_alloc_rank_3
35 call check_int_alloc_empty_4
36 contains
37 subroutine check_int_const_shape_rank_3()
38 integer :: a(3,4,5)
39 integer, allocatable :: r(:,:)
40 a = reshape(data60, shape(a))
41 r = maxloc(a, dim=1)
42 if (any(shape(r) /= (/ 4, 5 /))) error stop 11
43 if (any(r /= reshape(data1, (/ 4, 5 /)))) error stop 12
44 r = maxloc(a, dim=2)
45 if (any(shape(r) /= (/ 3, 5 /))) error stop 13
46 if (any(r /= reshape(data2, (/ 3, 5 /)))) error stop 14
47 r = maxloc(a, dim=3)
48 if (any(shape(r) /= (/ 3, 4 /))) error stop 15
49 if (any(r /= reshape(data3, (/ 3, 4 /)))) error stop 16
50 end subroutine
51 subroutine check_int_const_shape_empty_4()
52 integer :: a(9,3,0,7)
53 integer, allocatable :: r(:,:,:)
54 a = reshape((/ integer:: /), shape(a))
55 r = maxloc(a, dim=1)
56 if (any(shape(r) /= (/ 3, 0, 7 /))) error stop 21
57 r = maxloc(a, dim=2)
58 if (any(shape(r) /= (/ 9, 0, 7 /))) error stop 22
59 r = maxloc(a, dim=3)
60 if (any(shape(r) /= (/ 9, 3, 7 /))) error stop 23
61 if (any(r /= 0)) error stop 24
62 r = maxloc(a, dim=4)
63 if (any(shape(r) /= (/ 9, 3, 0 /))) error stop 25
64 end subroutine
65 subroutine check_int_alloc_rank_3()
66 integer, allocatable :: a(:,:,:)
67 integer, allocatable :: r(:,:)
68 allocate(a(3,4,5))
69 a(:,:,:) = reshape(data60, shape(a))
70 r = maxloc(a, dim=1)
71 if (any(shape(r) /= (/ 4, 5 /))) error stop 31
72 if (any(r /= reshape(data1, (/ 4, 5 /)))) error stop 32
73 r = maxloc(a, dim=2)
74 if (any(shape(r) /= (/ 3, 5 /))) error stop 33
75 if (any(r /= reshape(data2, (/ 3, 5 /)))) error stop 34
76 r = maxloc(a, dim=3)
77 if (any(shape(r) /= (/ 3, 4 /))) error stop 35
78 if (any(r /= reshape(data3, (/ 3, 4 /)))) error stop 36
79 end subroutine
80 subroutine check_int_alloc_empty_4()
81 integer, allocatable :: a(:,:,:,:)
82 integer, allocatable :: r(:,:,:)
83 allocate(a(9,3,0,7))
84 a(:,:,:,:) = reshape((/ integer:: /), shape(a))
85 r = maxloc(a, dim=1)
86 if (any(shape(r) /= (/ 3, 0, 7 /))) error stop 41
87 r = maxloc(a, dim=2)
88 if (any(shape(r) /= (/ 9, 0, 7 /))) error stop 42
89 r = maxloc(a, dim=3)
90 if (any(shape(r) /= (/ 9, 3, 7 /))) error stop 43
91 if (any(r /= 0)) error stop 44
92 r = maxloc(a, dim=4)
93 if (any(shape(r) /= (/ 9, 3, 0 /))) error stop 45
94 end subroutine
95 end subroutine
96
97 subroutine check_minloc
98 implicit none
99 integer, parameter :: data60(*) = (/ 7, 4, 5, 3, 9, 0, 6, 4, 5, 5, &
100 8, 2, 6, 7, 8, 7, 4, 5, 3, 9, &
101 0, 6, 4, 5, 5, 8, 2, 6, 7, 8, &
102 7, 4, 5, 3, 9, 0, 6, 4, 5, 5, &
103 8, 2, 6, 7, 8, 7, 4, 5, 3, 9, &
104 0, 6, 4, 5, 5, 8, 2, 6, 7, 8 /)
105 integer, parameter :: data1(*) = (/ 2, 3, 2, 3, &
106 1, 2, 3, 2, &
107 3, 1, 2, 3, &
108 2, 3, 1, 2, &
109 3, 2, 3, 1 /)
110 integer, parameter :: data2(*) = (/ 2, 1, 2, &
111 3, 2, 3, &
112 4, 3, 4, &
113 2, 1, 2, &
114 1, 2, 1 /)
115 integer, parameter :: data3(*) = (/ 5, 1, 5, &
116 1, 2, 1, &
117 2, 1, 2, &
118 3, 2, 3 /)
119 call check_int_const_shape_rank_3
120 call check_int_const_shape_empty_4
121 call check_int_alloc_rank_3
122 call check_int_alloc_empty_4
123 contains
124 subroutine check_int_const_shape_rank_3()
125 integer :: a(3,4,5)
126 integer, allocatable :: r(:,:)
127 a = reshape(data60, shape(a))
128 r = minloc(a, dim=1)
129 if (any(shape(r) /= (/ 4, 5 /))) error stop 111
130 if (any(r /= reshape(data1, (/ 4, 5 /)))) error stop 112
131 r = minloc(a, dim=2)
132 if (any(shape(r) /= (/ 3, 5 /))) error stop 113
133 if (any(r /= reshape(data2, (/ 3, 5 /)))) error stop 114
134 r = minloc(a, dim=3)
135 if (any(shape(r) /= (/ 3, 4 /))) error stop 115
136 if (any(r /= reshape(data3, (/ 3, 4 /)))) error stop 116
137 end subroutine
138 subroutine check_int_const_shape_empty_4()
139 integer :: a(9,3,0,7)
140 integer, allocatable :: r(:,:,:)
141 a = reshape((/ integer:: /), shape(a))
142 r = minloc(a, dim=1)
143 if (any(shape(r) /= (/ 3, 0, 7 /))) error stop 121
144 r = minloc(a, dim=2)
145 if (any(shape(r) /= (/ 9, 0, 7 /))) error stop 122
146 r = minloc(a, dim=3)
147 if (any(shape(r) /= (/ 9, 3, 7 /))) error stop 123
148 if (any(r /= 0)) error stop 124
149 r = minloc(a, dim=4)
150 if (any(shape(r) /= (/ 9, 3, 0 /))) error stop 125
151 end subroutine
152 subroutine check_int_alloc_rank_3()
153 integer, allocatable :: a(:,:,:)
154 integer, allocatable :: r(:,:)
155 allocate(a(3,4,5))
156 a(:,:,:) = reshape(data60, shape(a))
157 r = minloc(a, dim=1)
158 if (any(shape(r) /= (/ 4, 5 /))) error stop 131
159 if (any(r /= reshape(data1, (/ 4, 5 /)))) error stop 132
160 r = minloc(a, dim=2)
161 if (any(shape(r) /= (/ 3, 5 /))) error stop 133
162 if (any(r /= reshape(data2, (/ 3, 5 /)))) error stop 134
163 r = minloc(a, dim=3)
164 if (any(shape(r) /= (/ 3, 4 /))) error stop 135
165 if (any(r /= reshape(data3, (/ 3, 4 /)))) error stop 136
166 end subroutine
167 subroutine check_int_alloc_empty_4()
168 integer, allocatable :: a(:,:,:,:)
169 integer, allocatable :: r(:,:,:)
170 allocate(a(9,3,0,7))
171 a(:,:,:,:) = reshape((/ integer:: /), shape(a))
172 r = minloc(a, dim=1)
173 if (any(shape(r) /= (/ 3, 0, 7 /))) error stop 141
174 r = minloc(a, dim=2)
175 if (any(shape(r) /= (/ 9, 0, 7 /))) error stop 142
176 r = minloc(a, dim=3)
177 if (any(shape(r) /= (/ 9, 3, 7 /))) error stop 143
178 if (any(r /= 0)) error stop 144
179 r = minloc(a, dim=4)
180 if (any(shape(r) /= (/ 9, 3, 0 /))) error stop 145
181 end subroutine
182 end subroutine