Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / forall / forall-construct.f90
blobb4296a71028d5a0c47374fbedb6920e122a7a909
1 ! Test forall lowering
3 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
5 !*** Test a FORALL construct
6 subroutine test_forall_construct(a,b)
7 integer :: i, j
8 real :: a(:,:), b(:,:)
9 forall (i=1:ubound(a,1), j=1:ubound(a,2), b(j,i) > 0.0)
10 a(i,j) = b(j,i) / 3.14
11 end forall
12 end subroutine test_forall_construct
14 ! CHECK-LABEL: func @_QPtest_forall_construct(
15 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x?xf32>>{{.*}}, %[[VAL_1:.*]]: !fir.box<!fir.array<?x?xf32>>{{.*}}) {
16 ! CHECK: %[[VAL_2:.*]] = fir.alloca i32 {adapt.valuebyref, bindc_name = "j"}
17 ! CHECK: %[[VAL_3:.*]] = fir.alloca i32 {adapt.valuebyref, bindc_name = "i"}
18 ! CHECK: %[[VAL_4:.*]] = arith.constant 1 : i32
19 ! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i32) -> index
20 ! CHECK: %[[VAL_6:.*]] = arith.constant 0 : index
21 ! CHECK: %[[VAL_7:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_6]] : (!fir.box<!fir.array<?x?xf32>>, index) -> (index, index, index)
22 ! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]]#1 : (index) -> i64
23 ! CHECK: %[[VAL_9:.*]] = arith.constant 1 : index
24 ! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (index) -> i64
25 ! CHECK: %[[VAL_11:.*]] = arith.addi %[[VAL_8]], %[[VAL_10]] : i64
26 ! CHECK: %[[VAL_12:.*]] = arith.constant 1 : i64
27 ! CHECK: %[[VAL_13:.*]] = arith.subi %[[VAL_11]], %[[VAL_12]] : i64
28 ! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (i64) -> i32
29 ! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_14]] : (i32) -> index
30 ! CHECK: %[[VAL_16:.*]] = arith.constant 1 : index
31 ! CHECK: %[[VAL_17:.*]] = arith.constant 1 : i32
32 ! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (i32) -> index
33 ! CHECK: %[[VAL_19:.*]] = arith.constant 1 : index
34 ! CHECK: %[[VAL_20:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_19]] : (!fir.box<!fir.array<?x?xf32>>, index) -> (index, index, index)
35 ! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]]#1 : (index) -> i64
36 ! CHECK: %[[VAL_22:.*]] = arith.constant 1 : index
37 ! CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_22]] : (index) -> i64
38 ! CHECK: %[[VAL_24:.*]] = arith.addi %[[VAL_21]], %[[VAL_23]] : i64
39 ! CHECK: %[[VAL_25:.*]] = arith.constant 1 : i64
40 ! CHECK: %[[VAL_26:.*]] = arith.subi %[[VAL_24]], %[[VAL_25]] : i64
41 ! CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_26]] : (i64) -> i32
42 ! CHECK: %[[VAL_28:.*]] = fir.convert %[[VAL_27]] : (i32) -> index
43 ! CHECK: %[[VAL_29:.*]] = arith.constant 1 : index
44 ! CHECK: %[[VAL_30:.*]] = fir.array_load %[[VAL_0]] : (!fir.box<!fir.array<?x?xf32>>) -> !fir.array<?x?xf32>
45 ! CHECK: %[[VAL_31:.*]] = fir.array_load %[[VAL_1]] : (!fir.box<!fir.array<?x?xf32>>) -> !fir.array<?x?xf32>
46 ! CHECK: %[[VAL_32:.*]] = fir.do_loop %[[VAL_33:.*]] = %[[VAL_5]] to %[[VAL_15]] step %[[VAL_16]] unordered iter_args(%[[VAL_34:.*]] = %[[VAL_30]]) -> (!fir.array<?x?xf32>) {
47 ! CHECK: %[[VAL_35:.*]] = fir.convert %[[VAL_33]] : (index) -> i32
48 ! CHECK: fir.store %[[VAL_35]] to %[[VAL_3]] : !fir.ref<i32>
49 ! CHECK: %[[VAL_36:.*]] = fir.do_loop %[[VAL_37:.*]] = %[[VAL_18]] to %[[VAL_28]] step %[[VAL_29]] unordered iter_args(%[[VAL_38:.*]] = %[[VAL_34]]) -> (!fir.array<?x?xf32>) {
50 ! CHECK: %[[VAL_39:.*]] = fir.convert %[[VAL_37]] : (index) -> i32
51 ! CHECK: fir.store %[[VAL_39]] to %[[VAL_2]] : !fir.ref<i32>
52 ! CHECK: %[[VAL_40:.*]] = fir.load %[[VAL_2]] : !fir.ref<i32>
53 ! CHECK: %[[VAL_41:.*]] = fir.convert %[[VAL_40]] : (i32) -> i64
54 ! CHECK: %[[VAL_42:.*]] = arith.constant 1 : i64
55 ! CHECK: %[[VAL_43:.*]] = arith.subi %[[VAL_41]], %[[VAL_42]] : i64
56 ! CHECK: %[[VAL_44:.*]] = fir.load %[[VAL_3]] : !fir.ref<i32>
57 ! CHECK: %[[VAL_45:.*]] = fir.convert %[[VAL_44]] : (i32) -> i64
58 ! CHECK: %[[VAL_46:.*]] = arith.constant 1 : i64
59 ! CHECK: %[[VAL_47:.*]] = arith.subi %[[VAL_45]], %[[VAL_46]] : i64
60 ! CHECK: %[[VAL_48:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_43]], %[[VAL_47]] : (!fir.box<!fir.array<?x?xf32>>, i64, i64) -> !fir.ref<f32>
61 ! CHECK: %[[VAL_49:.*]] = fir.load %[[VAL_48]] : !fir.ref<f32>
62 ! CHECK: %[[VAL_50:.*]] = arith.constant 0.000000e+00 : f32
63 ! CHECK: %[[VAL_51:.*]] = arith.cmpf ogt, %[[VAL_49]], %[[VAL_50]] : f32
64 ! CHECK: %[[VAL_52:.*]] = fir.if %[[VAL_51]] -> (!fir.array<?x?xf32>) {
65 ! CHECK: %[[VAL_53:.*]] = arith.constant 1 : index
66 ! CHECK: %[[VAL_54:.*]] = fir.load %[[VAL_2]] : !fir.ref<i32>
67 ! CHECK: %[[VAL_55:.*]] = fir.convert %[[VAL_54]] : (i32) -> i64
68 ! CHECK: %[[VAL_56:.*]] = fir.convert %[[VAL_55]] : (i64) -> index
69 ! CHECK: %[[VAL_57:.*]] = arith.subi %[[VAL_56]], %[[VAL_53]] : index
70 ! CHECK: %[[VAL_58:.*]] = fir.load %[[VAL_3]] : !fir.ref<i32>
71 ! CHECK: %[[VAL_59:.*]] = fir.convert %[[VAL_58]] : (i32) -> i64
72 ! CHECK: %[[VAL_60:.*]] = fir.convert %[[VAL_59]] : (i64) -> index
73 ! CHECK: %[[VAL_61:.*]] = arith.subi %[[VAL_60]], %[[VAL_53]] : index
74 ! CHECK-DAG: %[[VAL_62:.*]] = arith.constant 3.140000e+00 : f32
75 ! CHECK-DAG: %[[VAL_63:.*]] = fir.array_fetch %[[VAL_31]], %[[VAL_57]], %[[VAL_61]] : (!fir.array<?x?xf32>, index, index) -> f32
76 ! CHECK: %[[VAL_64:.*]] = arith.divf %[[VAL_63]], %[[VAL_62]] {{.*}}: f32
77 ! CHECK: %[[VAL_65:.*]] = arith.constant 1 : index
78 ! CHECK: %[[VAL_66:.*]] = fir.load %[[VAL_3]] : !fir.ref<i32>
79 ! CHECK: %[[VAL_67:.*]] = fir.convert %[[VAL_66]] : (i32) -> i64
80 ! CHECK: %[[VAL_68:.*]] = fir.convert %[[VAL_67]] : (i64) -> index
81 ! CHECK: %[[VAL_69:.*]] = arith.subi %[[VAL_68]], %[[VAL_65]] : index
82 ! CHECK: %[[VAL_70:.*]] = fir.load %[[VAL_2]] : !fir.ref<i32>
83 ! CHECK: %[[VAL_71:.*]] = fir.convert %[[VAL_70]] : (i32) -> i64
84 ! CHECK: %[[VAL_72:.*]] = fir.convert %[[VAL_71]] : (i64) -> index
85 ! CHECK: %[[VAL_73:.*]] = arith.subi %[[VAL_72]], %[[VAL_65]] : index
86 ! CHECK: %[[VAL_74:.*]] = fir.array_update %[[VAL_38]], %[[VAL_64]], %[[VAL_69]], %[[VAL_73]] : (!fir.array<?x?xf32>, f32, index, index) -> !fir.array<?x?xf32>
87 ! CHECK: fir.result %[[VAL_74]] : !fir.array<?x?xf32>
88 ! CHECK: } else {
89 ! CHECK: fir.result %[[VAL_38]] : !fir.array<?x?xf32>
90 ! CHECK: }
91 ! CHECK: fir.result %[[VAL_75:.*]] : !fir.array<?x?xf32>
92 ! CHECK: }
93 ! CHECK: fir.result %[[VAL_76:.*]] : !fir.array<?x?xf32>
94 ! CHECK: }
95 ! CHECK: fir.array_merge_store %[[VAL_30]], %[[VAL_77:.*]] to %[[VAL_0]] : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.box<!fir.array<?x?xf32>>
96 ! CHECK: return
97 ! CHECK: }