1 ! RUN: bbc %s -o "-" -emit-fir | FileCheck %s
8 ! CHECK-LABEL: func @_QPsub1(
9 ! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<i32>
10 ! CHECK: %[[C1:.*]] = arith.constant 1 : i32
11 ! CHECK: fir.store %[[C1]] to %[[ARG0]] : !fir.ref<i32>
19 ! CHECK-LABEL: func @_QPsub2(
20 ! CHECK: %[[A:.*]]: !fir.ref<i32> {fir.bindc_name = "a"}
21 ! CHECK: %[[B:.*]]: !fir.ref<i64> {fir.bindc_name = "b"}
22 ! CHECK: %[[B_VAL:.*]] = fir.load %arg1 : !fir.ref<i64>
23 ! CHECK: %[[B_CONV:.*]] = fir.convert %[[B_VAL]] : (i64) -> i32
24 ! CHECK: fir.store %[[B_CONV]] to %[[A]] : !fir.ref<i32>
26 integer function negi(a
)
31 ! CHECK-LABEL: func @_QPnegi(
32 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i32> {fir.bindc_name = "a"}) -> i32 {
33 ! CHECK: %[[FCTRES:.*]] = fir.alloca i32 {bindc_name = "negi", uniq_name = "_QFnegiEnegi"}
34 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
35 ! CHECK: %[[C0:.*]] = arith.constant 0 : i32
36 ! CHECK: %[[NEG:.*]] = arith.subi %[[C0]], %[[A_VAL]] : i32
37 ! CHECK: fir.store %[[NEG]] to %[[FCTRES]] : !fir.ref<i32>
38 ! CHECK: %[[RET:.*]] = fir.load %[[FCTRES]] : !fir.ref<i32>
39 ! CHECK: return %[[RET]] : i32
46 ! CHECK-LABEL: func @_QPnegr(
47 ! CHECK-SAME: %[[A:.*]]: !fir.ref<f32> {fir.bindc_name = "a"}) -> f32 {
48 ! CHECK: %[[FCTRES:.*]] = fir.alloca f32 {bindc_name = "negr", uniq_name = "_QFnegrEnegr"}
49 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<f32>
50 ! CHECK: %[[NEG:.*]] = arith.negf %[[A_VAL]] {{.*}}: f32
51 ! CHECK: fir.store %[[NEG]] to %[[FCTRES]] : !fir.ref<f32>
52 ! CHECK: %[[RET:.*]] = fir.load %[[FCTRES]] : !fir.ref<f32>
53 ! CHECK: return %[[RET]] : f32
55 complex function negc(a
)
60 ! CHECK-LABEL: func @_QPnegc(
61 ! CHECK-SAME: %[[A:.*]]: !fir.ref<!fir.complex<4>> {fir.bindc_name = "a"}) -> !fir.complex<4> {
62 ! CHECK: %[[FCTRES:.*]] = fir.alloca !fir.complex<4> {bindc_name = "negc", uniq_name = "_QFnegcEnegc"}
63 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<!fir.complex<4>>
64 ! CHECK: %[[NEG:.*]] = fir.negc %[[A_VAL]] : !fir.complex<4>
65 ! CHECK: fir.store %[[NEG]] to %[[FCTRES]] : !fir.ref<!fir.complex<4>>
67 integer function addi(a
, b
)
72 ! CHECK-LABEL: func @_QPaddi(
73 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i32> {fir.bindc_name = "a"},
74 ! CHECK-SAME: %[[B:.*]]: !fir.ref<i32> {fir.bindc_name = "b"}
75 ! CHECK: %[[FCTRES:.*]] = fir.alloca i32
76 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
77 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32>
78 ! CHECK: %[[ADD:.*]] = arith.addi %[[A_VAL]], %[[B_VAL]] : i32
79 ! CHECK: fir.store %[[ADD]] to %[[FCTRES]] : !fir.ref<i32>
80 ! CHECK: %[[RET:.*]] = fir.load %[[FCTRES]] : !fir.ref<i32>
81 ! CHECK: return %[[RET]] : i32
83 integer function subi(a
, b
)
88 ! CHECK-LABEL: func @_QPsubi(
89 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i32> {fir.bindc_name = "a"},
90 ! CHECK-SAME: %[[B:.*]]: !fir.ref<i32> {fir.bindc_name = "b"}
91 ! CHECK: %[[FCTRES:.*]] = fir.alloca i32
92 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
93 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32>
94 ! CHECK: %[[SUB:.*]] = arith.subi %[[A_VAL]], %[[B_VAL]] : i32
95 ! CHECK: fir.store %[[SUB]] to %[[FCTRES]] : !fir.ref<i32>
96 ! CHECK: %[[RET:.*]] = fir.load %[[FCTRES]] : !fir.ref<i32>
97 ! CHECK: return %[[RET]] : i32
99 integer function muli(a
, b
)
104 ! CHECK-LABEL: func @_QPmuli(
105 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i32> {fir.bindc_name = "a"},
106 ! CHECK-SAME: %[[B:.*]]: !fir.ref<i32> {fir.bindc_name = "b"}
107 ! CHECK: %[[FCTRES:.*]] = fir.alloca i32
108 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
109 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32>
110 ! CHECK: %[[MUL:.*]] = arith.muli %[[A_VAL]], %[[B_VAL]] : i32
111 ! CHECK: fir.store %[[MUL]] to %[[FCTRES]] : !fir.ref<i32>
112 ! CHECK: %[[RET:.*]] = fir.load %[[FCTRES]] : !fir.ref<i32>
113 ! CHECK: return %[[RET]] : i32
115 integer function divi(a
, b
)
120 ! CHECK-LABEL: func @_QPdivi(
121 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i32> {fir.bindc_name = "a"},
122 ! CHECK-SAME: %[[B:.*]]: !fir.ref<i32> {fir.bindc_name = "b"}
123 ! CHECK: %[[FCTRES:.*]] = fir.alloca i32
124 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
125 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32>
126 ! CHECK: %[[DIV:.*]] = arith.divsi %[[A_VAL]], %[[B_VAL]] : i32
127 ! CHECK: fir.store %[[DIV]] to %[[FCTRES]] : !fir.ref<i32>
128 ! CHECK: %[[RET:.*]] = fir.load %[[FCTRES]] : !fir.ref<i32>
129 ! CHECK: return %[[RET]] : i32
131 real function addf(a
, b
)
136 ! CHECK-LABEL: func @_QPaddf(
137 ! CHECK-SAME: %[[A:.*]]: !fir.ref<f32> {fir.bindc_name = "a"},
138 ! CHECK-SAME: %[[B:.*]]: !fir.ref<f32> {fir.bindc_name = "b"}
139 ! CHECK: %[[FCTRES:.*]] = fir.alloca f32
140 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<f32>
141 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<f32>
142 ! CHECK: %[[ADD:.*]] = arith.addf %[[A_VAL]], %[[B_VAL]] {{.*}}: f32
143 ! CHECK: fir.store %[[ADD]] to %[[FCTRES]] : !fir.ref<f32>
144 ! CHECK: %[[RET:.*]] = fir.load %[[FCTRES]] : !fir.ref<f32>
145 ! CHECK: return %[[RET]] : f32
147 real function subf(a
, b
)
152 ! CHECK-LABEL: func @_QPsubf(
153 ! CHECK-SAME: %[[A:.*]]: !fir.ref<f32> {fir.bindc_name = "a"},
154 ! CHECK-SAME: %[[B:.*]]: !fir.ref<f32> {fir.bindc_name = "b"}
155 ! CHECK: %[[FCTRES:.*]] = fir.alloca f32
156 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<f32>
157 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<f32>
158 ! CHECK: %[[SUB:.*]] = arith.subf %[[A_VAL]], %[[B_VAL]] {{.*}}: f32
159 ! CHECK: fir.store %[[SUB]] to %[[FCTRES]] : !fir.ref<f32>
160 ! CHECK: %[[RET:.*]] = fir.load %[[FCTRES]] : !fir.ref<f32>
161 ! CHECK: return %[[RET]] : f32
163 real function mulf(a
, b
)
168 ! CHECK-LABEL: func @_QPmulf(
169 ! CHECK-SAME: %[[A:.*]]: !fir.ref<f32> {fir.bindc_name = "a"},
170 ! CHECK-SAME: %[[B:.*]]: !fir.ref<f32> {fir.bindc_name = "b"}
171 ! CHECK: %[[FCTRES:.*]] = fir.alloca f32
172 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<f32>
173 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<f32>
174 ! CHECK: %[[MUL:.*]] = arith.mulf %[[A_VAL]], %[[B_VAL]] {{.*}}: f32
175 ! CHECK: fir.store %[[MUL]] to %[[FCTRES]] : !fir.ref<f32>
176 ! CHECK: %[[RET:.*]] = fir.load %[[FCTRES]] : !fir.ref<f32>
177 ! CHECK: return %[[RET]] : f32
179 real function divf(a
, b
)
184 ! CHECK-LABEL: func @_QPdivf(
185 ! CHECK-SAME: %[[A:.*]]: !fir.ref<f32> {fir.bindc_name = "a"},
186 ! CHECK-SAME: %[[B:.*]]: !fir.ref<f32> {fir.bindc_name = "b"}
187 ! CHECK: %[[FCTRES:.*]] = fir.alloca f32
188 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<f32>
189 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<f32>
190 ! CHECK: %[[DIV:.*]] = arith.divf %[[A_VAL]], %[[B_VAL]] {{.*}}: f32
191 ! CHECK: fir.store %[[DIV]] to %[[FCTRES]] : !fir.ref<f32>
192 ! CHECK: %[[RET:.*]] = fir.load %[[FCTRES]] : !fir.ref<f32>
193 ! CHECK: return %[[RET]] : f32
195 complex function addc(a
, b
)
200 ! CHECK-LABEL: func @_QPaddc(
201 ! CHECK-SAME: %[[A:.*]]: !fir.ref<!fir.complex<4>> {fir.bindc_name = "a"},
202 ! CHECK-SAME: %[[B:.*]]: !fir.ref<!fir.complex<4>> {fir.bindc_name = "b"}
203 ! CHECK: %[[FCTRES:.*]] = fir.alloca !fir.complex<4>
204 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<!fir.complex<4>>
205 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<!fir.complex<4>>
206 ! CHECK: %[[ADD:.*]] = fir.addc %[[A_VAL]], %[[B_VAL]] : !fir.complex<4>
207 ! CHECK: fir.store %[[ADD]] to %[[FCTRES]] : !fir.ref<!fir.complex<4>>
208 ! CHECK: %[[RET:.*]] = fir.load %[[FCTRES]] : !fir.ref<!fir.complex<4>>
209 ! CHECK: return %[[RET]] : !fir.complex<4>
211 complex function subc(a
, b
)
216 ! CHECK-LABEL: func @_QPsubc(
217 ! CHECK-SAME: %[[A:.*]]: !fir.ref<!fir.complex<4>> {fir.bindc_name = "a"},
218 ! CHECK-SAME: %[[B:.*]]: !fir.ref<!fir.complex<4>> {fir.bindc_name = "b"}
219 ! CHECK: %[[FCTRES:.*]] = fir.alloca !fir.complex<4>
220 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<!fir.complex<4>>
221 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<!fir.complex<4>>
222 ! CHECK: %[[SUB:.*]] = fir.subc %[[A_VAL]], %[[B_VAL]] : !fir.complex<4>
223 ! CHECK: fir.store %[[SUB]] to %[[FCTRES]] : !fir.ref<!fir.complex<4>>
224 ! CHECK: %[[RET:.*]] = fir.load %[[FCTRES]] : !fir.ref<!fir.complex<4>>
225 ! CHECK: return %[[RET]] : !fir.complex<4>
227 complex function mulc(a
, b
)
232 ! CHECK-LABEL: func @_QPmulc(
233 ! CHECK-SAME: %[[A:.*]]: !fir.ref<!fir.complex<4>> {fir.bindc_name = "a"},
234 ! CHECK-SAME: %[[B:.*]]: !fir.ref<!fir.complex<4>> {fir.bindc_name = "b"}
235 ! CHECK: %[[FCTRES:.*]] = fir.alloca !fir.complex<4>
236 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<!fir.complex<4>>
237 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<!fir.complex<4>>
238 ! CHECK: %[[MUL:.*]] = fir.mulc %[[A_VAL]], %[[B_VAL]] : !fir.complex<4>
239 ! CHECK: fir.store %[[MUL]] to %[[FCTRES]] : !fir.ref<!fir.complex<4>>
240 ! CHECK: %[[RET:.*]] = fir.load %[[FCTRES]] : !fir.ref<!fir.complex<4>>
241 ! CHECK: return %[[RET]] : !fir.complex<4>
243 complex function divc(a
, b
)
248 ! CHECK-LABEL: func @_QPdivc(
249 ! CHECK-SAME: %[[A:.*]]: !fir.ref<!fir.complex<4>> {fir.bindc_name = "a"},
250 ! CHECK-SAME: %[[B:.*]]: !fir.ref<!fir.complex<4>> {fir.bindc_name = "b"}
251 ! CHECK: %[[FCTRES:.*]] = fir.alloca !fir.complex<4>
252 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<!fir.complex<4>>
253 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<!fir.complex<4>>
254 ! CHECK: %[[A_REAL:.*]] = fir.extract_value %[[A_VAL]], [0 : index] : (!fir.complex<4>) -> f32
255 ! CHECK: %[[A_IMAG:.*]] = fir.extract_value %[[A_VAL]], [1 : index] : (!fir.complex<4>) -> f32
256 ! CHECK: %[[B_REAL:.*]] = fir.extract_value %[[B_VAL]], [0 : index] : (!fir.complex<4>) -> f32
257 ! CHECK: %[[B_IMAG:.*]] = fir.extract_value %[[B_VAL]], [1 : index] : (!fir.complex<4>) -> f32
258 ! CHECK: %[[DIV:.*]] = fir.call @__divsc3(%[[A_REAL]], %[[A_IMAG]], %[[B_REAL]], %[[B_IMAG]]) fastmath<contract> : (f32, f32, f32, f32) -> !fir.complex<4>
259 ! CHECK: fir.store %[[DIV]] to %[[FCTRES]] : !fir.ref<!fir.complex<4>>
260 ! CHECK: %[[RET:.*]] = fir.load %[[FCTRES]] : !fir.ref<!fir.complex<4>>
261 ! CHECK: return %[[RET]] : !fir.complex<4>
263 subroutine real_constant()
276 ! CHECK: %[[A:.*]] = fir.alloca f16
277 ! CHECK: %[[B:.*]] = fir.alloca f32
278 ! CHECK: %[[C:.*]] = fir.alloca f64
279 ! CHECK: %[[D:.*]] = fir.alloca f80
280 ! CHECK: %[[E:.*]] = fir.alloca f128
281 ! CHECK: %[[C2:.*]] = arith.constant 2.000000e+00 : f16
282 ! CHECK: fir.store %[[C2]] to %[[A]] : !fir.ref<f16>
283 ! CHECK: %[[C4:.*]] = arith.constant 4.000000e+00 : f32
284 ! CHECK: fir.store %[[C4]] to %[[B]] : !fir.ref<f32>
285 ! CHECK: %[[C8:.*]] = arith.constant 8.000000e+00 : f64
286 ! CHECK: fir.store %[[C8]] to %[[C]] : !fir.ref<f64>
287 ! CHECK: %[[C10:.*]] = arith.constant 1.000000e+01 : f80
288 ! CHECK: fir.store %[[C10]] to %[[D]] : !fir.ref<f80>
289 ! CHECK: %[[C16:.*]] = arith.constant 1.600000e+01 : f128
290 ! CHECK: fir.store %[[C16]] to %[[E]] : !fir.ref<f128>
292 subroutine complex_constant()
297 ! CHECK-LABEL: func @_QPcomplex_constant()
298 ! CHECK: %[[A:.*]] = fir.alloca !fir.complex<4> {bindc_name = "a", uniq_name = "_QFcomplex_constantEa"}
299 ! CHECK: %[[C0:.*]] = arith.constant 0.000000e+00 : f32
300 ! CHECK: %[[C1:.*]] = arith.constant 1.000000e+00 : f32
301 ! CHECK: %[[UNDEF:.*]] = fir.undefined !fir.complex<4>
302 ! CHECK: %[[INS0:.*]] = fir.insert_value %[[UNDEF]], %[[C0]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
303 ! CHECK: %[[INS1:.*]] = fir.insert_value %[[INS0]], %[[C1]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
304 ! CHECK: fir.store %[[INS1]] to %[[A]] : !fir.ref<!fir.complex<4>>
306 subroutine sub1_arr(a
)
311 ! CHECK-LABEL: func @_QPsub1_arr(
312 ! CHECK-SAME: %[[A:.*]]: !fir.ref<!fir.array<10xi32>> {fir.bindc_name = "a"})
313 ! CHECK-DAG: %[[C10:.*]] = arith.constant 10 : i32
314 ! CHECK-DAG: %[[C2:.*]] = arith.constant 2 : i64
315 ! CHECK-DAG: %[[C1:.*]] = arith.constant 1 : i64
316 ! CHECK: %[[ZERO_BASED_INDEX:.*]] = arith.subi %[[C2]], %[[C1]] : i64
317 ! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[A]], %[[ZERO_BASED_INDEX]] : (!fir.ref<!fir.array<10xi32>>, i64) -> !fir.ref<i32>
318 ! CHECK: fir.store %[[C10]] to %[[COORD]] : !fir.ref<i32>
321 subroutine sub2_arr(a
)
326 ! CHECK-LABEL: func @_QPsub2_arr(
327 ! CHECK-SAME: %[[A:.*]]: !fir.ref<!fir.array<10xi32>> {fir.bindc_name = "a"})
328 ! CHECK-DAG: %[[C10_0:.*]] = arith.constant 10 : index
329 ! CHECK: %[[SHAPE:.*]] = fir.shape %[[C10_0]] : (index) -> !fir.shape<1>
330 ! CHECK: %[[LOAD:.*]] = fir.array_load %[[A]](%[[SHAPE]]) : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.array<10xi32>
331 ! CHECK-DAG: %[[C10_1:.*]] = arith.constant 10 : i32
332 ! CHECK-DAG: %[[C1:.*]] = arith.constant 1 : index
333 ! CHECK-DAG: %[[C0:.*]] = arith.constant 0 : index
334 ! CHECK-DAG: %[[UB:.*]] = arith.subi %[[C10_0]], %c1 : index
335 ! CHECK: %[[DO_RES:.*]] = fir.do_loop %[[ARG1:.*]] = %[[C0]] to %[[UB]] step %[[C1]] unordered iter_args(%[[ARG2:.*]] = %[[LOAD]]) -> (!fir.array<10xi32>) {
336 ! CHECK: %[[RES:.*]] = fir.array_update %[[ARG2]], %[[C10_1]], %[[ARG1]] : (!fir.array<10xi32>, i32, index) -> !fir.array<10xi32>
337 ! CHECK: fir.result %[[RES]] : !fir.array<10xi32>
339 ! CHECK: fir.array_merge_store %[[LOAD]], %[[DO_RES]] to %[[A]] : !fir.array<10xi32>, !fir.array<10xi32>, !fir.ref<!fir.array<10xi32>>