3 ! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
5 !*** Test forall with multiple assignment statements and mask
6 subroutine test3_forall_construct(a
,b
, mask
)
7 real :: a(100,400), b(200,200)
8 logical :: mask(100,200)
9 forall (i
=1:100, j
=1:200, mask(i
,j
))
10 a(i
,j
) = b(i
,j
) + b(i
+1,j
)
11 a(i
,200+j
) = 1.0 / b(j
, i
)
13 end subroutine test3_forall_construct
15 ! CHECK-LABEL: func @_QPtest3_forall_construct(
16 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<100x400xf32>>{{.*}}, %[[VAL_1:.*]]: !fir.ref<!fir.array<200x200xf32>>{{.*}}, %[[VAL_2:.*]]: !fir.ref<!fir.array<100x200x!fir.logical<4>>>{{.*}}) {
17 ! CHECK: %[[VAL_3:.*]] = fir.alloca i32 {adapt.valuebyref, bindc_name = "j"}
18 ! CHECK: %[[VAL_4:.*]] = fir.alloca i32 {adapt.valuebyref, bindc_name = "i"}
19 ! CHECK: %[[VAL_5:.*]] = fir.alloca i32 {adapt.valuebyref, bindc_name = "j"}
20 ! CHECK: %[[VAL_6:.*]] = fir.alloca i32 {adapt.valuebyref, bindc_name = "i"}
21 ! CHECK: %[[VAL_7:.*]] = arith.constant 100 : index
22 ! CHECK: %[[VAL_8:.*]] = arith.constant 400 : index
23 ! CHECK: %[[VAL_9:.*]] = arith.constant 200 : index
24 ! CHECK: %[[VAL_10:.*]] = arith.constant 200 : index
25 ! CHECK: %[[VAL_11:.*]] = arith.constant 1 : i32
26 ! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (i32) -> index
27 ! CHECK: %[[VAL_13:.*]] = arith.constant 100 : i32
28 ! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (i32) -> index
29 ! CHECK: %[[VAL_15:.*]] = arith.constant 1 : index
30 ! CHECK: %[[VAL_16:.*]] = arith.constant 1 : i32
31 ! CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_16]] : (i32) -> index
32 ! CHECK: %[[VAL_18:.*]] = arith.constant 200 : i32
33 ! CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_18]] : (i32) -> index
34 ! CHECK: %[[VAL_20:.*]] = arith.constant 1 : index
35 ! CHECK: %[[VAL_21:.*]] = fir.shape %[[VAL_7]], %[[VAL_8]] : (index, index) -> !fir.shape<2>
36 ! CHECK: %[[VAL_22:.*]] = fir.array_load %[[VAL_0]](%[[VAL_21]]) : (!fir.ref<!fir.array<100x400xf32>>, !fir.shape<2>) -> !fir.array<100x400xf32>
37 ! CHECK: %[[VAL_23:.*]] = fir.shape %[[VAL_9]], %[[VAL_10]] : (index, index) -> !fir.shape<2>
38 ! CHECK: %[[VAL_24:.*]] = fir.array_load %[[VAL_1]](%[[VAL_23]]) : (!fir.ref<!fir.array<200x200xf32>>, !fir.shape<2>) -> !fir.array<200x200xf32>
39 ! CHECK: %[[VAL_25:.*]] = fir.shape %[[VAL_9]], %[[VAL_10]] : (index, index) -> !fir.shape<2>
40 ! CHECK: %[[VAL_26:.*]] = fir.array_load %[[VAL_1]](%[[VAL_25]]) : (!fir.ref<!fir.array<200x200xf32>>, !fir.shape<2>) -> !fir.array<200x200xf32>
41 ! CHECK: %[[VAL_27:.*]] = fir.do_loop %[[VAL_28:.*]] = %[[VAL_12]] to %[[VAL_14]] step %[[VAL_15]] unordered iter_args(%[[VAL_29:.*]] = %[[VAL_22]]) -> (!fir.array<100x400xf32>) {
42 ! CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_28]] : (index) -> i32
43 ! CHECK: fir.store %[[VAL_30]] to %[[VAL_6]] : !fir.ref<i32>
44 ! CHECK: %[[VAL_31:.*]] = fir.do_loop %[[VAL_32:.*]] = %[[VAL_17]] to %[[VAL_19]] step %[[VAL_20]] unordered iter_args(%[[VAL_33:.*]] = %[[VAL_29]]) -> (!fir.array<100x400xf32>) {
45 ! CHECK: %[[VAL_34:.*]] = fir.convert %[[VAL_32]] : (index) -> i32
46 ! CHECK: fir.store %[[VAL_34]] to %[[VAL_5]] : !fir.ref<i32>
47 ! CHECK: %[[VAL_35:.*]] = fir.load %[[VAL_6]] : !fir.ref<i32>
48 ! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_35]] : (i32) -> i64
49 ! CHECK: %[[VAL_37:.*]] = arith.constant 1 : i64
50 ! CHECK: %[[VAL_38:.*]] = arith.subi %[[VAL_36]], %[[VAL_37]] : i64
51 ! CHECK: %[[VAL_39:.*]] = fir.load %[[VAL_5]] : !fir.ref<i32>
52 ! CHECK: %[[VAL_40:.*]] = fir.convert %[[VAL_39]] : (i32) -> i64
53 ! CHECK: %[[VAL_41:.*]] = arith.constant 1 : i64
54 ! CHECK: %[[VAL_42:.*]] = arith.subi %[[VAL_40]], %[[VAL_41]] : i64
55 ! CHECK: %[[VAL_43:.*]] = fir.coordinate_of %[[VAL_2]], %[[VAL_38]], %[[VAL_42]] : (!fir.ref<!fir.array<100x200x!fir.logical<4>>>, i64, i64) -> !fir.ref<!fir.logical<4>>
56 ! CHECK: %[[VAL_44:.*]] = fir.load %[[VAL_43]] : !fir.ref<!fir.logical<4>>
57 ! CHECK: %[[VAL_45:.*]] = fir.convert %[[VAL_44]] : (!fir.logical<4>) -> i1
58 ! CHECK: %[[VAL_46:.*]] = fir.if %[[VAL_45]] -> (!fir.array<100x400xf32>) {
59 ! CHECK: %[[VAL_47:.*]] = arith.constant 1 : index
60 ! CHECK: %[[VAL_48:.*]] = fir.load %[[VAL_6]] : !fir.ref<i32>
61 ! CHECK: %[[VAL_49:.*]] = fir.convert %[[VAL_48]] : (i32) -> i64
62 ! CHECK: %[[VAL_50:.*]] = fir.convert %[[VAL_49]] : (i64) -> index
63 ! CHECK: %[[VAL_51:.*]] = arith.subi %[[VAL_50]], %[[VAL_47]] : index
64 ! CHECK: %[[VAL_52:.*]] = fir.load %[[VAL_5]] : !fir.ref<i32>
65 ! CHECK: %[[VAL_53:.*]] = fir.convert %[[VAL_52]] : (i32) -> i64
66 ! CHECK: %[[VAL_54:.*]] = fir.convert %[[VAL_53]] : (i64) -> index
67 ! CHECK: %[[VAL_55:.*]] = arith.subi %[[VAL_54]], %[[VAL_47]] : index
68 ! CHECK: %[[VAL_67:.*]] = fir.array_fetch %[[VAL_24]], %[[VAL_51]], %[[VAL_55]] : (!fir.array<200x200xf32>, index, index) -> f32
69 ! CHECK: %[[VAL_56:.*]] = arith.constant 1 : index
70 ! CHECK-DAG: %[[VAL_57:.*]] = fir.load %[[VAL_6]] : !fir.ref<i32>
71 ! CHECK-DAG: %[[VAL_58:.*]] = arith.constant 1 : i32
72 ! CHECK: %[[VAL_59:.*]] = arith.addi %[[VAL_57]], %[[VAL_58]] : i32
73 ! CHECK: %[[VAL_60:.*]] = fir.convert %[[VAL_59]] : (i32) -> i64
74 ! CHECK: %[[VAL_61:.*]] = fir.convert %[[VAL_60]] : (i64) -> index
75 ! CHECK: %[[VAL_62:.*]] = arith.subi %[[VAL_61]], %[[VAL_56]] : index
76 ! CHECK: %[[VAL_63:.*]] = fir.load %[[VAL_5]] : !fir.ref<i32>
77 ! CHECK: %[[VAL_64:.*]] = fir.convert %[[VAL_63]] : (i32) -> i64
78 ! CHECK: %[[VAL_65:.*]] = fir.convert %[[VAL_64]] : (i64) -> index
79 ! CHECK: %[[VAL_66:.*]] = arith.subi %[[VAL_65]], %[[VAL_56]] : index
80 ! CHECK: %[[VAL_68:.*]] = fir.array_fetch %[[VAL_26]], %[[VAL_62]], %[[VAL_66]] : (!fir.array<200x200xf32>, index, index) -> f32
81 ! CHECK: %[[VAL_69:.*]] = arith.addf %[[VAL_67]], %[[VAL_68]] {{.*}}: f32
82 ! CHECK: %[[VAL_70:.*]] = arith.constant 1 : index
83 ! CHECK: %[[VAL_71:.*]] = fir.load %[[VAL_6]] : !fir.ref<i32>
84 ! CHECK: %[[VAL_72:.*]] = fir.convert %[[VAL_71]] : (i32) -> i64
85 ! CHECK: %[[VAL_73:.*]] = fir.convert %[[VAL_72]] : (i64) -> index
86 ! CHECK: %[[VAL_74:.*]] = arith.subi %[[VAL_73]], %[[VAL_70]] : index
87 ! CHECK: %[[VAL_75:.*]] = fir.load %[[VAL_5]] : !fir.ref<i32>
88 ! CHECK: %[[VAL_76:.*]] = fir.convert %[[VAL_75]] : (i32) -> i64
89 ! CHECK: %[[VAL_77:.*]] = fir.convert %[[VAL_76]] : (i64) -> index
90 ! CHECK: %[[VAL_78:.*]] = arith.subi %[[VAL_77]], %[[VAL_70]] : index
91 ! CHECK: %[[VAL_79:.*]] = fir.array_update %[[VAL_33]], %[[VAL_69]], %[[VAL_74]], %[[VAL_78]] : (!fir.array<100x400xf32>, f32, index, index) -> !fir.array<100x400xf32>
92 ! CHECK: fir.result %[[VAL_79]] : !fir.array<100x400xf32>
94 ! CHECK: fir.result %[[VAL_33]] : !fir.array<100x400xf32>
96 ! CHECK: fir.result %[[VAL_80:.*]] : !fir.array<100x400xf32>
98 ! CHECK: fir.result %[[VAL_81:.*]] : !fir.array<100x400xf32>
100 ! CHECK: fir.array_merge_store %[[VAL_22]], %[[VAL_82:.*]] to %[[VAL_0]] : !fir.array<100x400xf32>, !fir.array<100x400xf32>, !fir.ref<!fir.array<100x400xf32>>
101 ! CHECK: %[[VAL_83:.*]] = fir.shape %[[VAL_7]], %[[VAL_8]] : (index, index) -> !fir.shape<2>
102 ! CHECK: %[[VAL_84:.*]] = fir.array_load %[[VAL_0]](%[[VAL_83]]) : (!fir.ref<!fir.array<100x400xf32>>, !fir.shape<2>) -> !fir.array<100x400xf32>
103 ! CHECK: %[[VAL_85:.*]] = fir.shape %[[VAL_9]], %[[VAL_10]] : (index, index) -> !fir.shape<2>
104 ! CHECK: %[[VAL_86:.*]] = fir.array_load %[[VAL_1]](%[[VAL_85]]) : (!fir.ref<!fir.array<200x200xf32>>, !fir.shape<2>) -> !fir.array<200x200xf32>
105 ! CHECK: %[[VAL_87:.*]] = fir.do_loop %[[VAL_88:.*]] = %[[VAL_12]] to %[[VAL_14]] step %[[VAL_15]] unordered iter_args(%[[VAL_89:.*]] = %[[VAL_84]]) -> (!fir.array<100x400xf32>) {
106 ! CHECK: %[[VAL_90:.*]] = fir.convert %[[VAL_88]] : (index) -> i32
107 ! CHECK: fir.store %[[VAL_90]] to %[[VAL_4]] : !fir.ref<i32>
108 ! CHECK: %[[VAL_91:.*]] = fir.do_loop %[[VAL_92:.*]] = %[[VAL_17]] to %[[VAL_19]] step %[[VAL_20]] unordered iter_args(%[[VAL_93:.*]] = %[[VAL_89]]) -> (!fir.array<100x400xf32>) {
109 ! CHECK: %[[VAL_94:.*]] = fir.convert %[[VAL_92]] : (index) -> i32
110 ! CHECK: fir.store %[[VAL_94]] to %[[VAL_3]] : !fir.ref<i32>
111 ! CHECK: %[[VAL_95:.*]] = fir.load %[[VAL_4]] : !fir.ref<i32>
112 ! CHECK: %[[VAL_96:.*]] = fir.convert %[[VAL_95]] : (i32) -> i64
113 ! CHECK: %[[VAL_97:.*]] = arith.constant 1 : i64
114 ! CHECK: %[[VAL_98:.*]] = arith.subi %[[VAL_96]], %[[VAL_97]] : i64
115 ! CHECK: %[[VAL_99:.*]] = fir.load %[[VAL_3]] : !fir.ref<i32>
116 ! CHECK: %[[VAL_100:.*]] = fir.convert %[[VAL_99]] : (i32) -> i64
117 ! CHECK: %[[VAL_101:.*]] = arith.constant 1 : i64
118 ! CHECK: %[[VAL_102:.*]] = arith.subi %[[VAL_100]], %[[VAL_101]] : i64
119 ! CHECK: %[[VAL_103:.*]] = fir.coordinate_of %[[VAL_2]], %[[VAL_98]], %[[VAL_102]] : (!fir.ref<!fir.array<100x200x!fir.logical<4>>>, i64, i64) -> !fir.ref<!fir.logical<4>>
120 ! CHECK: %[[VAL_104:.*]] = fir.load %[[VAL_103]] : !fir.ref<!fir.logical<4>>
121 ! CHECK: %[[VAL_105:.*]] = fir.convert %[[VAL_104]] : (!fir.logical<4>) -> i1
122 ! CHECK: %[[VAL_106:.*]] = fir.if %[[VAL_105]] -> (!fir.array<100x400xf32>) {
123 ! CHECK: %[[VAL_107:.*]] = arith.constant 1.000000e+00 : f32
124 ! CHECK: %[[VAL_108:.*]] = arith.constant 1 : index
125 ! CHECK: %[[VAL_109:.*]] = fir.load %[[VAL_3]] : !fir.ref<i32>
126 ! CHECK: %[[VAL_110:.*]] = fir.convert %[[VAL_109]] : (i32) -> i64
127 ! CHECK: %[[VAL_111:.*]] = fir.convert %[[VAL_110]] : (i64) -> index
128 ! CHECK: %[[VAL_112:.*]] = arith.subi %[[VAL_111]], %[[VAL_108]] : index
129 ! CHECK: %[[VAL_113:.*]] = fir.load %[[VAL_4]] : !fir.ref<i32>
130 ! CHECK: %[[VAL_114:.*]] = fir.convert %[[VAL_113]] : (i32) -> i64
131 ! CHECK: %[[VAL_115:.*]] = fir.convert %[[VAL_114]] : (i64) -> index
132 ! CHECK: %[[VAL_116:.*]] = arith.subi %[[VAL_115]], %[[VAL_108]] : index
133 ! CHECK: %[[VAL_117:.*]] = fir.array_fetch %[[VAL_86]], %[[VAL_112]], %[[VAL_116]] : (!fir.array<200x200xf32>, index, index) -> f32
134 ! CHECK: %[[VAL_118:.*]] = arith.divf %[[VAL_107]], %[[VAL_117]] {{.*}}: f32
135 ! CHECK: %[[VAL_119:.*]] = arith.constant 1 : index
136 ! CHECK: %[[VAL_120:.*]] = fir.load %[[VAL_4]] : !fir.ref<i32>
137 ! CHECK: %[[VAL_121:.*]] = fir.convert %[[VAL_120]] : (i32) -> i64
138 ! CHECK: %[[VAL_122:.*]] = fir.convert %[[VAL_121]] : (i64) -> index
139 ! CHECK: %[[VAL_123:.*]] = arith.subi %[[VAL_122]], %[[VAL_119]] : index
140 ! CHECK: %[[VAL_124:.*]] = arith.constant 200 : i32
141 ! CHECK: %[[VAL_125:.*]] = fir.load %[[VAL_3]] : !fir.ref<i32>
142 ! CHECK: %[[VAL_126:.*]] = arith.addi %[[VAL_124]], %[[VAL_125]] : i32
143 ! CHECK: %[[VAL_127:.*]] = fir.convert %[[VAL_126]] : (i32) -> i64
144 ! CHECK: %[[VAL_128:.*]] = fir.convert %[[VAL_127]] : (i64) -> index
145 ! CHECK: %[[VAL_129:.*]] = arith.subi %[[VAL_128]], %[[VAL_119]] : index
146 ! CHECK: %[[VAL_130:.*]] = fir.array_update %[[VAL_93]], %[[VAL_118]], %[[VAL_123]], %[[VAL_129]] : (!fir.array<100x400xf32>, f32, index, index) -> !fir.array<100x400xf32>
147 ! CHECK: fir.result %[[VAL_130]] : !fir.array<100x400xf32>
149 ! CHECK: fir.result %[[VAL_93]] : !fir.array<100x400xf32>
151 ! CHECK: fir.result %[[VAL_131:.*]] : !fir.array<100x400xf32>
153 ! CHECK: fir.result %[[VAL_132:.*]] : !fir.array<100x400xf32>
155 ! CHECK: fir.array_merge_store %[[VAL_84]], %[[VAL_133:.*]] to %[[VAL_0]] : !fir.array<100x400xf32>, !fir.array<100x400xf32>, !fir.ref<!fir.array<100x400xf32>>