[flang][openacc][NFC] Check only HLFIR lowering for atomic tests (#72922)
[llvm-project.git] / flang / test / Lower / array-expression-subscript.f90
blob60180b5e305df589288a90dd04e166303421cb15
1 ! RUN: bbc --emit-fir -hlfir=false %s -o - | FileCheck %s
3 ! CHECK-LABEL: func @_QPtest1a(
4 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<10xi32>>{{.*}}, %[[VAL_1:.*]]: !fir.ref<!fir.array<10xi32>>{{.*}}, %[[VAL_2:.*]]: !fir.ref<!fir.array<20xi32>>{{.*}}) {
5 ! CHECK: %[[VAL_3:.*]] = arith.constant 10 : index
6 ! CHECK: %[[VAL_4:.*]] = arith.constant 10 : index
7 ! CHECK: %[[VAL_5:.*]] = arith.constant 20 : index
8 ! CHECK: %[[VAL_6:.*]] = fir.shape %[[VAL_3]] : (index) -> !fir.shape<1>
9 ! CHECK: %[[VAL_7:.*]] = fir.array_load %[[VAL_0]](%[[VAL_6]]) : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.array<10xi32>
10 ! CHECK: %[[VAL_8:.*]] = arith.constant 1 : index
11 ! CHECK: %[[VAL_9:.*]] = arith.constant 1 : i64
12 ! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (i64) -> index
13 ! CHECK: %[[VAL_11:.*]] = arith.constant 2 : i64
14 ! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (i64) -> index
15 ! CHECK: %[[VAL_13:.*]] = arith.constant 20 : i64
16 ! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (i64) -> index
17 ! CHECK: %[[VAL_15:.*]] = arith.constant 0 : index
18 ! CHECK: %[[VAL_16:.*]] = arith.subi %[[VAL_14]], %[[VAL_10]] : index
19 ! CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_16]], %[[VAL_12]] : index
20 ! CHECK: %[[VAL_18:.*]] = arith.divsi %[[VAL_17]], %[[VAL_12]] : index
21 ! CHECK: %[[VAL_19:.*]] = arith.cmpi sgt, %[[VAL_18]], %[[VAL_15]] : index
22 ! CHECK: %[[VAL_20:.*]] = arith.select %[[VAL_19]], %[[VAL_18]], %[[VAL_15]] : index
23 ! CHECK: %[[VAL_21:.*]] = fir.shape %[[VAL_5]] : (index) -> !fir.shape<1>
24 ! CHECK: %[[VAL_22:.*]] = fir.slice %[[VAL_10]], %[[VAL_14]], %[[VAL_12]] : (index, index, index) -> !fir.slice<1>
25 ! CHECK: %[[VAL_23:.*]] = fir.array_load %[[VAL_2]](%[[VAL_21]]) {{\[}}%[[VAL_22]]] : (!fir.ref<!fir.array<20xi32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.array<20xi32>
26 ! CHECK: %[[VAL_24:.*]] = arith.cmpi sgt, %[[VAL_20]], %[[VAL_3]] : index
27 ! CHECK: %[[VAL_25:.*]] = arith.select %[[VAL_24]], %[[VAL_3]], %[[VAL_20]] : index
28 ! CHECK: %[[VAL_32:.*]] = fir.shape %[[VAL_4]] : (index) -> !fir.shape<1>
29 ! CHECK: %[[VAL_34:.*]] = fir.array_load %[[VAL_1]](%[[VAL_32]]) : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.array<10xi32>
30 ! CHECK: %[[VAL_35:.*]] = arith.constant 1 : index
31 ! CHECK: %[[VAL_36:.*]] = arith.constant 0 : index
32 ! CHECK: %[[VAL_37:.*]] = arith.subi %[[VAL_25]], %[[VAL_35]] : index
33 ! CHECK: %[[VAL_38:.*]] = fir.do_loop %[[VAL_39:.*]] = %[[VAL_36]] to %[[VAL_37]] step %[[VAL_35]] unordered iter_args(%[[VAL_40:.*]] = %[[VAL_7]]) -> (!fir.array<10xi32>) {
34 ! CHECK: %[[VAL_41:.*]] = fir.array_fetch %[[VAL_23]], %[[VAL_39]] : (!fir.array<20xi32>, index) -> i32
35 ! CHECK: %[[VAL_42:.*]] = fir.convert %[[VAL_41]] : (i32) -> index
36 ! CHECK: %[[VAL_43:.*]] = arith.subi %[[VAL_42]], %[[VAL_8]] : index
37 ! CHECK: %[[VAL_44:.*]] = fir.array_fetch %[[VAL_34]], %[[VAL_43]] : (!fir.array<10xi32>, index) -> i32
38 ! CHECK: %[[VAL_45:.*]] = fir.array_update %[[VAL_40]], %[[VAL_44]], %[[VAL_39]] : (!fir.array<10xi32>, i32, index) -> !fir.array<10xi32>
39 ! CHECK: fir.result %[[VAL_45]] : !fir.array<10xi32>
40 ! CHECK: }
41 ! CHECK: fir.array_merge_store %[[VAL_7]], %[[VAL_46:.*]] to %[[VAL_0]] : !fir.array<10xi32>, !fir.array<10xi32>, !fir.ref<!fir.array<10xi32>>
42 ! CHECK: return
43 ! CHECK: }
45 subroutine test1a(a,b,c)
46 integer :: a(10), b(10), c(20)
48 a = b(c(1:20:2))
49 end subroutine test1a
51 ! CHECK-LABEL: func @_QPtest1b(
52 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<10xi32>>{{.*}}, %[[VAL_1:.*]]: !fir.ref<!fir.array<10xi32>>{{.*}}, %[[VAL_2:.*]]: !fir.ref<!fir.array<20xi32>>{{.*}}) {
53 ! CHECK: %[[VAL_3:.*]] = arith.constant 10 : index
54 ! CHECK: %[[VAL_4:.*]] = arith.constant 10 : index
55 ! CHECK: %[[VAL_5:.*]] = arith.constant 20 : index
56 ! CHECK: %[[VAL_6:.*]] = arith.constant 1 : index
57 ! CHECK: %[[VAL_7:.*]] = arith.constant 1 : i64
58 ! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i64) -> index
59 ! CHECK: %[[VAL_9:.*]] = arith.constant 2 : i64
60 ! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (i64) -> index
61 ! CHECK: %[[VAL_11:.*]] = arith.constant 20 : i64
62 ! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (i64) -> index
63 ! CHECK: %[[VAL_13:.*]] = arith.constant 0 : index
64 ! CHECK: %[[VAL_14:.*]] = arith.subi %[[VAL_12]], %[[VAL_8]] : index
65 ! CHECK: %[[VAL_15:.*]] = arith.addi %[[VAL_14]], %[[VAL_10]] : index
66 ! CHECK: %[[VAL_16:.*]] = arith.divsi %[[VAL_15]], %[[VAL_10]] : index
67 ! CHECK: %[[VAL_17:.*]] = arith.cmpi sgt, %[[VAL_16]], %[[VAL_13]] : index
68 ! CHECK: %[[VAL_18:.*]] = arith.select %[[VAL_17]], %[[VAL_16]], %[[VAL_13]] : index
69 ! CHECK: %[[VAL_19:.*]] = fir.shape %[[VAL_5]] : (index) -> !fir.shape<1>
70 ! CHECK: %[[VAL_20:.*]] = fir.slice %[[VAL_8]], %[[VAL_12]], %[[VAL_10]] : (index, index, index) -> !fir.slice<1>
71 ! CHECK: %[[VAL_21:.*]] = fir.array_load %[[VAL_2]](%[[VAL_19]]) {{\[}}%[[VAL_20]]] : (!fir.ref<!fir.array<20xi32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.array<20xi32>
72 ! CHECK: %[[VAL_22:.*]] = arith.cmpi sgt, %[[VAL_18]], %[[VAL_4]] : index
73 ! CHECK: %[[VAL_23:.*]] = arith.select %[[VAL_22]], %[[VAL_4]], %[[VAL_18]] : index
74 ! CHECK: %[[VAL_30:.*]] = fir.shape %[[VAL_4]] : (index) -> !fir.shape<1>
75 ! CHECK: %[[VAL_32:.*]] = fir.array_load %[[VAL_1]](%[[VAL_30]]) : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.array<10xi32>
76 ! CHECK: %[[VAL_33:.*]] = fir.shape %[[VAL_3]] : (index) -> !fir.shape<1>
77 ! CHECK: %[[VAL_34:.*]] = fir.array_load %[[VAL_0]](%[[VAL_33]]) : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.array<10xi32>
78 ! CHECK: %[[VAL_35:.*]] = arith.constant 1 : index
79 ! CHECK: %[[VAL_36:.*]] = arith.constant 0 : index
80 ! CHECK: %[[VAL_37:.*]] = arith.subi %[[VAL_23]], %[[VAL_35]] : index
81 ! CHECK: %[[VAL_38:.*]] = fir.do_loop %[[VAL_39:.*]] = %[[VAL_36]] to %[[VAL_37]] step %[[VAL_35]] unordered iter_args(%[[VAL_40:.*]] = %[[VAL_32]]) -> (!fir.array<10xi32>) {
82 ! CHECK: %[[VAL_41:.*]] = fir.array_fetch %[[VAL_34]], %[[VAL_39]] : (!fir.array<10xi32>, index) -> i32
83 ! CHECK: %[[VAL_42:.*]] = fir.array_fetch %[[VAL_21]], %[[VAL_39]] : (!fir.array<20xi32>, index) -> i32
84 ! CHECK: %[[VAL_43:.*]] = fir.convert %[[VAL_42]] : (i32) -> index
85 ! CHECK: %[[VAL_44:.*]] = arith.subi %[[VAL_43]], %[[VAL_6]] : index
86 ! CHECK: %[[VAL_45:.*]] = fir.array_update %[[VAL_40]], %[[VAL_41]], %[[VAL_44]] : (!fir.array<10xi32>, i32, index) -> !fir.array<10xi32>
87 ! CHECK: fir.result %[[VAL_45]] : !fir.array<10xi32>
88 ! CHECK: }
89 ! CHECK: fir.array_merge_store %[[VAL_32]], %[[VAL_46:.*]] to %[[VAL_1]] : !fir.array<10xi32>, !fir.array<10xi32>, !fir.ref<!fir.array<10xi32>>
90 ! CHECK: return
91 ! CHECK: }
93 subroutine test1b(a,b,c)
94 integer :: a(10), b(10), c(20)
96 b(c(1:20:2)) = a
97 end subroutine test1b
99 ! CHECK-LABEL: func @_QPtest2a(
100 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<10xi32>>{{.*}}, %[[VAL_1:.*]]: !fir.ref<!fir.array<10xi32>>{{.*}}, %[[VAL_2:.*]]: !fir.ref<!fir.array<10xi32>>{{.*}}, %[[VAL_3:.*]]: !fir.ref<!fir.array<10xi32>>{{.*}}) {
101 ! CHECK: %[[VAL_4:.*]] = arith.constant 10 : index
102 ! CHECK: %[[VAL_5:.*]] = arith.constant 10 : index
103 ! CHECK: %[[VAL_6:.*]] = arith.constant 10 : index
104 ! CHECK: %[[VAL_7:.*]] = arith.constant 10 : index
105 ! CHECK: %[[VAL_8:.*]] = fir.shape %[[VAL_4]] : (index) -> !fir.shape<1>
106 ! CHECK: %[[VAL_9:.*]] = fir.array_load %[[VAL_0]](%[[VAL_8]]) : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.array<10xi32>
107 ! CHECK: %[[VAL_10:.*]] = arith.constant 1 : index
108 ! CHECK: %[[VAL_11:.*]] = arith.constant 1 : index
109 ! CHECK: %[[VAL_12:.*]] = fir.shape %[[VAL_7]] : (index) -> !fir.shape<1>
110 ! CHECK: %[[VAL_13:.*]] = fir.array_load %[[VAL_3]](%[[VAL_12]]) : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.array<10xi32>
111 ! CHECK: %[[VAL_14:.*]] = arith.cmpi sgt, %[[VAL_7]], %[[VAL_6]] : index
112 ! CHECK: %[[VAL_15:.*]] = arith.select %[[VAL_14]], %[[VAL_6]], %[[VAL_7]] : index
113 ! CHECK: %[[VAL_16:.*]] = fir.shape %[[VAL_6]] : (index) -> !fir.shape<1>
114 ! CHECK: %[[VAL_18:.*]] = fir.array_load %[[VAL_2]](%[[VAL_16]]) : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.array<10xi32>
115 ! CHECK: %[[VAL_19:.*]] = arith.cmpi sgt, %[[VAL_15]], %[[VAL_4]] : index
116 ! CHECK: %[[VAL_20:.*]] = arith.select %[[VAL_19]], %[[VAL_4]], %[[VAL_15]] : index
117 ! CHECK: %[[VAL_27:.*]] = fir.shape %[[VAL_5]] : (index) -> !fir.shape<1>
118 ! CHECK: %[[VAL_29:.*]] = fir.array_load %[[VAL_1]](%[[VAL_27]]) : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.array<10xi32>
119 ! CHECK: %[[VAL_30:.*]] = arith.constant 1 : index
120 ! CHECK: %[[VAL_31:.*]] = arith.constant 0 : index
121 ! CHECK: %[[VAL_32:.*]] = arith.subi %[[VAL_20]], %[[VAL_30]] : index
122 ! CHECK: %[[VAL_33:.*]] = fir.do_loop %[[VAL_34:.*]] = %[[VAL_31]] to %[[VAL_32]] step %[[VAL_30]] unordered iter_args(%[[VAL_35:.*]] = %[[VAL_9]]) -> (!fir.array<10xi32>) {
123 ! CHECK: %[[VAL_36:.*]] = fir.array_fetch %[[VAL_13]], %[[VAL_34]] : (!fir.array<10xi32>, index) -> i32
124 ! CHECK: %[[VAL_37:.*]] = fir.convert %[[VAL_36]] : (i32) -> index
125 ! CHECK: %[[VAL_38:.*]] = arith.subi %[[VAL_37]], %[[VAL_11]] : index
126 ! CHECK: %[[VAL_39:.*]] = fir.array_fetch %[[VAL_18]], %[[VAL_38]] : (!fir.array<10xi32>, index) -> i32
127 ! CHECK: %[[VAL_40:.*]] = fir.convert %[[VAL_39]] : (i32) -> index
128 ! CHECK: %[[VAL_41:.*]] = arith.subi %[[VAL_40]], %[[VAL_10]] : index
129 ! CHECK: %[[VAL_42:.*]] = fir.array_fetch %[[VAL_29]], %[[VAL_41]] : (!fir.array<10xi32>, index) -> i32
130 ! CHECK: %[[VAL_43:.*]] = fir.array_update %[[VAL_35]], %[[VAL_42]], %[[VAL_34]] : (!fir.array<10xi32>, i32, index) -> !fir.array<10xi32>
131 ! CHECK: fir.result %[[VAL_43]] : !fir.array<10xi32>
132 ! CHECK: }
133 ! CHECK: fir.array_merge_store %[[VAL_9]], %[[VAL_44:.*]] to %[[VAL_0]] : !fir.array<10xi32>, !fir.array<10xi32>, !fir.ref<!fir.array<10xi32>>
134 ! CHECK: return
135 ! CHECK: }
137 subroutine test2a(a,b,c,d)
138 integer :: a(10), b(10), c(10), d(10)
140 a = b(c(d))
141 end subroutine test2a
143 ! CHECK-LABEL: func @_QPtest2b(
144 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<10xi32>>{{.*}}, %[[VAL_1:.*]]: !fir.ref<!fir.array<10xi32>>{{.*}}, %[[VAL_2:.*]]: !fir.ref<!fir.array<10xi32>>{{.*}}, %[[VAL_3:.*]]: !fir.ref<!fir.array<10xi32>>{{.*}}) {
145 ! CHECK: %[[VAL_4:.*]] = arith.constant 10 : index
146 ! CHECK: %[[VAL_5:.*]] = arith.constant 10 : index
147 ! CHECK: %[[VAL_6:.*]] = arith.constant 10 : index
148 ! CHECK: %[[VAL_7:.*]] = arith.constant 10 : index
149 ! CHECK: %[[VAL_8:.*]] = arith.constant 1 : index
150 ! CHECK: %[[VAL_9:.*]] = arith.constant 1 : index
151 ! CHECK: %[[VAL_10:.*]] = fir.shape %[[VAL_7]] : (index) -> !fir.shape<1>
152 ! CHECK: %[[VAL_11:.*]] = fir.array_load %[[VAL_3]](%[[VAL_10]]) : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.array<10xi32>
153 ! CHECK: %[[VAL_12:.*]] = arith.cmpi sgt, %[[VAL_7]], %[[VAL_6]] : index
154 ! CHECK: %[[VAL_13:.*]] = arith.select %[[VAL_12]], %[[VAL_6]], %[[VAL_7]] : index
155 ! CHECK: %[[VAL_14:.*]] = fir.shape %[[VAL_6]] : (index) -> !fir.shape<1>
156 ! CHECK: %[[VAL_16:.*]] = fir.array_load %[[VAL_2]](%[[VAL_14]]) : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.array<10xi32>
157 ! CHECK: %[[VAL_17:.*]] = arith.cmpi sgt, %[[VAL_13]], %[[VAL_5]] : index
158 ! CHECK: %[[VAL_18:.*]] = arith.select %[[VAL_17]], %[[VAL_5]], %[[VAL_13]] : index
159 ! CHECK: %[[VAL_25:.*]] = fir.shape %[[VAL_5]] : (index) -> !fir.shape<1>
160 ! CHECK: %[[VAL_27:.*]] = fir.array_load %[[VAL_1]](%[[VAL_25]]) : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.array<10xi32>
161 ! CHECK: %[[VAL_28:.*]] = fir.shape %[[VAL_4]] : (index) -> !fir.shape<1>
162 ! CHECK: %[[VAL_29:.*]] = fir.array_load %[[VAL_0]](%[[VAL_28]]) : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.array<10xi32>
163 ! CHECK: %[[VAL_30:.*]] = arith.constant 1 : index
164 ! CHECK: %[[VAL_31:.*]] = arith.constant 0 : index
165 ! CHECK: %[[VAL_32:.*]] = arith.subi %[[VAL_18]], %[[VAL_30]] : index
166 ! CHECK: %[[VAL_33:.*]] = fir.do_loop %[[VAL_34:.*]] = %[[VAL_31]] to %[[VAL_32]] step %[[VAL_30]] unordered iter_args(%[[VAL_35:.*]] = %[[VAL_27]]) -> (!fir.array<10xi32>) {
167 ! CHECK: %[[VAL_36:.*]] = fir.array_fetch %[[VAL_29]], %[[VAL_34]] : (!fir.array<10xi32>, index) -> i32
168 ! CHECK: %[[VAL_37:.*]] = fir.array_fetch %[[VAL_11]], %[[VAL_34]] : (!fir.array<10xi32>, index) -> i32
169 ! CHECK: %[[VAL_38:.*]] = fir.convert %[[VAL_37]] : (i32) -> index
170 ! CHECK: %[[VAL_39:.*]] = arith.subi %[[VAL_38]], %[[VAL_9]] : index
171 ! CHECK: %[[VAL_40:.*]] = fir.array_fetch %[[VAL_16]], %[[VAL_39]] : (!fir.array<10xi32>, index) -> i32
172 ! CHECK: %[[VAL_41:.*]] = fir.convert %[[VAL_40]] : (i32) -> index
173 ! CHECK: %[[VAL_42:.*]] = arith.subi %[[VAL_41]], %[[VAL_8]] : index
174 ! CHECK: %[[VAL_43:.*]] = fir.array_update %[[VAL_35]], %[[VAL_36]], %[[VAL_42]] : (!fir.array<10xi32>, i32, index) -> !fir.array<10xi32>
175 ! CHECK: fir.result %[[VAL_43]] : !fir.array<10xi32>
176 ! CHECK: }
177 ! CHECK: fir.array_merge_store %[[VAL_27]], %[[VAL_44:.*]] to %[[VAL_1]] : !fir.array<10xi32>, !fir.array<10xi32>, !fir.ref<!fir.array<10xi32>>
178 ! CHECK: return
179 ! CHECK: }
181 subroutine test2b(a,b,c,d)
182 integer :: a(10), b(10), c(10), d(10)
184 b(c(d)) = a
185 end subroutine test2b
187 ! CHECK-LABEL: func @_QPtest1c(
188 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<10xi32>>{{.*}}, %[[VAL_1:.*]]: !fir.ref<!fir.array<10xi32>>{{.*}}, %[[VAL_2:.*]]: !fir.ref<!fir.array<20xi32>>{{.*}}, %[[VAL_3:.*]]: !fir.ref<!fir.array<10xi32>>{{.*}}) {
189 ! CHECK: return
190 ! CHECK: }
191 subroutine test1c(a,b,c,d)
192 integer :: a(10), b(10), d(10), c(20)
194 ! flang: parser FAIL (final position)
195 !a = b(d(c(1:20:2))
196 end subroutine test1c