1
+ ! RUN: bbc -emit-fir %s -o - | FileCheck %s
2
+
3
+ program nested_where
4
+ integer :: a(3 ) = 0
5
+ logical :: mask1(3 ) = (/ .true. ,.false. ,.true. / )
6
+ logical :: mask2(3 ) = (/ .true. ,.true. ,.false. / )
7
+ forall (i= 1 :3 )
8
+ where (mask1)
9
+ where (mask2)
10
+ a = 1
11
+ end where
12
+ endwhere
13
+ end forall
14
+ end program nested_where
15
+
16
+ ! CHECK-LABEL: func @_QQmain() {
17
+ ! CHECK: %[[VAL_0:.*]] = fir.alloca i32 {adapt.valuebyref, bindc_name = "i"}
18
+ ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.heap<index>
19
+ ! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.heap<i8>
20
+ ! CHECK: %[[VAL_3:.*]] = fir.alloca !fir.heap<index>
21
+ ! CHECK: %[[VAL_4:.*]] = fir.alloca !fir.heap<i8>
22
+ ! CHECK: %[[VAL_5:.*]] = fir.address_of(@_QEa) : !fir.ref<!fir.array<3xi32>>
23
+ ! CHECK: %[[VAL_6:.*]] = constant 3 : index
24
+ ! CHECK: %[[VAL_7:.*]] = fir.address_of(@_QEmask1) : !fir.ref<!fir.array<3x!fir.logical<4>>>
25
+ ! CHECK: %[[VAL_8:.*]] = constant 3 : index
26
+ ! CHECK: %[[VAL_9:.*]] = fir.address_of(@_QEmask2) : !fir.ref<!fir.array<3x!fir.logical<4>>>
27
+ ! CHECK: %[[VAL_10:.*]] = constant 3 : index
28
+ ! CHECK: %[[VAL_11:.*]] = fir.zero_bits !fir.heap<i8>
29
+ ! CHECK: fir.store %[[VAL_11]] to %[[VAL_4]] : !fir.ref<!fir.heap<i8>>
30
+ ! CHECK: %[[VAL_12:.*]] = fir.zero_bits !fir.heap<index>
31
+ ! CHECK: fir.store %[[VAL_12]] to %[[VAL_3]] : !fir.ref<!fir.heap<index>>
32
+ ! CHECK: %[[VAL_13:.*]] = fir.zero_bits !fir.heap<i8>
33
+ ! CHECK: fir.store %[[VAL_13]] to %[[VAL_2]] : !fir.ref<!fir.heap<i8>>
34
+ ! CHECK: %[[VAL_14:.*]] = fir.zero_bits !fir.heap<index>
35
+ ! CHECK: fir.store %[[VAL_14]] to %[[VAL_1]] : !fir.ref<!fir.heap<index>>
36
+ ! CHECK: %[[VAL_15:.*]] = constant 1 : i32
37
+ ! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (i32) -> index
38
+ ! CHECK: %[[VAL_17:.*]] = constant 3 : i32
39
+ ! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (i32) -> index
40
+ ! CHECK: %[[VAL_19:.*]] = constant 1 : index
41
+ ! CHECK: %[[VAL_20:.*]] = fir.shape %[[VAL_6]] : (index) -> !fir.shape<1>
42
+ ! CHECK: %[[VAL_21:.*]] = fir.array_load %[[VAL_5]](%[[VAL_20]]) : (!fir.ref<!fir.array<3xi32>>, !fir.shape<1>) -> !fir.array<3xi32>
43
+ ! CHECK: %[[VAL_22:.*]] = fir.do_loop %[[VAL_23:.*]] = %[[VAL_16]] to %[[VAL_18]] step %[[VAL_19]] unordered iter_args(%[[VAL_24:.*]] = %[[VAL_21]]) -> (!fir.array<3xi32>) {
44
+ ! CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_23]] : (index) -> i32
45
+ ! CHECK: fir.store %[[VAL_25]] to %[[VAL_0]] : !fir.ref<i32>
46
+ ! CHECK: %[[VAL_26:.*]] = fir.shape %[[VAL_6]] : (index) -> !fir.shape<1>
47
+ ! CHECK: %[[VAL_27:.*]] = fir.array_load %[[VAL_5]](%[[VAL_26]]) : (!fir.ref<!fir.array<3xi32>>, !fir.shape<1>) -> !fir.array<3xi32>
48
+ ! CHECK: %[[VAL_28:.*]] = constant 3 : i64
49
+ ! CHECK: %[[VAL_29:.*]] = fir.convert %[[VAL_28]] : (i64) -> index
50
+ ! CHECK: %[[VAL_30:.*]] = constant 1 : i32
51
+ ! CHECK: %[[VAL_31:.*]] = fir.shape %[[VAL_8]] : (index) -> !fir.shape<1>
52
+ ! CHECK: %[[VAL_32:.*]] = fir.array_load %[[VAL_7]](%[[VAL_31]]) : (!fir.ref<!fir.array<3x!fir.logical<4>>>, !fir.shape<1>) -> !fir.array<3x!fir.logical<4>>
53
+ ! CHECK: %[[VAL_33:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.heap<i8>>
54
+ ! CHECK: %[[VAL_34:.*]] = fir.convert %[[VAL_33]] : (!fir.heap<i8>) -> !fir.heap<!fir.array<?xi8>>
55
+ ! CHECK: %[[VAL_35:.*]] = fir.shape %[[VAL_8]] : (index) -> !fir.shape<1>
56
+ ! CHECK: %[[VAL_36:.*]] = fir.array_load %[[VAL_34]](%[[VAL_35]]) : (!fir.heap<!fir.array<?xi8>>, !fir.shape<1>) -> !fir.array<?xi8>
57
+ ! CHECK: %[[VAL_37:.*]] = constant 1 : index
58
+ ! CHECK: %[[VAL_38:.*]] = constant 0 : index
59
+ ! CHECK: %[[VAL_39:.*]] = subi %[[VAL_8]], %[[VAL_37]] : index
60
+ ! CHECK: %[[VAL_40:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.heap<i8>>
61
+ ! CHECK: %[[VAL_41:.*]] = fir.convert %[[VAL_40]] : (!fir.heap<i8>) -> !fir.heap<!fir.array<?xi8>>
62
+ ! CHECK: %[[VAL_42:.*]] = fir.convert %[[VAL_41]] : (!fir.heap<!fir.array<?xi8>>) -> i64
63
+ ! CHECK: %[[VAL_43:.*]] = constant 0 : i64
64
+ ! CHECK: %[[VAL_44:.*]] = cmpi eq, %[[VAL_42]], %[[VAL_43]] : i64
65
+ ! CHECK: fir.if %[[VAL_44]] {
66
+ ! CHECK: %[[VAL_45:.*]] = fir.allocmem !fir.array<?xi8>, %[[VAL_8]] {uniq_name = ".lazy.mask"}
67
+ ! CHECK: %[[VAL_46:.*]] = fir.convert %[[VAL_4]] : (!fir.ref<!fir.heap<i8>>) -> !fir.ref<!fir.heap<!fir.array<?xi8>>>
68
+ ! CHECK: fir.store %[[VAL_45]] to %[[VAL_46]] : !fir.ref<!fir.heap<!fir.array<?xi8>>>
69
+ ! CHECK: %[[VAL_47:.*]] = fir.allocmem !fir.array<1xindex> {uniq_name = ".lazy.mask.shape"}
70
+ ! CHECK: %[[VAL_48:.*]] = constant 0 : index
71
+ ! CHECK: %[[VAL_49:.*]] = fir.coordinate_of %[[VAL_47]], %[[VAL_48]] : (!fir.heap<!fir.array<1xindex>>, index) -> !fir.ref<index>
72
+ ! CHECK: fir.store %[[VAL_8]] to %[[VAL_49]] : !fir.ref<index>
73
+ ! CHECK: %[[VAL_50:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<!fir.heap<index>>) -> !fir.ref<!fir.heap<!fir.array<1xindex>>>
74
+ ! CHECK: fir.store %[[VAL_47]] to %[[VAL_50]] : !fir.ref<!fir.heap<!fir.array<1xindex>>>
75
+ ! CHECK: }
76
+ ! CHECK: %[[VAL_51:.*]] = fir.do_loop %[[VAL_52:.*]] = %[[VAL_38]] to %[[VAL_39]] step %[[VAL_37]] unordered iter_args(%[[VAL_53:.*]] = %[[VAL_36]]) -> (!fir.array<?xi8>) {
77
+ ! CHECK: %[[VAL_54:.*]] = fir.array_fetch %[[VAL_32]], %[[VAL_52]] : (!fir.array<3x!fir.logical<4>>, index) -> !fir.logical<4>
78
+ ! CHECK: %[[VAL_55:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.heap<i8>>
79
+ ! CHECK: %[[VAL_56:.*]] = fir.convert %[[VAL_55]] : (!fir.heap<i8>) -> !fir.heap<!fir.array<?xi8>>
80
+ ! CHECK: %[[VAL_57:.*]] = fir.shape %[[VAL_8]] : (index) -> !fir.shape<1>
81
+ ! CHECK: %[[VAL_58:.*]] = constant 1 : index
82
+ ! CHECK: %[[VAL_59:.*]] = addi %[[VAL_52]], %[[VAL_58]] : index
83
+ ! CHECK: %[[VAL_60:.*]] = fir.array_coor %[[VAL_56]](%[[VAL_57]]) %[[VAL_59]] : (!fir.heap<!fir.array<?xi8>>, !fir.shape<1>, index) -> !fir.ref<i8>
84
+ ! CHECK: %[[VAL_61:.*]] = fir.convert %[[VAL_54]] : (!fir.logical<4>) -> i8
85
+ ! CHECK: fir.store %[[VAL_61]] to %[[VAL_60]] : !fir.ref<i8>
86
+ ! CHECK: fir.result %[[VAL_53]] : !fir.array<?xi8>
87
+ ! CHECK: }
88
+ ! CHECK: %[[VAL_62:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.heap<i8>>
89
+ ! CHECK: %[[VAL_63:.*]] = fir.convert %[[VAL_62]] : (!fir.heap<i8>) -> !fir.heap<!fir.array<?xi8>>
90
+ ! CHECK: fir.array_merge_store %[[VAL_36]], %[[VAL_64:.*]] to %[[VAL_63]] : !fir.array<?xi8>, !fir.array<?xi8>, !fir.heap<!fir.array<?xi8>>
91
+ ! CHECK: %[[VAL_65:.*]] = fir.shape %[[VAL_8]] : (index) -> !fir.shape<1>
92
+ ! CHECK: %[[VAL_66:.*]] = fir.shape %[[VAL_10]] : (index) -> !fir.shape<1>
93
+ ! CHECK: %[[VAL_67:.*]] = fir.array_load %[[VAL_9]](%[[VAL_66]]) : (!fir.ref<!fir.array<3x!fir.logical<4>>>, !fir.shape<1>) -> !fir.array<3x!fir.logical<4>>
94
+ ! CHECK: %[[VAL_68:.*]] = fir.load %[[VAL_2]] : !fir.ref<!fir.heap<i8>>
95
+ ! CHECK: %[[VAL_69:.*]] = fir.convert %[[VAL_68]] : (!fir.heap<i8>) -> !fir.heap<!fir.array<?xi8>>
96
+ ! CHECK: %[[VAL_70:.*]] = fir.shape %[[VAL_10]] : (index) -> !fir.shape<1>
97
+ ! CHECK: %[[VAL_71:.*]] = fir.array_load %[[VAL_69]](%[[VAL_70]]) : (!fir.heap<!fir.array<?xi8>>, !fir.shape<1>) -> !fir.array<?xi8>
98
+ ! CHECK: %[[VAL_72:.*]] = constant 1 : index
99
+ ! CHECK: %[[VAL_73:.*]] = constant 0 : index
100
+ ! CHECK: %[[VAL_74:.*]] = subi %[[VAL_10]], %[[VAL_72]] : index
101
+ ! CHECK: %[[VAL_75:.*]] = fir.load %[[VAL_2]] : !fir.ref<!fir.heap<i8>>
102
+ ! CHECK: %[[VAL_76:.*]] = fir.convert %[[VAL_75]] : (!fir.heap<i8>) -> !fir.heap<!fir.array<?xi8>>
103
+ ! CHECK: %[[VAL_77:.*]] = fir.convert %[[VAL_76]] : (!fir.heap<!fir.array<?xi8>>) -> i64
104
+ ! CHECK: %[[VAL_78:.*]] = constant 0 : i64
105
+ ! CHECK: %[[VAL_79:.*]] = cmpi eq, %[[VAL_77]], %[[VAL_78]] : i64
106
+ ! CHECK: fir.if %[[VAL_79]] {
107
+ ! CHECK: %[[VAL_80:.*]] = fir.allocmem !fir.array<?xi8>, %[[VAL_10]] {uniq_name = ".lazy.mask"}
108
+ ! CHECK: %[[VAL_81:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<!fir.heap<i8>>) -> !fir.ref<!fir.heap<!fir.array<?xi8>>>
109
+ ! CHECK: fir.store %[[VAL_80]] to %[[VAL_81]] : !fir.ref<!fir.heap<!fir.array<?xi8>>>
110
+ ! CHECK: %[[VAL_82:.*]] = fir.allocmem !fir.array<1xindex> {uniq_name = ".lazy.mask.shape"}
111
+ ! CHECK: %[[VAL_83:.*]] = constant 0 : index
112
+ ! CHECK: %[[VAL_84:.*]] = fir.coordinate_of %[[VAL_82]], %[[VAL_83]] : (!fir.heap<!fir.array<1xindex>>, index) -> !fir.ref<index>
113
+ ! CHECK: fir.store %[[VAL_10]] to %[[VAL_84]] : !fir.ref<index>
114
+ ! CHECK: %[[VAL_85:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<!fir.heap<index>>) -> !fir.ref<!fir.heap<!fir.array<1xindex>>>
115
+ ! CHECK: fir.store %[[VAL_82]] to %[[VAL_85]] : !fir.ref<!fir.heap<!fir.array<1xindex>>>
116
+ ! CHECK: }
117
+ ! CHECK: %[[VAL_86:.*]] = fir.do_loop %[[VAL_87:.*]] = %[[VAL_73]] to %[[VAL_74]] step %[[VAL_72]] unordered iter_args(%[[VAL_88:.*]] = %[[VAL_71]]) -> (!fir.array<?xi8>) {
118
+ ! CHECK: %[[VAL_89:.*]] = fir.array_fetch %[[VAL_67]], %[[VAL_87]] : (!fir.array<3x!fir.logical<4>>, index) -> !fir.logical<4>
119
+ ! CHECK: %[[VAL_90:.*]] = fir.load %[[VAL_2]] : !fir.ref<!fir.heap<i8>>
120
+ ! CHECK: %[[VAL_91:.*]] = fir.convert %[[VAL_90]] : (!fir.heap<i8>) -> !fir.heap<!fir.array<?xi8>>
121
+ ! CHECK: %[[VAL_92:.*]] = fir.shape %[[VAL_10]] : (index) -> !fir.shape<1>
122
+ ! CHECK: %[[VAL_93:.*]] = constant 1 : index
123
+ ! CHECK: %[[VAL_94:.*]] = addi %[[VAL_87]], %[[VAL_93]] : index
124
+ ! CHECK: %[[VAL_95:.*]] = fir.array_coor %[[VAL_91]](%[[VAL_92]]) %[[VAL_94]] : (!fir.heap<!fir.array<?xi8>>, !fir.shape<1>, index) -> !fir.ref<i8>
125
+ ! CHECK: %[[VAL_96:.*]] = fir.convert %[[VAL_89]] : (!fir.logical<4>) -> i8
126
+ ! CHECK: fir.store %[[VAL_96]] to %[[VAL_95]] : !fir.ref<i8>
127
+ ! CHECK: fir.result %[[VAL_88]] : !fir.array<?xi8>
128
+ ! CHECK: }
129
+ ! CHECK: %[[VAL_97:.*]] = fir.load %[[VAL_2]] : !fir.ref<!fir.heap<i8>>
130
+ ! CHECK: %[[VAL_98:.*]] = fir.convert %[[VAL_97]] : (!fir.heap<i8>) -> !fir.heap<!fir.array<?xi8>>
131
+ ! CHECK: fir.array_merge_store %[[VAL_71]], %[[VAL_99:.*]] to %[[VAL_98]] : !fir.array<?xi8>, !fir.array<?xi8>, !fir.heap<!fir.array<?xi8>>
132
+ ! CHECK: %[[VAL_100:.*]] = fir.shape %[[VAL_10]] : (index) -> !fir.shape<1>
133
+ ! CHECK: %[[VAL_101:.*]] = constant 1 : index
134
+ ! CHECK: %[[VAL_102:.*]] = constant 0 : index
135
+ ! CHECK: %[[VAL_103:.*]] = subi %[[VAL_29]], %[[VAL_101]] : index
136
+ ! CHECK: %[[VAL_104:.*]] = fir.do_loop %[[VAL_105:.*]] = %[[VAL_102]] to %[[VAL_103]] step %[[VAL_101]] unordered iter_args(%[[VAL_106:.*]] = %[[VAL_27]]) -> (!fir.array<3xi32>) {
137
+ ! CHECK: %[[VAL_107:.*]] = constant 1 : index
138
+ ! CHECK: %[[VAL_108:.*]] = addi %[[VAL_105]], %[[VAL_107]] : index
139
+ ! CHECK: %[[VAL_109:.*]] = fir.array_coor %[[VAL_63]](%[[VAL_65]]) %[[VAL_108]] : (!fir.heap<!fir.array<?xi8>>, !fir.shape<1>, index) -> !fir.ref<i8>
140
+ ! CHECK: %[[VAL_110:.*]] = fir.load %[[VAL_109]] : !fir.ref<i8>
141
+ ! CHECK: %[[VAL_111:.*]] = fir.convert %[[VAL_110]] : (i8) -> i1
142
+ ! CHECK: %[[VAL_112:.*]] = fir.if %[[VAL_111]] -> (!fir.array<3xi32>) {
143
+ ! CHECK: %[[VAL_113:.*]] = constant 1 : index
144
+ ! CHECK: %[[VAL_114:.*]] = addi %[[VAL_105]], %[[VAL_113]] : index
145
+ ! CHECK: %[[VAL_115:.*]] = fir.array_coor %[[VAL_98]](%[[VAL_100]]) %[[VAL_114]] : (!fir.heap<!fir.array<?xi8>>, !fir.shape<1>, index) -> !fir.ref<i8>
146
+ ! CHECK: %[[VAL_116:.*]] = fir.load %[[VAL_115]] : !fir.ref<i8>
147
+ ! CHECK: %[[VAL_117:.*]] = fir.convert %[[VAL_116]] : (i8) -> i1
148
+ ! CHECK: %[[VAL_118:.*]] = fir.if %[[VAL_117]] -> (!fir.array<3xi32>) {
149
+ ! CHECK: %[[VAL_119:.*]] = fir.array_update %[[VAL_106]], %[[VAL_30]], %[[VAL_105]] : (!fir.array<3xi32>, i32, index) -> !fir.array<3xi32>
150
+ ! CHECK: fir.result %[[VAL_119]] : !fir.array<3xi32>
151
+ ! CHECK: } else {
152
+ ! CHECK: fir.result %[[VAL_106]] : !fir.array<3xi32>
153
+ ! CHECK: }
154
+ ! CHECK: fir.result %[[VAL_120:.*]] : !fir.array<3xi32>
155
+ ! CHECK: } else {
156
+ ! CHECK: fir.result %[[VAL_106]] : !fir.array<3xi32>
157
+ ! CHECK: }
158
+ ! CHECK: fir.result %[[VAL_121:.*]] : !fir.array<3xi32>
159
+ ! CHECK: }
160
+ ! CHECK: fir.array_merge_store %[[VAL_27]], %[[VAL_122:.*]] to %[[VAL_5]] : !fir.array<3xi32>, !fir.array<3xi32>, !fir.ref<!fir.array<3xi32>>
161
+ ! CHECK: fir.result %[[VAL_24]] : !fir.array<3xi32>
162
+ ! CHECK: }
163
+ ! CHECK: fir.array_merge_store %[[VAL_21]], %[[VAL_123:.*]] to %[[VAL_5]] : !fir.array<3xi32>, !fir.array<3xi32>, !fir.ref<!fir.array<3xi32>>
164
+ ! CHECK: %[[VAL_124:.*]] = fir.load %[[VAL_2]] : !fir.ref<!fir.heap<i8>>
165
+ ! CHECK: %[[VAL_125:.*]] = fir.convert %[[VAL_124]] : (!fir.heap<i8>) -> i64
166
+ ! CHECK: %[[VAL_126:.*]] = constant 0 : i64
167
+ ! CHECK: %[[VAL_127:.*]] = cmpi ne, %[[VAL_125]], %[[VAL_126]] : i64
168
+ ! CHECK: fir.if %[[VAL_127]] {
169
+ ! CHECK: fir.freemem %[[VAL_124]] : !fir.heap<i8>
170
+ ! CHECK: }
171
+ ! CHECK: %[[VAL_128:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.heap<i8>>
172
+ ! CHECK: %[[VAL_129:.*]] = fir.convert %[[VAL_128]] : (!fir.heap<i8>) -> i64
173
+ ! CHECK: %[[VAL_130:.*]] = constant 0 : i64
174
+ ! CHECK: %[[VAL_131:.*]] = cmpi ne, %[[VAL_129]], %[[VAL_130]] : i64
175
+ ! CHECK: fir.if %[[VAL_131]] {
176
+ ! CHECK: fir.freemem %[[VAL_128]] : !fir.heap<i8>
177
+ ! CHECK: }
178
+ ! CHECK: return
179
+ ! CHECK: }
0 commit comments