[flang][openacc] Use OpenACC terminator instead of fir.unreachable after Stop stmt...
[llvm-project.git] / flang / test / Lower / cray-pointer.f90
blobc9f3a4ca88ac35b9087484a0f27ade15faa2482c
1 ! RUN: bbc %s -emit-fir -o - | FileCheck %s
2 ! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
4 ! Test Cray Pointers
6 ! Test Scalar Case
8 ! CHECK-LABEL: func.func @_QPcray_scalar() {
9 subroutine cray_scalar()
10 integer :: i, pte
11 integer :: data = 3
12 integer :: j = -3
13 pointer(ptr, pte)
14 ptr = loc(data)
16 ! CHECK: %[[data:.*]] = fir.address_of(@_QFcray_scalarEdata) {{.*}}
17 ! CHECK: %[[i:.*]] = fir.alloca i32 {{.*}}
18 ! CHECK: %[[j:.*]] = fir.address_of(@_QFcray_scalarEj) {{.*}}
19 ! CHECK: %[[ptr:.*]] = fir.alloca i64 {{.*}}
20 ! CHECK: %[[databox:.*]] = fir.embox %[[data]] : (!fir.ref<i32>) -> !fir.box<i32>
21 ! CHECK: %[[dataaddr:.*]] = fir.box_addr %[[databox]] : (!fir.box<i32>) -> !fir.ref<i32>
22 ! CHECK: %[[dataaddrval:.*]] = fir.convert %[[dataaddr]] : (!fir.ref<i32>) -> i64
23 ! CHECK: fir.store %[[dataaddrval]] to %[[ptr]] : !fir.ref<i64>
25 i = pte
26 print *, i
28 ! CHECK: %[[ptrbox:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<i64>
29 ! CHECK: %[[ptraddr:.*]] = fir.box_addr %[[ptrbox]] : (!fir.box<i64>) -> !fir.ref<i64>
30 ! CHECK: %[[ptraddrval:.*]] = fir.convert %[[ptraddr]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<i32>>
31 ! CHECK: %[[ptrld:.*]] = fir.load %[[ptraddrval]] : !fir.ref<!fir.ptr<i32>>
32 ! CHECK: %[[ptrldd:.*]] = fir.load %[[ptrld]] : !fir.ptr<i32>
33 ! CHECK: fir.store %[[ptrldd]] to %[[i]] : !fir.ref<i32>
35 pte = j
36 print *, data, pte
38 ! CHECK: %[[jld:.*]] = fir.load %[[j]] : !fir.ref<i32>
39 ! CHECK: %[[ptrbox1:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<i64>
40 ! CHECK: %[[ptraddr1:.*]] = fir.box_addr %[[ptrbox1]] : (!fir.box<i64>) -> !fir.ref<i64>
41 ! CHECK: %[[ptraddrval1:.*]] = fir.convert %[[ptraddr1]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<i32>>
42 ! CHECK: %[[ptrld1:.*]] = fir.load %[[ptraddrval1]] : !fir.ref<!fir.ptr<i32>>
43 ! CHECK: fir.store %[[jld]] to %[[ptrld1]] : !fir.ptr<i32>
45 end
47 ! Test Derived Type Case
49 ! CHECK-LABEL: func.func @_QPcray_derivedtype() {
50 subroutine cray_derivedType()
51 integer :: pte, k
52 type dt
53 integer :: i, j
54 end type
55 type(dt) :: xdt
56 pointer(ptr, pte)
57 xdt = dt(-1, -3)
58 ptr = loc(xdt)
60 ! CHECK: %[[dt:.*]] = fir.alloca !fir.type<_QFcray_derivedtypeTdt{i:i32,j:i32}>
61 ! CHECK: %[[k:.*]] = fir.alloca i32 {{.*}}
62 ! CHECK: %[[pte:.*]] = fir.alloca i32 {{.*}}
63 ! CHECK: %[[ptr:.*]] = fir.alloca i64 {{.*}}
64 ! CHECK: %[[xdt:.*]] = fir.alloca !fir.type<_QFcray_derivedtypeTdt{i:i32,j:i32}> {{.*}}
65 ! CHECK: %[[xdtbox:.*]] = fir.embox %[[xdt]] : (!fir.ref<!fir.type<_QFcray_derivedtypeTdt{i:i32,j:i32}>>) -> !fir.box<!fir.type<_QFcray_derivedtypeTdt{i:i32,j:i32}>>
66 ! CHECK: %[[xdtaddr:.*]] = fir.box_addr %[[xdtbox]] : (!fir.box<!fir.type<_QFcray_derivedtypeTdt{i:i32,j:i32}>>) -> !fir.ref<!fir.type<_QFcray_derivedtypeTdt{i:i32,j:i32}>>
67 ! CHECK: %[[xdtaddrval:.*]] = fir.convert %[[xdtaddr]] : (!fir.ref<!fir.type<_QFcray_derivedtypeTdt{i:i32,j:i32}>>) -> i64
68 ! CHECK: fir.store %[[xdtaddrval]] to %[[ptr]] : !fir.ref<i64>
70 k = pte
71 print *, k
73 ! CHECK: %[[ptrbox:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<i64>
74 ! CHECK: %[[ptraddr:.*]] = fir.box_addr %[[ptrbox]] : (!fir.box<i64>) -> !fir.ref<i64>
75 ! CHECK: %[[ptraddrval:.*]] = fir.convert %[[ptraddr]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<i32>>
76 ! CHECK: %[[ptrld:.*]] = fir.load %[[ptraddrval]] : !fir.ref<!fir.ptr<i32>>
77 ! CHECK: %[[ptrldd:.*]] = fir.load %[[ptrld]] : !fir.ptr<i32>
78 ! CHECK: fir.store %[[ptrldd]] to %[[k]] : !fir.ref<i32>
80 pte = k + 2
81 print *, xdt, pte
83 ! CHECK: %[[kld:.*]] = fir.load %[[k]] : !fir.ref<i32>
84 ! CHECK: %[[kld1:.*]] = fir.load %[[k]] : !fir.ref<i32>
85 ! CHECK: %[[const:.*]] = arith.constant 2 : i32
86 ! CHECK: %[[add:.*]] = arith.addi %[[kld1]], %[[const]] : i32
87 ! CHECK: %[[ptrbox1:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<i64>
88 ! CHECK: %[[ptraddr1:.*]] = fir.box_addr %[[ptrbox1]] : (!fir.box<i64>) -> !fir.ref<i64>
89 ! CHECK: %[[ptraddrval1:.*]] = fir.convert %[[ptraddr1]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<i32>>
90 ! CHECK: %[[ptrld1:.*]] = fir.load %[[ptraddrval1]] : !fir.ref<!fir.ptr<i32>>
91 ! CHECK: fir.store %[[add]] to %[[ptrld1]] : !fir.ptr<i32>
93 end
95 ! Test Ptr arithmetic Case
97 ! CHECK-LABEL: func.func @_QPcray_ptrarth() {
98 subroutine cray_ptrArth()
99 integer :: pte, i
100 pointer(ptr, pte)
101 type dt
102 integer :: x, y, z
103 end type
104 type(dt) :: xdt
105 xdt = dt(5, 11, 2)
106 ptr = loc(xdt)
108 ! CHECK: %[[dt:.*]] = fir.alloca !fir.type<_QFcray_ptrarthTdt{x:i32,y:i32,z:i32}>
109 ! CHECK: %[[i:.*]] = fir.alloca i32 {{.*}}
110 ! CHECK: %[[pte:.*]] = fir.alloca i32 {{.*}}
111 ! CHECK: %[[ptr:.*]] = fir.alloca i64 {{.*}}
112 ! CHECK: %[[xdt:.*]] = fir.alloca !fir.type<_QFcray_ptrarthTdt{x:i32,y:i32,z:i32}> {{.*}}
113 ! CHECK: %[[xdtbox:.*]] = fir.embox %[[xdt]] : (!fir.ref<!fir.type<_QFcray_ptrarthTdt{x:i32,y:i32,z:i32}>>) -> !fir.box<!fir.type<_QFcray_ptrarthTdt{x:i32,y:i32,z:i32}>>
114 ! CHECK: %[[xdtaddr:.*]] = fir.box_addr %[[xdtbox]] : (!fir.box<!fir.type<_QFcray_ptrarthTdt{x:i32,y:i32,z:i32}>>) -> !fir.ref<!fir.type<_QFcray_ptrarthTdt{x:i32,y:i32,z:i32}>>
115 ! CHECK: %[[xdtaddrval:.*]] = fir.convert %[[xdtaddr]] : (!fir.ref<!fir.type<_QFcray_ptrarthTdt{x:i32,y:i32,z:i32}>>) -> i64
116 ! CHECK: fir.store %[[xdtaddrval]] to %[[ptr]] : !fir.ref<i64>
118 ptr = ptr + 4
119 i = pte
120 print *, i
122 ! CHECK: %[[ptrbox:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<i64>
123 ! CHECK: %[[ptraddr:.*]] = fir.box_addr %[[ptrbox]] : (!fir.box<i64>) -> !fir.ref<i64>
124 ! CHECK: %[[ptraddrval:.*]] = fir.convert %[[ptraddr]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<i32>>
125 ! CHECK: %[[ptrld:.*]] = fir.load %[[ptraddrval]] : !fir.ref<!fir.ptr<i32>>
126 ! CHECK: %[[ptrldd:.*]] = fir.load %[[ptrld]] : !fir.ptr<i32>
127 ! CHECK: fir.store %[[ptrldd]] to %[[i]] : !fir.ref<i32>
129 ptr = ptr + 4
130 pte = -7
131 print *, xdt
133 ! CHECK: %[[ld:.*]] = fir.load %[[ptr]] : !fir.ref<i64>
134 ! CHECK: %[[const:.*]] = arith.constant 4 : i64
135 ! CHECK: %[[add:.*]] = arith.addi %[[ld]], %[[const]] : i64
136 ! CHECK: fir.store %[[add]] to %[[ptr]] : !fir.ref<i64>
137 ! CHECK: %[[const1:.*]] = arith.constant -7 : i32
138 ! CHECK: %[[ptrbox1:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<i64>
139 ! CHECK: %[[ptraddr1:.*]] = fir.box_addr %[[ptrbox1]] : (!fir.box<i64>) -> !fir.ref<i64>
140 ! CHECK: %[[ptraddrval1:.*]] = fir.convert %[[ptraddr1]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<i32>>
141 ! CHECK: %[[ptrld1:.*]] = fir.load %[[ptraddrval1]] : !fir.ref<!fir.ptr<i32>>
142 ! CHECK: fir.store %[[const1]] to %[[ptrld1]] : !fir.ptr<i32>
146 ! Test Array element Case
148 ! CHECK-LABEL: func.func @_QPcray_arrayelement() {
149 subroutine cray_arrayElement()
150 integer :: pte, k, data(5)
151 pointer (ptr, pte(3))
152 data = [ 1, 2, 3, 4, 5 ]
153 ptr = loc(data(2))
155 ! CHECK: %[[data:.*]] = fir.alloca !fir.array<5xi32> {{.*}}
156 ! CHECK: %[[k:.*]] = fir.alloca i32 {{.*}}
157 ! CHECK: %[[pte:.*]] = fir.alloca !fir.array<3xi32> {{.*}}
158 ! CHECK: %[[ptr:.*]] = fir.alloca i64 {{.*}}
159 ! CHECK: %[[c2:.*]] = arith.constant 2 : i64
160 ! CHECK: %[[c1:.*]] = arith.constant 1 : i64
161 ! CHECK: %[[sub:.*]] = arith.subi %[[c2]], %[[c1]] : i64
162 ! CHECK: %[[cor:.*]] = fir.coordinate_of %[[data]], %[[sub]] : (!fir.ref<!fir.array<5xi32>>, i64) -> !fir.ref<i32>
163 ! CHECK: %[[box:.*]] = fir.embox %[[cor]] : (!fir.ref<i32>) -> !fir.box<i32>
164 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<i32>) -> !fir.ref<i32>
165 ! CHECK: %[[val:.*]] = fir.convert %[[addr]] : (!fir.ref<i32>) -> i64
166 ! CHECK: fir.store %[[val]] to %[[ptr]] : !fir.ref<i64>
168 k = pte(3)
169 print *, k
171 ! CHECK: %[[c3:.*]] = arith.constant 3 : i64
172 ! CHECK: %[[c1:.*]] = arith.constant 1 : i64
173 ! CHECK: %[[sub:.*]] = arith.subi %[[c3]], %[[c1]] : i64
174 ! CHECK: %[[box:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<!fir.ref<i64>>
175 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.ref<i64>>) -> !fir.ref<i64>
176 ! CHECK: %[[val:.*]] = fir.convert %[[addr]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<!fir.array<3xi32>>>
177 ! CHECK: %[[ld1:.*]] = fir.load %[[val]] : !fir.ref<!fir.ptr<!fir.array<3xi32>>>
178 ! CHECK: %[[cor:.*]] = fir.coordinate_of %[[ld1]], %[[sub]] : (!fir.ptr<!fir.array<3xi32>>, i64) -> !fir.ref<i32>
179 ! CHECK: %[[ld2:.*]] = fir.load %[[cor]] : !fir.ref<i32>
180 ! CHECK: fir.store %[[ld2]] to %[[k]] : !fir.ref<i32>
182 pte(2) = -2
183 print *, data
185 ! CHECK: %[[c2n:.*]] = arith.constant -2 : i32
186 ! CHECK: %[[c2:.*]] = arith.constant 2 : i64
187 ! CHECK: %[[c1:.*]] = arith.constant 1 : i64
188 ! CHECK: %[[sub:.*]] = arith.subi %[[c2]], %[[c1]] : i64
189 ! CHECK: %[[box:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<!fir.ref<i64>>
190 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.ref<i64>>) -> !fir.ref<i64>
191 ! CHECK: %[[val:.*]] = fir.convert %[[addr]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<!fir.array<3xi32>>>
192 ! CHECK: %[[ld1:.*]] = fir.load %[[val]] : !fir.ref<!fir.ptr<!fir.array<3xi32>>>
193 ! CHECK: %[[cor:.*]] = fir.coordinate_of %[[ld1]], %[[sub]] : (!fir.ptr<!fir.array<3xi32>>, i64) -> !fir.ref<i32>
194 ! CHECK: fir.store %[[c2n]] to %[[cor]] : !fir.ref<i32>
198 ! Test 2d Array element Case
200 ! CHECK-LABEL: func.func @_QPcray_2darrayelement() {
201 subroutine cray_2darrayElement()
202 integer :: pte, k, data(2,4)
203 pointer (ptr, pte(2,3))
204 data = reshape([1,2,3,4,5,6,7,8], [2,4])
205 ptr = loc(data(2,2))
207 ! CHECK: %[[data:.*]] = fir.alloca !fir.array<2x4xi32> {{.*}}
208 ! CHECK: %[[k:.*]] = fir.alloca i32 {{.*}}
209 ! CHECK: %[[pte:.*]] = fir.alloca !fir.array<2x3xi32> {{.*}}
210 ! CHECK: %[[ptr:.*]] = fir.alloca i64 {{.*}}
211 ! CHECK: %[[c2:.*]] = arith.constant 2 : i64
212 ! CHECK: %[[c1:.*]] = arith.constant 1 : i64
213 ! CHECK: %[[sub1:.*]] = arith.subi %[[c2]], %[[c1]] : i64
214 ! CHECK: %[[c22:.*]] = arith.constant 2 : i64
215 ! CHECK: %[[c12:.*]] = arith.constant 1 : i64
216 ! CHECK: %[[sub2:.*]] = arith.subi %[[c22]], %[[c12]] : i64
217 ! CHECK: %[[cor:.*]] = fir.coordinate_of %[[data]], %[[sub1]], %[[sub2]] : (!fir.ref<!fir.array<2x4xi32>>, i64, i64) -> !fir.ref<i32>
218 ! CHECK: %[[box:.*]] = fir.embox %[[cor]] : (!fir.ref<i32>) -> !fir.box<i32>
219 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<i32>) -> !fir.ref<i32>
220 ! CHECK: %[[val:.*]] = fir.convert %[[addr]] : (!fir.ref<i32>) -> i64
221 ! CHECK: fir.store %[[val]] to %[[ptr]] : !fir.ref<i64>
223 k = pte(1,1)
224 print *, k
226 ! CHECK: %[[c2:.*]] = arith.constant 1 : i64
227 ! CHECK: %[[c1:.*]] = arith.constant 1 : i64
228 ! CHECK: %[[sub1:.*]] = arith.subi %[[c2]], %[[c1]] : i64
229 ! CHECK: %[[c22:.*]] = arith.constant 1 : i64
230 ! CHECK: %[[c12:.*]] = arith.constant 1 : i64
231 ! CHECK: %[[sub2:.*]] = arith.subi %[[c22]], %[[c12]] : i64
232 ! CHECK: %[[box:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<!fir.ref<i64>>
233 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.ref<i64>>) -> !fir.ref<i64>
234 ! CHECK: %[[val:.*]] = fir.convert %[[addr]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<!fir.array<2x3xi32>>>
235 ! CHECK: %[[ld1:.*]] = fir.load %[[val]] : !fir.ref<!fir.ptr<!fir.array<2x3xi32>>>
236 ! CHECK: %[[cor:.*]] = fir.coordinate_of %[[ld1]], %[[sub1]], %[[sub2]] : (!fir.ptr<!fir.array<2x3xi32>>, i64, i64) -> !fir.ref<i32>
237 ! CHECK: %[[ld2:.*]] = fir.load %[[cor]] : !fir.ref<i32>
238 ! CHECK: fir.store %[[ld2]] to %[[k]] : !fir.ref<i32>
240 pte(1,2) = -2
241 print *, data
243 ! CHECK: %[[c2n:.*]] = arith.constant -2 : i32
244 ! CHECK: %[[c2:.*]] = arith.constant 1 : i64
245 ! CHECK: %[[c1:.*]] = arith.constant 1 : i64
246 ! CHECK: %[[sub1:.*]] = arith.subi %[[c2]], %[[c1]] : i64
247 ! CHECK: %[[c22:.*]] = arith.constant 2 : i64
248 ! CHECK: %[[c12:.*]] = arith.constant 1 : i64
249 ! CHECK: %[[sub2:.*]] = arith.subi %[[c22]], %[[c12]] : i64
250 ! CHECK: %[[box:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<!fir.ref<i64>>
251 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.ref<i64>>) -> !fir.ref<i64>
252 ! CHECK: %[[val:.*]] = fir.convert %[[addr]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<!fir.array<2x3xi32>>>
253 ! CHECK: %[[ld1:.*]] = fir.load %[[val]] : !fir.ref<!fir.ptr<!fir.array<2x3xi32>>>
254 ! CHECK: %[[cor:.*]] = fir.coordinate_of %[[ld1]], %[[sub1]], %[[sub2]] : (!fir.ptr<!fir.array<2x3xi32>>, i64, i64) -> !fir.ref<i32>
255 ! CHECK: fir.store %[[c2n]] to %[[cor]] : !fir.ref<i32>
259 ! Test Whole Array case
261 ! CHECK-LABEL: func.func @_QPcray_array() {
262 subroutine cray_array()
263 integer :: pte, k(3), data(5)
264 pointer (ptr, pte(3))
265 data = [ 1, 2, 3, 4, 5 ]
266 ptr = loc(data(2))
268 ! CHECK: %[[data:.*]] = fir.alloca !fir.array<5xi32> {{.*}}
269 ! CHECK: %[[c3:.*]] = arith.constant 3 : index
270 ! CHECK: %[[k:.*]] = fir.alloca !fir.array<3xi32> {{.*}}
271 ! CHECK: %[[c31:.*]] = arith.constant 3 : index
272 ! CHECK: %[[pte:.*]] = fir.alloca !fir.array<3xi32> {{.*}}
273 ! CHECK: %[[ptr:.*]] = fir.alloca i64 {{.*}}
274 ! CHECK: %[[c2:.*]] = arith.constant 2 : i64
275 ! CHECK: %[[c1:.*]] = arith.constant 1 : i64
276 ! CHECK: %[[sub:.*]] = arith.subi %[[c2]], %[[c1]] : i64
277 ! CHECK: %[[cor:.*]] = fir.coordinate_of %[[data]], %[[sub]] : (!fir.ref<!fir.array<5xi32>>, i64) -> !fir.ref<i32>
278 ! CHECK: %[[box:.*]] = fir.embox %[[cor]] : (!fir.ref<i32>) -> !fir.box<i32>
279 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<i32>) -> !fir.ref<i32>
280 ! CHECK: %[[val:.*]] = fir.convert %[[addr]] : (!fir.ref<i32>) -> i64
281 ! CHECK: fir.store %[[val]] to %[[ptr]] : !fir.ref<i64>
283 k = pte
284 print *, k
286 ! CHECK: %[[shape1:.*]] = fir.shape %[[c3]] : (index) -> !fir.shape<1>
287 ! CHECK: %[[arrayld1:.*]] = fir.array_load %[[k]](%[[shape1]]) : (!fir.ref<!fir.array<3xi32>>, !fir.shape<1>) -> !fir.array<3xi32>
288 ! CHECK: %[[shape:.*]] = fir.shape %[[c31]] : (index) -> !fir.shape<1>
289 ! CHECK: %[[box:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<!fir.ref<i64>>
290 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.ref<i64>>) -> !fir.ref<i64>
291 ! CHECK: %[[val:.*]] = fir.convert %[[addr]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<!fir.array<3xi32>>>
292 ! CHECK: %[[ld:.*]] = fir.load %[[val]] : !fir.ref<!fir.ptr<!fir.array<3xi32>>>
293 ! CHECK: %[[arrayld:.*]] = fir.array_load %[[ld]](%[[shape]]) : (!fir.ptr<!fir.array<3xi32>>, !fir.shape<1>) -> !fir.array<3xi32>
294 ! CHECK: %[[c1:.*]] = arith.constant 1 : index
295 ! CHECK: %[[c0:.*]] = arith.constant 0 : index
296 ! CHECK: %[[sub:.*]] = arith.subi %[[c3]], %[[c1]] : index
297 ! CHECK: %[[doloop:.*]] = fir.do_loop %arg0 = %[[c0]] to %[[sub]] step %[[c1]] unordered iter_args(%arg1 = %[[arrayld1]]) -> (!fir.array<3xi32>) {
298 ! CHECK: %[[arrayfetch:.*]] = fir.array_fetch %[[arrayld]], %arg0 : (!fir.array<3xi32>, index) -> i32
299 ! CHECK: %[[arrayupdate:.*]] = fir.array_update %arg1, %[[arrayfetch]], %arg0 : (!fir.array<3xi32>, i32, index) -> !fir.array<3xi32>
300 ! CHECK: fir.result %[[arrayupdate]] : !fir.array<3xi32>
301 ! CHECK: fir.array_merge_store %[[arrayld1]], %[[doloop]] to %[[k]] : !fir.array<3xi32>, !fir.array<3xi32>, !fir.ref<!fir.array<3xi32>>
303 pte = -2
304 print *, data
306 ! CHECK: %[[shape:.*]] = fir.shape %[[c31]] : (index) -> !fir.shape<1>
307 ! CHECK: %[[box:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<!fir.ref<i64>>
308 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.ref<i64>>) -> !fir.ref<i64>
309 ! CHECK: %[[val:.*]] = fir.convert %[[addr]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<!fir.array<3xi32>>>
310 ! CHECK: %[[ld:.*]] = fir.load %[[val]] : !fir.ref<!fir.ptr<!fir.array<3xi32>>>
311 ! CHECK: %[[arrayld:.*]] = fir.array_load %[[ld]](%[[shape]]) : (!fir.ptr<!fir.array<3xi32>>, !fir.shape<1>) -> !fir.array<3xi32>
312 ! CHECK: %[[c2n:.*]] = arith.constant -2 : i32
313 ! CHECK: %[[c1:.*]] = arith.constant 1 : index
314 ! CHECK: %[[c0:.*]] = arith.constant 0 : index
315 ! CHECK: %[[sub1:.*]] = arith.subi %[[c31]], %[[c1]] : index
316 ! CHECK: %[[doloop:.*]] = fir.do_loop %arg0 = %[[c0]] to %[[sub1]] step %[[c1]] unordered iter_args(%arg1 = %[[arrayld]]) -> (!fir.array<3xi32>) {
317 ! CHECK: %[[arrayupdate:.*]] = fir.array_update %arg1, %[[c2n]], %arg0 : (!fir.array<3xi32>, i32, index) -> !fir.array<3xi32>
318 ! CHECK: fir.result %[[arrayupdate]] : !fir.array<3xi32>
319 ! CHECK: fir.array_merge_store %[[arrayld]], %[[doloop]] to %[[ld]] : !fir.array<3xi32>, !fir.array<3xi32>, !fir.ptr<!fir.array<3xi32>>
322 ! Test Array Section case
324 ! CHECK-LABEL: func.func @_QPcray_arraysection() {
325 subroutine cray_arraySection()
326 integer :: pte, k(2), data(5)
327 pointer (ptr, pte(3))
328 data = [ 1, 2, 3, 4, 5 ]
329 ptr = loc(data(2))
331 ! CHECK: %[[c5:.*]] = arith.constant 5 : index
332 ! CHECK: %[[data:.*]] = fir.alloca !fir.array<5xi32> {{.*}}
333 ! CHECK: %[[c2:.*]] = arith.constant 2 : index
334 ! CHECK: %[[k:.*]] = fir.alloca !fir.array<2xi32> {{.*}}
335 ! CHECK: %[[c3:.*]] = arith.constant 3 : index
336 ! CHECK: %[[pte:.*]] = fir.alloca !fir.array<3xi32> {{.*}}
337 ! CHECK: %[[ptr:.*]] = fir.alloca i64 {{.*}}
338 ! CHECK: %[[c1:.*]] = arith.constant 2 : i64
339 ! CHECK: %[[c0:.*]] = arith.constant 1 : i64
340 ! CHECK: %[[sub:.*]] = arith.subi %[[c1]], %[[c0]] : i64
341 ! CHECK: %[[cor:.*]] = fir.coordinate_of %[[data]], %[[sub]] : (!fir.ref<!fir.array<5xi32>>, i64) -> !fir.ref<i32>
342 ! CHECK: %[[box:.*]] = fir.embox %[[cor]] : (!fir.ref<i32>) -> !fir.box<i32>
343 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<i32>) -> !fir.ref<i32>
344 ! CHECK: %[[val:.*]] = fir.convert %[[addr]] : (!fir.ref<i32>) -> i64
345 ! CHECK: fir.store %[[val]] to %[[ptr]] : !fir.ref<i64>
347 k = pte(2:3)
348 print *, k
350 ! CHECK: %[[shape1:.*]] = fir.shape %[[c2]] : (index) -> !fir.shape<1>
351 ! CHECK: %[[arrayld1:.*]] = fir.array_load %[[k]](%[[shape1]]) : (!fir.ref<!fir.array<2xi32>>, !fir.shape<1>) -> !fir.array<2xi32>
352 ! CHECK: %[[c2i64:.*]] = arith.constant 2 : i64
353 ! CHECK: %[[conv:.*]] = fir.convert %[[c2i64]] : (i64) -> index
354 ! CHECK: %[[c1i64:.*]] = arith.constant 1 : i64
355 ! CHECK: %[[conv1:.*]] = fir.convert %[[c1i64]] : (i64) -> index
356 ! CHECK: %[[c3i64:.*]] = arith.constant 3 : i64
357 ! CHECK: %[[conv2:.*]] = fir.convert %[[c3i64]] : (i64) -> index
358 ! CHECK: %[[shape:.*]] = fir.shape %[[c3]] : (index) -> !fir.shape<1>
359 ! CHECK: %[[slice:.*]] = fir.slice %[[conv]], %[[conv2]], %[[conv1]] : (index, index, index) -> !fir.slice<1>
360 ! CHECK: %[[box:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<!fir.ref<i64>>
361 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.ref<i64>>) -> !fir.ref<i64>
362 ! CHECK: %[[val:.*]] = fir.convert %[[addr]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<!fir.array<3xi32>>>
363 ! CHECK: %[[ld:.*]] = fir.load %[[val]] : !fir.ref<!fir.ptr<!fir.array<3xi32>>>
364 ! CHECK: %[[arrayld:.*]] = fir.array_load %[[ld]](%[[shape]]) [%[[slice]]] : (!fir.ptr<!fir.array<3xi32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.array<3xi32>
365 ! CHECK: %[[c1_3:.*]] = arith.constant 1 : index
366 ! CHECK: %[[c0_4:.*]] = arith.constant 0 : index
367 ! CHECK: %[[sub:.*]] = arith.subi %[[c2]], %[[c1_3]] : index
368 ! CHECK: %[[doloop:.*]] = fir.do_loop %arg0 = %[[c0_4]] to %[[sub]] step %[[c1_3]] unordered iter_args(%arg1 = %[[arrayld1]]) -> (!fir.array<2xi32>) {
369 ! CHECK: %[[arrayfetch:.*]] = fir.array_fetch %[[arrayld]], %arg0 : (!fir.array<3xi32>, index) -> i32
370 ! CHECK: %[[arrayupdate:.*]] = fir.array_update %arg1, %[[arrayfetch]], %arg0 : (!fir.array<2xi32>, i32, index) -> !fir.array<2xi32>
371 ! CHECK: fir.result %[[arrayupdate]] : !fir.array<2xi32>
372 ! CHECK: fir.array_merge_store %[[arrayld1]], %[[doloop]] to %[[k]] : !fir.array<2xi32>, !fir.array<2xi32>, !fir.ref<!fir.array<2xi32>>
374 pte(1:2) = -2
375 print *, data
377 ! CHECK: %[[c1_5:.*]] = arith.constant 1 : i64
378 ! CHECK: %[[conv:.*]] = fir.convert %[[c1_5]] : (i64) -> index
379 ! CHECK: %[[c1_6:.*]] = arith.constant 1 : i64
380 ! CHECK: %[[conv1:.*]] = fir.convert %[[c1_6]] : (i64) -> index
381 ! CHECK: %[[c2_7:.*]] = arith.constant 2 : i64
382 ! CHECK: %[[conv2:.*]] = fir.convert %[[c2_7]] : (i64) -> index
383 ! CHECK: %[[c0_8:.*]] = arith.constant 0 : index
384 ! CHECK: %[[sub:.*]] = arith.subi %[[conv2]], %[[conv]] : index
385 ! CHECK: %[[add:.*]] = arith.addi %[[sub]], %[[conv1]] : index
386 ! CHECK: %[[div:.*]] = arith.divsi %[[add]], %[[conv1]] : index
387 ! CHECK: %[[cmp:.*]] = arith.cmpi sgt, %[[div]], %[[c0_8]] : index
388 ! CHECK: %[[sel:.*]] = arith.select %[[cmp]], %[[div]], %[[c0_8]] : index
389 ! CHECK: %[[shape:.*]] = fir.shape %[[c3]] : (index) -> !fir.shape<1>
390 ! CHECK: %[[slice:.*]] = fir.slice %[[conv]], %[[conv2]], %[[conv1]] : (index, index, index) -> !fir.slice<1>
391 ! CHECK: %[[box:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<!fir.ref<i64>>
392 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.ref<i64>>) -> !fir.ref<i64>
393 ! CHECK: %[[val:.*]] = fir.convert %[[addr]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<!fir.array<3xi32>>>
394 ! CHECK: %[[ld:.*]] = fir.load %[[val]] : !fir.ref<!fir.ptr<!fir.array<3xi32>>>
395 ! CHECK: %[[arrayld:.*]] = fir.array_load %[[ld]](%[[shape]]) [%[[slice]]] : (!fir.ptr<!fir.array<3xi32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.array<3xi32>
396 ! CHECK: %[[c2n:.*]] = arith.constant -2 : i32
397 ! CHECK: %[[c1_9:.*]] = arith.constant 1 : index
398 ! CHECK: %[[c0_8:.*]] = arith.constant 0 : index
399 ! CHECK: %[[sub1:.*]] = arith.subi %[[sel]], %[[c1_9]] : index
400 ! CHECK: %[[doloop:.*]] = fir.do_loop %arg0 = %[[c0_8]] to %[[sub1]] step %[[c1_9]] unordered iter_args(%arg1 = %[[arrayld]]) -> (!fir.array<3xi32>) {
401 ! CHECK: %[[arrayupdate:.*]] = fir.array_update %arg1, %[[c2n]], %arg0 : (!fir.array<3xi32>, i32, index) -> !fir.array<3xi32>
402 ! CHECK: fir.result %[[arrayupdate]] : !fir.array<3xi32>
403 ! CHECK: fir.array_merge_store %[[arrayld]], %[[doloop]] to %[[ld]][%[[slice]]] : !fir.array<3xi32>, !fir.array<3xi32>, !fir.ptr<!fir.array<3xi32>>, !fir.slice<1>
406 ! Test Cray pointer declared in a module
407 module mod_cray_ptr
408 integer :: pte
409 pointer(ptr, pte)
410 end module
412 ! CHECK-LABEL: @_QPtest_ptr
413 subroutine test_ptr()
414 use mod_cray_ptr
415 implicit none
416 integer :: x
417 ptr = loc(x)
418 ! CHECK: %[[ptr:.*]] = fir.address_of(@_QMmod_cray_ptrEptr) : !fir.ref<i64>
419 ! CHECK: %[[x:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFtest_ptrEx"}
420 ! CHECK: %[[box:.*]] = fir.embox %[[x]] : (!fir.ref<i32>) -> !fir.box<i32>
421 ! CHECK: %[[boxAddr:.*]] = fir.box_addr %[[box]] : (!fir.box<i32>) -> !fir.ref<i32>
422 ! CHECK: %[[addr_x:.*]] = fir.convert %[[boxAddr]] : (!fir.ref<i32>) -> i64
423 ! CHECK: fir.store %[[addr_x]] to %[[ptr]] : !fir.ref<i64>
426 subroutine test_pte()
427 use mod_cray_ptr
428 implicit none
429 integer :: x
430 pte = x
431 ! CHECK: %[[ptr:.*]] = fir.address_of(@_QMmod_cray_ptrEptr) : !fir.ref<i64>
432 ! CHECK: %[[x:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFtest_pteEx"}
433 ! CHECK: %[[xval:.*]] = fir.load %[[x]] : !fir.ref<i32>
434 ! CHECK: %[[box:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<i64>
435 ! CHECK: %[[boxAddr:.*]] = fir.box_addr %[[box]] : (!fir.box<i64>) -> !fir.ref<i64>
436 ! CHECK: %[[ptr2:.*]] = fir.convert %[[boxAddr]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<i32>>
437 ! CHECK: %[[ptr2val:.*]] = fir.load %[[ptr2]] : !fir.ref<!fir.ptr<i32>>
438 ! CHECK: fir.store %[[xval]] to %[[ptr2val]] : !fir.ptr<i32>
440 x = pte
441 ! CHECK: %[[box2:.*]] = fir.embox %[[ptr]] : (!fir.ref<i64>) -> !fir.box<i64>
442 ! CHECK: %[[box2Addr:.*]] = fir.box_addr %[[box2]] : (!fir.box<i64>) -> !fir.ref<i64>
443 ! CHECK: %[[refptr:.*]] = fir.convert %[[box2Addr]] : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<i32>>
444 ! CHECK: %[[ptr4:.*]] = fir.load %[[refptr]] : !fir.ref<!fir.ptr<i32>>
445 ! CHECK: %[[val:.*]] = fir.load %[[ptr4]] : !fir.ptr<i32>
446 ! CHECK: fir.store %[[val]] to %[[x]] : !fir.ref<i32>