[RISCV] Rename a lambda to have plural nouns to reflect that it contains a loop. NFC
[llvm-project.git] / flang / test / Lower / forall / forall-allocatable-2.f90
blob95bd290f27350469e4a0cb7c52106ca066ea8c22
1 ! Test forall lowering
3 ! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
5 subroutine forall_with_allocatable2(a1)
6 real :: a1(:)
7 type t
8 integer :: i
9 real, allocatable :: arr(:)
10 end type t
11 type(t) :: thing
12 forall (i=5:15)
13 thing%arr(i) = a1(i)
14 end forall
15 end subroutine forall_with_allocatable2
17 ! CHECK-LABEL: func @_QPforall_with_allocatable2(
18 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) {
19 ! CHECK: %[[VAL_1:.*]] = fir.alloca i32 {adapt.valuebyref, bindc_name = "i"}
20 ! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.type<_QFforall_with_allocatable2Tt{i:i32,arr:!fir.box<!fir.heap<!fir.array<?xf32>>>}> {bindc_name = "thing", uniq_name = "_QFforall_with_allocatable2Ething"}
21 ! CHECK: %[[VAL_3:.*]] = fir.embox %[[VAL_2]] : (!fir.ref<!fir.type<_QFforall_with_allocatable2Tt{i:i32,arr:!fir.box<!fir.heap<!fir.array<?xf32>>>}>>) -> !fir.box<!fir.type<_QFforall_with_allocatable2Tt{i:i32,arr:!fir.box<!fir.heap<!fir.array<?xf32>>>}>>
22 ! CHECK: %[[VAL_4:.*]] = fir.address_of(@_QQclX{{.*}}) : !fir.ref<!fir.char<1,
23 ! CHECK: %[[VAL_5:.*]] = arith.constant {{.*}} : i32
24 ! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_3]] : (!fir.box<!fir.type<_QFforall_with_allocatable2Tt{i:i32,arr:!fir.box<!fir.heap<!fir.array<?xf32>>>}>>) -> !fir.box<none>
25 ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_4]] : (!fir.ref<!fir.char<1,{{.*}}>>) -> !fir.ref<i8>
26 ! CHECK: %[[VAL_8:.*]] = fir.call @_FortranAInitialize(%[[VAL_6]], %[[VAL_7]], %[[VAL_5]]) {{.*}}: (!fir.box<none>, !fir.ref<i8>, i32) -> none
27 ! CHECK: %[[VAL_9:.*]] = arith.constant 5 : i32
28 ! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (i32) -> index
29 ! CHECK: %[[VAL_11:.*]] = arith.constant 15 : i32
30 ! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (i32) -> index
31 ! CHECK: %[[VAL_13:.*]] = arith.constant 1 : index
32 ! CHECK: %[[VAL_14:.*]] = fir.field_index arr, !fir.type<_QFforall_with_allocatable2Tt{i:i32,arr:!fir.box<!fir.heap<!fir.array<?xf32>>>}>
33 ! CHECK: %[[VAL_15:.*]] = fir.coordinate_of %[[VAL_2]], %[[VAL_14]] : (!fir.ref<!fir.type<_QFforall_with_allocatable2Tt{i:i32,arr:!fir.box<!fir.heap<!fir.array<?xf32>>>}>>, !fir.field) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
34 ! CHECK: %[[VAL_16:.*]] = fir.load %[[VAL_15]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
35 ! CHECK: %[[VAL_17:.*]] = arith.constant 0 : index
36 ! CHECK: %[[VAL_18:.*]]:3 = fir.box_dims %[[VAL_16]], %[[VAL_17]] : (!fir.box<!fir.heap<!fir.array<?xf32>>>, index) -> (index, index, index)
37 ! CHECK: %[[VAL_19:.*]] = fir.box_addr %[[VAL_16]] : (!fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.heap<!fir.array<?xf32>>
38 ! CHECK: %[[VAL_20:.*]] = fir.shape_shift %[[VAL_18]]#0, %[[VAL_18]]#1 : (index, index) -> !fir.shapeshift<1>
39 ! CHECK: %[[VAL_21:.*]] = fir.array_load %[[VAL_19]](%[[VAL_20]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shapeshift<1>) -> !fir.array<?xf32>
40 ! CHECK: %[[VAL_22:.*]] = fir.array_load %[[VAL_0]] : (!fir.box<!fir.array<?xf32>>) -> !fir.array<?xf32>
41 ! CHECK: %[[VAL_23:.*]] = fir.do_loop %[[VAL_24:.*]] = %[[VAL_10]] to %[[VAL_12]] step %[[VAL_13]] unordered iter_args(%[[VAL_25:.*]] = %[[VAL_21]]) -> (!fir.array<?xf32>) {
42 ! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_24]] : (index) -> i32
43 ! CHECK: fir.store %[[VAL_26]] to %[[VAL_1]] : !fir.ref<i32>
44 ! CHECK: %[[VAL_27:.*]] = arith.constant 1 : index
45 ! CHECK: %[[VAL_28:.*]] = fir.load %[[VAL_1]] : !fir.ref<i32>
46 ! CHECK: %[[VAL_29:.*]] = fir.convert %[[VAL_28]] : (i32) -> i64
47 ! CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_29]] : (i64) -> index
48 ! CHECK: %[[VAL_31:.*]] = arith.subi %[[VAL_30]], %[[VAL_27]] : index
49 ! CHECK: %[[VAL_32:.*]] = fir.array_fetch %[[VAL_22]], %[[VAL_31]] : (!fir.array<?xf32>, index) -> f32
50 ! CHECK: %[[VAL_33:.*]] = arith.constant 1 : index
51 ! CHECK: %[[VAL_34:.*]] = fir.load %[[VAL_1]] : !fir.ref<i32>
52 ! CHECK: %[[VAL_35:.*]] = fir.convert %[[VAL_34]] : (i32) -> i64
53 ! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_35]] : (i64) -> index
54 ! CHECK: %[[VAL_37:.*]] = arith.subi %[[VAL_36]], %[[VAL_33]] : index
55 ! CHECK: %[[VAL_38:.*]] = fir.array_update %[[VAL_25]], %[[VAL_32]], %[[VAL_37]] : (!fir.array<?xf32>, f32, index) -> !fir.array<?xf32>
56 ! CHECK: fir.result %[[VAL_38]] : !fir.array<?xf32>
57 ! CHECK: }
58 ! CHECK: fir.array_merge_store %[[VAL_21]], %[[VAL_39:.*]] to %[[VAL_19]] : !fir.array<?xf32>, !fir.array<?xf32>, !fir.heap<!fir.array<?xf32>>
59 ! CHECK: return
60 ! CHECK: }