[LoopReroll] Add an extra defensive check to avoid SCEV assertion.
[llvm-project.git] / flang / test / Semantics / omp-symbol08.f90
blob4fd01e718fd52bdb505e62f2bb0fa832719a5408
1 ! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp
2 ! REQUIRES: shell
4 ! 2.15.1.1 Predetermined rules for associated do-loops index variable
5 ! a) The loop iteration variable(s) in the associated do-loop(s) of a do,
6 ! parallel do, taskloop, or distribute construct is (are) private.
7 ! b) The loop iteration variable in the associated do-loop of a simd construct
8 ! with just one associated do-loop is linear with a linear-step that is the
9 ! increment of the associated do-loop.
10 ! c) The loop iteration variables in the associated do-loops of a simd
11 ! construct with multiple associated do-loops are lastprivate.
12 ! d) A loop iteration variable for a sequential loop in a parallel or task
13 ! generating construct is private in the innermost such construct that
14 ! encloses the loop.
15 ! - TBD
17 ! All the tests assume that the do-loops association for collapse/ordered
18 ! clause has been performed (the number of nested do-loops >= n).
20 ! Rule a)
21 ! TODO: nested constructs (k should be private too)
22 !DEF: /test_do (Subroutine) Subprogram
23 subroutine test_do
24 implicit none
25 !DEF: /test_do/a ObjectEntity REAL(4)
26 real a(20,20,20)
27 !DEF: /test_do/i ObjectEntity INTEGER(4)
28 !DEF: /test_do/j ObjectEntity INTEGER(4)
29 !DEF: /test_do/k ObjectEntity INTEGER(4)
30 integer i, j, k
31 !$omp parallel
32 !REF: /test_do/i
33 i = 99
34 !$omp do collapse(2)
35 !DEF: /test_do/Block1/Block1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
36 do i=1,5
37 !DEF: /test_do/Block1/Block1/j (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
38 do j=6,10
39 !REF: /test_do/a
40 a(1,1,1) = 0.
41 !DEF: /test_do/Block1/k (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
42 do k=11,15
43 !REF: /test_do/a
44 !REF: /test_do/Block1/k
45 !REF: /test_do/Block1/Block1/j
46 !REF: /test_do/Block1/Block1/i
47 a(k,j,i) = 1.
48 end do
49 end do
50 end do
51 !$omp end parallel
52 end subroutine test_do
54 ! Rule a)
55 !DEF: /test_pardo (Subroutine) Subprogram
56 subroutine test_pardo
57 implicit none
58 !DEF: /test_pardo/a ObjectEntity REAL(4)
59 real a(20,20,20)
60 !DEF: /test_pardo/i ObjectEntity INTEGER(4)
61 !DEF: /test_pardo/j ObjectEntity INTEGER(4)
62 !DEF: /test_pardo/k ObjectEntity INTEGER(4)
63 integer i, j, k
64 !$omp parallel do collapse(2) private(k) ordered(2)
65 !DEF: /test_pardo/Block1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
66 do i=1,5
67 !DEF: /test_pardo/Block1/j (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
68 do j=6,10
69 !REF: /test_pardo/a
70 a(1,1,1) = 0.
71 !DEF: /test_pardo/Block1/k (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
72 do k=11,15
73 !REF: /test_pardo/a
74 !REF: /test_pardo/Block1/k
75 !REF: /test_pardo/Block1/j
76 !REF: /test_pardo/Block1/i
77 a(k,j,i) = 1.
78 end do
79 end do
80 end do
81 end subroutine test_pardo
83 ! Rule a)
84 !DEF: /test_taskloop (Subroutine) Subprogram
85 subroutine test_taskloop
86 implicit none
87 !DEF: /test_taskloop/a ObjectEntity REAL(4)
88 real a(5,5)
89 !DEF: /test_taskloop/i ObjectEntity INTEGER(4)
90 !DEF: /test_taskloop/j ObjectEntity INTEGER(4)
91 integer i, j
92 !$omp taskloop private(j)
93 !DEF: /test_taskloop/Block1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
94 do i=1,5
95 !DEF: /test_taskloop/Block1/j (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
96 !REF: /test_taskloop/Block1/i
97 do j=1,i
98 !REF: /test_taskloop/a
99 !REF: /test_taskloop/Block1/j
100 !REF: /test_taskloop/Block1/i
101 a(j,i) = 3.14
102 end do
103 end do
104 !$omp end taskloop
105 end subroutine test_taskloop
107 ! Rule a); OpenMP 4.5 Examples teams.2.f90
108 ! TODO: reduction; data-mapping attributes
109 !DEF: /dotprod (Subroutine) Subprogram
110 !DEF: /dotprod/b ObjectEntity REAL(4)
111 !DEF: /dotprod/c ObjectEntity REAL(4)
112 !DEF: /dotprod/n ObjectEntity INTEGER(4)
113 !DEF: /dotprod/block_size ObjectEntity INTEGER(4)
114 !DEF: /dotprod/num_teams ObjectEntity INTEGER(4)
115 !DEF: /dotprod/block_threads ObjectEntity INTEGER(4)
116 subroutine dotprod (b, c, n, block_size, num_teams, block_threads)
117 implicit none
118 !REF: /dotprod/n
119 integer n
120 !REF: /dotprod/b
121 !REF: /dotprod/n
122 !REF: /dotprod/c
123 !DEF: /dotprod/sum ObjectEntity REAL(4)
124 real b(n), c(n), sum
125 !REF: /dotprod/block_size
126 !REF: /dotprod/num_teams
127 !REF: /dotprod/block_threads
128 !DEF: /dotprod/i ObjectEntity INTEGER(4)
129 !DEF: /dotprod/i0 ObjectEntity INTEGER(4)
130 integer block_size, num_teams, block_threads, i, i0
131 !REF: /dotprod/sum
132 sum = 0.0e0
133 !$omp target map(to:b,c) map(tofrom:sum)
134 !$omp teams num_teams(num_teams) thread_limit(block_threads) reduction(+:sum)
135 !$omp distribute
136 !DEF: /dotprod/Block1/Block1/Block1/i0 (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
137 !REF: /dotprod/n
138 !REF: /dotprod/block_size
139 do i0=1,n,block_size
140 !$omp parallel do reduction(+:sum)
141 !DEF: /dotprod/Block1/Block1/Block1/Block1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
142 !REF: /dotprod/Block1/Block1/Block1/i0
143 !DEF: /dotprod/min ELEMENTAL, INTRINSIC, PURE (Function) ProcEntity
144 !REF: /dotprod/block_size
145 !REF: /dotprod/n
146 do i=i0,min(i0+block_size, n)
147 !DEF: /dotprod/Block1/Block1/Block1/Block1/sum (OmpReduction) HostAssoc REAL(4)
148 !REF: /dotprod/b
149 !REF: /dotprod/Block1/Block1/Block1/Block1/i
150 !REF: /dotprod/c
151 sum = sum+b(i)*c(i)
152 end do
153 end do
154 !$omp end teams
155 !$omp end target
156 !REF: /dotprod/sum
157 print *, sum
158 end subroutine dotprod
160 ! Rule b)
161 ! TODO: nested constructs (j, k should be private too)
162 !DEF: /test_simd (Subroutine) Subprogram
163 subroutine test_simd
164 implicit none
165 !DEF: /test_simd/a ObjectEntity REAL(4)
166 real a(20,20,20)
167 !DEF: /test_simd/i ObjectEntity INTEGER(4)
168 !DEF: /test_simd/j ObjectEntity INTEGER(4)
169 !DEF: /test_simd/k ObjectEntity INTEGER(4)
170 integer i, j, k
171 !$omp parallel do simd
172 !DEF: /test_simd/Block1/i (OmpLinear, OmpPreDetermined) HostAssoc INTEGER(4)
173 do i=1,5
174 !DEF: /test_simd/Block1/j (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
175 do j=6,10
176 !DEF: /test_simd/Block1/k (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
177 do k=11,15
178 !REF: /test_simd/a
179 !REF: /test_simd/Block1/k
180 !REF: /test_simd/Block1/j
181 !REF: /test_simd/Block1/i
182 a(k,j,i) = 3.14
183 end do
184 end do
185 end do
186 end subroutine test_simd
188 ! Rule c)
189 !DEF: /test_simd_multi (Subroutine) Subprogram
190 subroutine test_simd_multi
191 implicit none
192 !DEF: /test_simd_multi/a ObjectEntity REAL(4)
193 real a(20,20,20)
194 !DEF: /test_simd_multi/i ObjectEntity INTEGER(4)
195 !DEF: /test_simd_multi/j ObjectEntity INTEGER(4)
196 !DEF: /test_simd_multi/k ObjectEntity INTEGER(4)
197 integer i, j, k
198 !$omp parallel do simd collapse(3)
199 !DEF: /test_simd_multi/Block1/i (OmpLastPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
200 do i=1,5
201 !DEF: /test_simd_multi/Block1/j (OmpLastPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
202 do j=6,10
203 !DEF: /test_simd_multi/Block1/k (OmpLastPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
204 do k=11,15
205 !REF: /test_simd_multi/a
206 !REF: /test_simd_multi/Block1/k
207 !REF: /test_simd_multi/Block1/j
208 !REF: /test_simd_multi/Block1/i
209 a(k,j,i) = 3.14
210 end do
211 end do
212 end do
213 end subroutine test_simd_multi
215 ! Rule d)
216 !DEF: /test_seq_loop (Subroutine) Subprogram
217 subroutine test_seq_loop
218 implicit none
219 !DEF: /test_seq_loop/i ObjectEntity INTEGER(4)
220 !DEF: /test_seq_loop/j ObjectEntity INTEGER(4)
221 integer i, j
222 !REF: /test_seq_loop/i
223 i = -1
224 !REF: /test_seq_loop/j
225 j = -1
226 !$omp parallel
227 !REF: /test_seq_loop/i
228 !REF: /test_seq_loop/j
229 print *, i, j
230 !$omp parallel
231 !REF: /test_seq_loop/i
232 !DEF: /test_seq_loop/Block1/Block1/j (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
233 print *, i, j
234 !$omp do
235 !DEF: /test_seq_loop/Block1/Block1/Block1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
236 do i=1,10
237 !REF: /test_seq_loop/Block1/Block1/j
238 do j=1,10
239 end do
240 end do
241 !REF: /test_seq_loop/i
242 !REF: /test_seq_loop/Block1/Block1/j
243 print *, i, j
244 !$omp end parallel
245 !REF: /test_seq_loop/i
246 !REF: /test_seq_loop/j
247 print *, i, j
248 !$omp end parallel
249 !REF: /test_seq_loop/i
250 !REF: /test_seq_loop/j
251 print *, i, j
252 end subroutine test_seq_loop