Debian Codegraph @

gcc/testsuite/gfortran.dg/minmaxloc_20.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 a scalar.
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_true_mask
33 call check_int_const_shape_rank_3_false_mask
34 call check_int_alloc_rank_3_true_mask
35 call check_int_alloc_rank_3_false_mask
36 contains
37 subroutine check_int_const_shape_rank_3_true_mask()
38 integer :: a(3,4,5)
39 integer, allocatable :: r(:,:)
40 a = reshape(data60, shape(a))
41 r = maxloc(a, dim = 1, mask = .true.)
42 if (any(shape(r) /= (/ 4, 5 /))) error stop 21
43 if (any(r /= reshape(data1, (/ 4, 5 /)))) error stop 22
44 r = maxloc(a, dim = 2, mask = .true.)
45 if (any(shape(r) /= (/ 3, 5 /))) error stop 23
46 if (any(r /= reshape(data2, (/ 3, 5 /)))) error stop 24
47 r = maxloc(a, dim = 3, mask = .true.)
48 if (any(shape(r) /= (/ 3, 4 /))) error stop 25
49 if (any(r /= reshape(data3, (/ 3, 4 /)))) error stop 26
50 end subroutine
51 subroutine check_int_const_shape_rank_3_false_mask()
52 integer :: a(3,4,5)
53 integer, allocatable :: r(:,:)
54 a = reshape(data60, shape(a))
55 r = maxloc(a, dim = 1, mask = .false.)
56 if (any(shape(r) /= (/ 4, 5 /))) error stop 31
57 if (any(r /= 0)) error stop 32
58 r = maxloc(a, dim = 2, mask = .false.)
59 if (any(shape(r) /= (/ 3, 5 /))) error stop 33
60 if (any(r /= 0)) error stop 34
61 r = maxloc(a, dim = 3, mask = .false.)
62 if (any(shape(r) /= (/ 3, 4 /))) error stop 35
63 if (any(r /= 0)) error stop 36
64 end subroutine
65 subroutine check_int_alloc_rank_3_true_mask()
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, mask = .true.)
71 if (any(shape(r) /= (/ 4, 5 /))) error stop 81
72 if (any(r /= reshape(data1, (/ 4, 5 /)))) error stop 82
73 r = maxloc(a, dim = 2, mask = .true.)
74 if (any(shape(r) /= (/ 3, 5 /))) error stop 83
75 if (any(r /= reshape(data2, (/ 3, 5 /)))) error stop 84
76 r = maxloc(a, dim = 3, mask = .true.)
77 if (any(shape(r) /= (/ 3, 4 /))) error stop 85
78 if (any(r /= reshape(data3, (/ 3, 4 /)))) error stop 86
79 end subroutine
80 subroutine check_int_alloc_rank_3_false_mask()
81 integer, allocatable :: a(:,:,:)
82 integer, allocatable :: r(:,:)
83 allocate(a(3,4,5))
84 a(:,:,:) = reshape(data60, shape(a))
85 r = maxloc(a, dim = 1, mask = .false.)
86 if (any(shape(r) /= (/ 4, 5 /))) error stop 91
87 if (any(r /= 0)) error stop 92
88 r = maxloc(a, dim = 2, mask = .false.)
89 if (any(shape(r) /= (/ 3, 5 /))) error stop 93
90 if (any(r /= 0)) error stop 94
91 r = maxloc(a, dim = 3, mask = .false.)
92 if (any(shape(r) /= (/ 3, 4 /))) error stop 95
93 if (any(r /= 0)) error stop 96
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_true_mask
120 call check_int_const_shape_rank_3_false_mask
121 call check_int_alloc_rank_3_true_mask
122 call check_int_alloc_rank_3_false_mask
123 contains
124 subroutine check_int_const_shape_rank_3_true_mask()
125 integer :: a(3,4,5)
126 integer, allocatable :: r(:,:)
127 a = reshape(data60, shape(a))
128 r = minloc(a, dim = 1, mask = .true.)
129 if (any(shape(r) /= (/ 4, 5 /))) error stop 121
130 if (any(r /= reshape(data1, (/ 4, 5 /)))) error stop 122
131 r = minloc(a, dim = 2, mask = .true.)
132 if (any(shape(r) /= (/ 3, 5 /))) error stop 123
133 if (any(r /= reshape(data2, (/ 3, 5 /)))) error stop 124
134 r = minloc(a, dim = 3, mask = .true.)
135 if (any(shape(r) /= (/ 3, 4 /))) error stop 125
136 if (any(r /= reshape(data3, (/ 3, 4 /)))) error stop 126
137 end subroutine
138 subroutine check_int_const_shape_rank_3_false_mask()
139 integer :: a(3,4,5)
140 integer, allocatable :: r(:,:)
141 a = reshape(data60, shape(a))
142 r = minloc(a, dim = 1, mask = .false.)
143 if (any(shape(r) /= (/ 4, 5 /))) error stop 131
144 if (any(r /= 0)) error stop 132
145 r = minloc(a, dim = 2, mask = .false.)
146 if (any(shape(r) /= (/ 3, 5 /))) error stop 133
147 if (any(r /= 0)) error stop 134
148 r = minloc(a, dim = 3, mask = .false.)
149 if (any(shape(r) /= (/ 3, 4 /))) error stop 135
150 if (any(r /= 0)) error stop 136
151 end subroutine
152 subroutine check_int_alloc_rank_3_true_mask()
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, mask = .true.)
158 if (any(shape(r) /= (/ 4, 5 /))) error stop 181
159 if (any(r /= reshape(data1, (/ 4, 5 /)))) error stop 182
160 r = minloc(a, dim = 2, mask = .true.)
161 if (any(shape(r) /= (/ 3, 5 /))) error stop 183
162 if (any(r /= reshape(data2, (/ 3, 5 /)))) error stop 184
163 r = minloc(a, dim = 3, mask = .true.)
164 if (any(shape(r) /= (/ 3, 4 /))) error stop 185
165 if (any(r /= reshape(data3, (/ 3, 4 /)))) error stop 186
166 end subroutine
167 subroutine check_int_alloc_rank_3_false_mask()
168 integer, allocatable :: a(:,:,:)
169 integer, allocatable :: r(:,:)
170 allocate(a(3,4,5))
171 a(:,:,:) = reshape(data60, shape(a))
172 r = minloc(a, dim = 1, mask = .false.)
173 if (any(shape(r) /= (/ 4, 5 /))) error stop 191
174 if (any(r /= 0)) error stop 192
175 r = minloc(a, dim = 2, mask = .false.)
176 if (any(shape(r) /= (/ 3, 5 /))) error stop 193
177 if (any(r /= 0)) error stop 194
178 r = minloc(a, dim = 3, mask = .false.)
179 if (any(shape(r) /= (/ 3, 4 /))) error stop 195
180 if (any(r /= 0)) error stop 196
181 end subroutine
182 end subroutine