1 // Test the FIR operations
3 // RUN: fir-opt %s | fir-opt | FileCheck %s
5 // CHECK-LABEL: func private @it1() -> !fir.int<4>
6 // CHECK: func private @box1() -> !fir.boxchar<2>
7 // CHECK: func private @box2() -> !fir.boxproc<(i32, i32) -> i64>
8 // CHECK: func private @box3() -> !fir.box<!fir.type<derived3{f:f32}>>
9 func.func private @it1() -> !fir.int<4>
10 func.func private @box1() -> !fir.boxchar<2>
11 func.func private @box2() -> !fir.boxproc<(i32, i32) -> i64>
12 func.func private @box3() -> !fir.box<!fir.type<derived3{f:f32}>>
14 // Fortran SUBROUTINE and FUNCTION
15 // CHECK-LABEL: func private @print_index3(index, index, index)
16 // CHECK: func private @user_i64(i64)
17 // CHECK: func private @user_tdesc(!fir.tdesc<!fir.type<x>>)
18 func.func private @print_index3(index, index, index)
19 func.func private @user_i64(i64)
20 func.func private @user_tdesc(!fir.tdesc<!fir.type<x>>)
22 // expect the void return to be omitted
23 // CHECK-LABEL: func private @store_tuple(tuple<!fir.type<qq1{f1:i32}>>)
24 // CHECK: func private @get_method_box() -> !fir.box<!fir.type<derived3{f:f32}>>
25 // CHECK: func private @method_impl(!fir.box<!fir.type<derived3{f:f32}>>)
26 func.func private @store_tuple(tuple<!fir.type<qq1{f1:i32}>>) -> ()
27 func.func private @get_method_box() -> !fir.box<!fir.type<derived3{f:f32}>>
28 func.func private @method_impl(!fir.box<!fir.type<derived3{f:f32}>>)
30 // CHECK-LABEL: func private @nop()
31 // CHECK-LABEL: func private @get_func() -> (() -> ())
32 func.func private @nop()
33 func.func private @get_func() -> (() -> ())
35 // CHECK-LABEL: func @instructions() {
36 func.func @instructions() {
37 // CHECK: [[VAL_0:%.*]] = fir.alloca !fir.array<10xi32>
38 // CHECK: [[VAL_1:%.*]] = fir.load [[VAL_0]] : !fir.ref<!fir.array<10xi32>>
39 // CHECK: [[VAL_2:%.*]] = fir.alloca i32
40 // CHECK: [[VAL_3:%.*]] = arith.constant 22 : i32
41 %0 = fir.alloca !fir.array<10xi32>
42 %1 = fir.load %0 : !fir.ref<!fir.array<10xi32>>
44 %3 = arith.constant 22 : i32
46 // CHECK: fir.store [[VAL_3]] to [[VAL_2]] : !fir.ref<i32>
47 // CHECK: [[VAL_4:%.*]] = fir.undefined i32
48 // CHECK: [[VAL_5:%.*]] = fir.allocmem !fir.array<100xf32>
49 // CHECK: [[VAL_6:%.*]] = fir.embox [[VAL_5]] : (!fir.heap<!fir.array<100xf32>>) -> !fir.box<!fir.array<100xf32>>
50 fir.store %3 to %2 : !fir.ref<i32>
51 %4 = fir.undefined i32
52 %5 = fir.allocmem !fir.array<100xf32>
53 %6 = fir.embox %5 : (!fir.heap<!fir.array<100xf32>>) -> !fir.box<!fir.array<100xf32>>
55 // CHECK: [[VAL_7:%.*]] = fir.box_addr [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> !fir.ref<!fir.array<100xf32>>
56 %7 = fir.box_addr %6 : (!fir.box<!fir.array<100xf32>>) -> !fir.ref<!fir.array<100xf32>>
57 // CHECK: %[[WAL_2:.*]] = fir.undefined !fir.boxproc<() -> ()>
58 %ba1 = fir.undefined !fir.boxproc<() -> ()>
59 // CHECK: %{{.*}} = fir.box_addr %[[WAL_2]] : (!fir.boxproc<() -> ()>) -> (() -> ())
60 %ba2 = fir.box_addr %ba1 : (!fir.boxproc<() -> ()>) -> (() -> ())
61 %ba3 = fir.undefined !fir.boxchar<1>
62 // CHECK: %{{.*}} = fir.box_addr %{{.*}} : (!fir.boxchar<1>) -> !fir.ref<!fir.char<1>>
63 %ba4 = fir.box_addr %ba3 : (!fir.boxchar<1>) -> !fir.ref<!fir.char<1>>
64 %c0 = arith.constant 0 : index
65 %d1:3 = fir.box_dims %6, %c0 : (!fir.box<!fir.array<100xf32>>, index) -> (index, index, index)
66 // CHECK: [[VAL_8:%.*]] = arith.constant 0 : index
67 // CHECK: [[VAL_9:%.*]]:3 = fir.box_dims [[VAL_6]], [[VAL_8]] : (!fir.box<!fir.array<100xf32>>, index) -> (index, index, index)
68 // CHECK: fir.call @print_index3([[VAL_9]]#0, [[VAL_9]]#1, [[VAL_9]]#2) : (index, index, index) -> ()
69 // CHECK: [[VAL_10:%.*]] = fir.call @it1() : () -> !fir.int<4>
70 fir.call @print_index3(%d1#0, %d1#1, %d1#2) : (index, index, index) -> ()
71 %8 = fir.call @it1() : () -> !fir.int<4>
73 // CHECK: [[VAL_11:%.*]] = fir.box_elesize [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> i64
74 // CHECK: [[VAL_12:%.*]] = fir.box_isalloc [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> i1
75 // CHECK: [[VAL_13:%.*]] = fir.box_isarray [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> i1
76 // CHECK: [[VAL_14:%.*]] = fir.box_isptr [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> i1
77 // CHECK: [[VAL_15:%.*]] = fir.box_rank [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> i64
78 %9 = fir.box_elesize %6 : (!fir.box<!fir.array<100xf32>>) -> i64
79 %10 = fir.box_isalloc %6 : (!fir.box<!fir.array<100xf32>>) -> i1
80 %11 = fir.box_isarray %6 : (!fir.box<!fir.array<100xf32>>) -> i1
81 %12 = fir.box_isptr %6 : (!fir.box<!fir.array<100xf32>>) -> i1
82 %13 = fir.box_rank %6 : (!fir.box<!fir.array<100xf32>>) -> i64
84 // CHECK: [[VAL_16:%.*]] = fir.box_tdesc [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> !fir.tdesc<!fir.array<100xf32>>
85 // CHECK: [[VAL_17:%.*]] = fir.call @box1() : () -> !fir.boxchar<2>
86 // CHECK: [[VAL_18:%.*]] = fir.boxchar_len [[VAL_17]] : (!fir.boxchar<2>) -> i32
87 // CHECK: [[VAL_19:%.*]] = fir.call @box2() : () -> !fir.boxproc<(i32, i32) -> i64>
88 // CHECK: [[VAL_20:%.*]] = fir.boxproc_host [[VAL_19]] : (!fir.boxproc<(i32, i32) -> i64>) -> !fir.ref<i32>
89 %14 = fir.box_tdesc %6 : (!fir.box<!fir.array<100xf32>>) -> !fir.tdesc<!fir.array<100xf32>>
90 %15 = fir.call @box1() : () -> !fir.boxchar<2>
91 %16 = fir.boxchar_len %15 : (!fir.boxchar<2>) -> i32
92 %17 = fir.call @box2() : () -> !fir.boxproc<(i32, i32) -> i64>
93 %18 = fir.boxproc_host %17 : (!fir.boxproc<(i32, i32) -> i64>) -> !fir.ref<i32>
95 // CHECK: [[VAL_21:%.*]] = arith.constant 10 : i32
96 // CHECK: [[VAL_22:%.*]] = fir.coordinate_of [[VAL_5]], [[VAL_21]] : (!fir.heap<!fir.array<100xf32>>, i32) -> !fir.ref<f32>
97 // CHECK: [[VAL_23:%.*]] = fir.field_index f, !fir.type<derived{f:f32}>
98 // CHECK: [[VAL_24:%.*]] = fir.undefined !fir.type<derived{f:f32}>
99 // CHECK: [[VAL_25:%.*]] = fir.extract_value [[VAL_24]], ["f", !fir.type<derived{f:f32}>] : (!fir.type<derived{f:f32}>) -> f32
100 %19 = arith.constant 10 : i32
101 %20 = fir.coordinate_of %5, %19 : (!fir.heap<!fir.array<100xf32>>, i32) -> !fir.ref<f32>
102 %21 = fir.field_index f, !fir.type<derived{f:f32}>
103 %22 = fir.undefined !fir.type<derived{f:f32}>
104 %23 = fir.extract_value %22, ["f", !fir.type<derived{f:f32}>] : (!fir.type<derived{f:f32}>) -> f32
106 // CHECK: [[VAL_26:%.*]] = arith.constant 1 : i32
107 // CHECK: [[VAL_27:%.*]] = fir.shape [[VAL_21]] : (i32) -> !fir.shape<1>
108 // CHECK: [[VAL_28:%.*]] = arith.constant 1.0
109 // CHECK: [[VAL_29:%.*]] = fir.insert_value [[VAL_24]], [[VAL_28]], ["f", !fir.type<derived{f:f32}>] : (!fir.type<derived{f:f32}>, f32) -> !fir.type<derived{f:f32}>
110 // CHECK: [[VAL_30:%.*]] = fir.len_param_index f, !fir.type<derived3{f:f32}>
111 %c1 = arith.constant 1 : i32
112 %24 = fir.shape %19 : (i32) -> !fir.shape<1>
113 %cf1 = arith.constant 1.0 : f32
114 %25 = fir.insert_value %22, %cf1, ["f", !fir.type<derived{f:f32}>] : (!fir.type<derived{f:f32}>, f32) -> !fir.type<derived{f:f32}>
115 %26 = fir.len_param_index f, !fir.type<derived3{f:f32}>
117 // CHECK: [[VAL_31:%.*]] = fir.call @box3() : () -> !fir.class<!fir.type<derived3{f:f32}>>
118 // CHECK: [[VAL_32:%.*]] = fir.dispatch "method"([[VAL_31]] : !fir.class<!fir.type<derived3{f:f32}>>) -> i32
119 // CHECK: [[VAL_33:%.*]] = fir.convert [[VAL_32]] : (i32) -> i64
120 // CHECK: [[VAL_34:%.*]] = fir.type_desc !fir.type<x>
121 // CHECK: fir.call @user_tdesc([[VAL_34]]) : (!fir.tdesc<!fir.type<x>>) -> ()
122 // CHECK: [[VAL_35:%.*]] = fir.no_reassoc [[VAL_33]] : i64
123 %27 = fir.call @box3() : () -> !fir.class<!fir.type<derived3{f:f32}>>
124 %28 = fir.dispatch "method"(%27 : !fir.class<!fir.type<derived3{f:f32}>>) -> i32
125 %29 = fir.convert %28 : (i32) -> i64
126 %30 = fir.type_desc !fir.type<x>
127 fir.call @user_tdesc(%30) : (!fir.tdesc<!fir.type<x>>) -> ()
128 %31 = fir.no_reassoc %29 : i64
130 // CHECK: fir.call @user_i64([[VAL_35]]) : (i64) -> ()
131 // CHECK: fir.freemem [[VAL_5]] : !fir.heap<!fir.array<100xf32>>
132 // CHECK: [[VAL_36:%.*]] = fir.call @get_func() : () -> (() -> ())
133 // CHECK: fir.call [[VAL_36]]() : () -> ()
134 // CHECK: [[VAL_37:%.*]] = fir.address_of(@it1) : !fir.ref<() -> !fir.int<4>>
137 fir.call @user_i64(%31) : (i64) -> ()
138 fir.freemem %5 : !fir.heap<!fir.array<100xf32>>
139 %32 = fir.call @get_func() : () -> (() -> ())
140 fir.call %32() : () -> ()
141 %33 = fir.address_of (@it1) : !fir.ref<() -> !fir.int<4>>
145 // CHECK-LABEL: func @boxing_match() {
146 func.func @boxing_match() {
147 // CHECK: [[VAL_38:%.*]] = fir.alloca i32
148 // CHECK: [[VAL_39:%.*]] = fir.alloca !fir.type<qq2{f1:i32,f2:f64}>
149 // CHECK: [[VAL_40:%.*]] = fir.alloca !fir.char<1>
150 // CHECK: [[VAL_41:%.*]] = fir.alloca tuple<i32, f64>
151 // CHECK: [[VAL_42:%.*]] = fir.embox [[VAL_38]] : (!fir.ref<i32>) -> !fir.box<i32>
152 // CHECK: [[VAL_44:%.*]] = arith.constant 8 : i32
153 // CHECK: [[VAL_45:%.*]] = fir.undefined !fir.char<1>
154 // CHECK: [[VAL_46:%.*]] = fir.emboxchar [[VAL_40]], [[VAL_44]] : (!fir.ref<!fir.char<1>>, i32) -> !fir.boxchar<1>
155 // CHECK: [[VAL_47:%.*]]:2 = fir.unboxchar [[VAL_46]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1>>, i32)
156 // CHECK: [[VAL_48:%.*]] = fir.undefined !fir.type<qq2{f1:i32,f2:f64}>
157 // CHECK: [[VAL_49:%.*]] = arith.constant 0 : i32
158 // CHECK: [[VAL_50:%.*]] = arith.constant 12 : i32
159 // CHECK: [[VAL_51:%.*]] = fir.insert_value [[VAL_48]], [[VAL_50]], [0 : i32] : (!fir.type<qq2{f1:i32,f2:f64}>, i32) -> !fir.type<qq2{f1:i32,f2:f64}>
160 // CHECK: [[VAL_52:%.*]] = arith.constant 1 : i32
161 // CHECK: [[VAL_53:%.*]] = arith.constant 4.213000e+01 : f64
162 // CHECK: [[VAL_54:%.*]] = fir.insert_value [[VAL_48]], [[VAL_53]], [1 : i32] : (!fir.type<qq2{f1:i32,f2:f64}>, f64) -> !fir.type<qq2{f1:i32,f2:f64}>
163 // CHECK: fir.store [[VAL_54]] to [[VAL_39]] : !fir.ref<!fir.type<qq2{f1:i32,f2:f64}>>
164 // CHECK: %[[WAL_1:.*]] = fir.address_of(@method_impl)
165 // CHECK: [[VAL_55:%.*]] = fir.emboxproc %[[WAL_1]], [[VAL_41]] : ((!fir.box<!fir.type<derived3{f:f32}>>) -> (), !fir.ref<tuple<i32, f64>>) -> !fir.boxproc<(!fir.box<!fir.type<derived3{f:f32}>>) -> ()>
166 // CHECK: [[VAL_56:%.*]], [[VAL_57:%.*]] = fir.unboxproc [[VAL_55]] : (!fir.boxproc<(!fir.box<!fir.type<derived3{f:f32}>>) -> ()>) -> ((!fir.box<!fir.type<derived3{f:f32}>>) -> (), !fir.ref<tuple<!fir.type<qq2{f1:i32,f2:f64}>>>)
167 // CHECK: [[VAL_58:%.*]] = fir.call @box2() : () -> !fir.boxproc<(i32, i32) -> i64>
168 // CHECK: [[VAL_59:%.*]], [[VAL_60:%.*]] = fir.unboxproc [[VAL_58]] : (!fir.boxproc<(i32, i32) -> i64>) -> ((i32, i32) -> i64, !fir.ref<tuple<!fir.type<qq1{f1:i32}>>>)
169 // CHECK: [[VAL_61:%.*]] = fir.load [[VAL_60]] : !fir.ref<tuple<!fir.type<qq1{f1:i32}>>>
170 // CHECK: fir.call @store_tuple([[VAL_61]]) : (tuple<!fir.type<qq1{f1:i32}>>) -> ()
174 %d6 = fir.alloca !fir.type<qq2{f1:i32,f2:f64}>
175 %d3 = fir.alloca !fir.char<1>
176 %e6 = fir.alloca tuple<i32,f64>
177 %1 = fir.embox %0 : (!fir.ref<i32>) -> !fir.box<i32>
178 %c8 = arith.constant 8 : i32
179 %3 = fir.undefined !fir.char<1>
180 %4 = fir.emboxchar %d3, %c8 : (!fir.ref<!fir.char<1>>, i32) -> !fir.boxchar<1>
181 %5:2 = fir.unboxchar %4 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1>>, i32)
182 %6 = fir.undefined !fir.type<qq2{f1:i32,f2:f64}>
183 %z = arith.constant 0 : i32
184 %c12 = arith.constant 12 : i32
185 %a2 = fir.insert_value %6, %c12, [0 : i32] : (!fir.type<qq2{f1:i32,f2:f64}>, i32) -> !fir.type<qq2{f1:i32,f2:f64}>
186 %z1 = arith.constant 1 : i32
187 %c42 = arith.constant 42.13 : f64
188 %a3 = fir.insert_value %6, %c42, [1 : i32] : (!fir.type<qq2{f1:i32,f2:f64}>, f64) -> !fir.type<qq2{f1:i32,f2:f64}>
189 fir.store %a3 to %d6 : !fir.ref<!fir.type<qq2{f1:i32,f2:f64}>>
190 %mi = fir.address_of(@method_impl) : (!fir.box<!fir.type<derived3{f:f32}>>) -> ()
191 %7 = fir.emboxproc %mi, %e6 : ((!fir.box<!fir.type<derived3{f:f32}>>) -> (), !fir.ref<tuple<i32,f64>>) -> !fir.boxproc<(!fir.box<!fir.type<derived3{f:f32}>>) -> ()>
192 %8:2 = fir.unboxproc %7 : (!fir.boxproc<(!fir.box<!fir.type<derived3{f:f32}>>) -> ()>) -> ((!fir.box<!fir.type<derived3{f:f32}>>) -> (), !fir.ref<tuple<!fir.type<qq2{f1:i32,f2:f64}>>>)
193 %9 = fir.call @box2() : () -> !fir.boxproc<(i32, i32) -> i64>
194 %10:2 = fir.unboxproc %9 : (!fir.boxproc<(i32, i32) -> i64>) -> ((i32, i32) -> i64, !fir.ref<tuple<!fir.type<qq1{f1:i32}>>>)
195 %11 = fir.load %10#1 : !fir.ref<tuple<!fir.type<qq1{f1:i32}>>>
196 fir.call @store_tuple(%11) : (tuple<!fir.type<qq1{f1:i32}>>) -> ()
200 // CHECK-LABEL: func @loop() {
202 // CHECK: [[VAL_62:%.*]] = arith.constant 1 : index
203 // CHECK: [[VAL_63:%.*]] = arith.constant 10 : index
204 // CHECK: [[VAL_64:%.*]] = arith.constant true
205 %c1 = arith.constant 1 : index
206 %c10 = arith.constant 10 : index
207 %ct = arith.constant true
209 // CHECK: fir.do_loop [[VAL_65:%.*]] = [[VAL_62]] to [[VAL_63]] step [[VAL_62]] {
210 // CHECK: fir.if [[VAL_64]] {
211 // CHECK: fir.call @nop() : () -> ()
213 // CHECK: fir.call @nop() : () -> ()
216 // CHECK: fir.unreachable
218 fir.do_loop %i = %c1 to %c10 step %c1 {
220 fir.call @nop() : () -> ()
222 fir.call @nop() : () -> ()
228 // CHECK: func @bar_select([[VAL_66:%.*]]: i32, [[VAL_67:%.*]]: i32) -> i32 {
229 func.func @bar_select(%arg : i32, %arg2 : i32) -> i32 {
230 // CHECK: [[VAL_68:%.*]] = arith.constant 1 : i32
231 // CHECK: [[VAL_69:%.*]] = arith.constant 2 : i32
232 // CHECK: [[VAL_70:%.*]] = arith.constant 3 : i32
233 // CHECK: [[VAL_71:%.*]] = arith.constant 4 : i32
234 %0 = arith.constant 1 : i32
235 %1 = arith.constant 2 : i32
236 %2 = arith.constant 3 : i32
237 %3 = arith.constant 4 : i32
239 // CHECK: fir.select [[VAL_66]] : i32 [1, ^bb1([[VAL_68]] : i32), 2, ^bb2([[VAL_70]], [[VAL_66]], [[VAL_67]] : i32, i32, i32), -3, ^bb3([[VAL_67]], [[VAL_70]] : i32, i32), 4, ^bb4([[VAL_69]] : i32), unit, ^bb5]
240 // CHECK: ^bb1([[VAL_72:%.*]]: i32):
241 // CHECK: return [[VAL_72]] : i32
242 // CHECK: ^bb2([[VAL_73:%.*]]: i32, [[VAL_74:%.*]]: i32, [[VAL_75:%.*]]: i32):
243 // CHECK: [[VAL_76:%.*]] = arith.addi [[VAL_73]], [[VAL_74]] : i32
244 // CHECK: [[VAL_77:%.*]] = arith.addi [[VAL_76]], [[VAL_75]] : i32
245 // CHECK: return [[VAL_77]] : i32
246 // CHECK: ^bb3([[VAL_78:%.*]]: i32, [[VAL_79:%.*]]: i32):
247 // CHECK: [[VAL_80:%.*]] = arith.addi [[VAL_78]], [[VAL_79]] : i32
248 // CHECK: return [[VAL_80]] : i32
249 // CHECK: ^bb4([[VAL_81:%.*]]: i32):
250 // CHECK: return [[VAL_81]] : i32
252 // CHECK: [[VAL_82:%.*]] = arith.constant 0 : i32
253 // CHECK: return [[VAL_82]] : i32
255 fir.select %arg:i32 [ 1,^bb1(%0:i32), 2,^bb2(%2,%arg,%arg2:i32,i32,i32), -3,^bb3(%arg2,%2:i32,i32), 4,^bb4(%1:i32), unit,^bb5 ]
258 ^bb2(%b : i32, %b2 : i32, %b3:i32) :
259 %4 = arith.addi %b, %b2 : i32
260 %5 = arith.addi %4, %b3 : i32
262 ^bb3(%c:i32, %c2:i32) :
263 %6 = arith.addi %c, %c2 : i32
268 %zero = arith.constant 0 : i32
272 // CHECK-LABEL: func @bar_select_rank(
273 // CHECK-SAME: [[VAL_83:%.*]]: i32, [[VAL_84:%.*]]: i32) -> i32 {
274 func.func @bar_select_rank(%arg : i32, %arg2 : i32) -> i32 {
275 // CHECK: [[VAL_85:%.*]] = arith.constant 1 : i32
276 // CHECK: [[VAL_86:%.*]] = arith.constant 2 : i32
277 // CHECK: [[VAL_87:%.*]] = arith.constant 3 : i32
278 // CHECK: [[VAL_88:%.*]] = arith.constant 4 : i32
279 %0 = arith.constant 1 : i32
280 %1 = arith.constant 2 : i32
281 %2 = arith.constant 3 : i32
282 %3 = arith.constant 4 : i32
284 // CHECK: fir.select_rank [[VAL_83]] : i32 [1, ^bb1([[VAL_85]] : i32), 2, ^bb2([[VAL_87]], [[VAL_83]], [[VAL_84]] : i32, i32, i32), 3, ^bb3([[VAL_84]], [[VAL_87]] : i32, i32), -1, ^bb4([[VAL_86]] : i32), unit, ^bb5]
285 // CHECK: ^bb1([[VAL_89:%.*]]: i32):
286 // CHECK: return [[VAL_89]] : i32
287 // CHECK: ^bb2([[VAL_90:%.*]]: i32, [[VAL_91:%.*]]: i32, [[VAL_92:%.*]]: i32):
288 // CHECK: [[VAL_93:%.*]] = arith.addi [[VAL_90]], [[VAL_91]] : i32
289 // CHECK: [[VAL_94:%.*]] = arith.addi [[VAL_93]], [[VAL_92]] : i32
290 // CHECK: return [[VAL_94]] : i32
291 fir.select_rank %arg:i32 [ 1,^bb1(%0:i32), 2,^bb2(%2,%arg,%arg2:i32,i32,i32), 3,^bb3(%arg2,%2:i32,i32), -1,^bb4(%1:i32), unit,^bb5 ]
294 ^bb2(%b : i32, %b2 : i32, %b3:i32) :
295 %4 = arith.addi %b, %b2 : i32
296 %5 = arith.addi %4, %b3 : i32
299 // CHECK: ^bb3([[VAL_95:%.*]]: i32, [[VAL_96:%.*]]: i32):
300 // CHECK: [[VAL_97:%.*]] = arith.addi [[VAL_95]], [[VAL_96]] : i32
301 // CHECK: return [[VAL_97]] : i32
302 // CHECK: ^bb4([[VAL_98:%.*]]: i32):
303 // CHECK: return [[VAL_98]] : i32
304 ^bb3(%c:i32, %c2:i32) :
305 %6 = arith.addi %c, %c2 : i32
311 // CHECK: [[VAL_99:%.*]] = arith.constant 0 : i32
312 // CHECK: [[VAL_100:%.*]] = fir.call @get_method_box() : () -> !fir.class<!fir.type<derived3{f:f32}>>
313 // CHECK: fir.dispatch "method"([[VAL_100]] : !fir.class<!fir.type<derived3{f:f32}>>)
315 %zero = arith.constant 0 : i32
316 %7 = fir.call @get_method_box() : () -> !fir.class<!fir.type<derived3{f:f32}>>
317 fir.dispatch "method"(%7 : !fir.class<!fir.type<derived3{f:f32}>>)
319 // CHECK: return [[VAL_99]] : i32
324 // CHECK-LABEL: func @bar_select_type(
325 // CHECK-SAME: [[VAL_101:%.*]]: !fir.class<!fir.type<name(param1:i32){fld:!fir.char<1>}>>) -> i32 {
326 func.func @bar_select_type(%arg : !fir.class<!fir.type<name(param1:i32){fld:!fir.char<1>}>>) -> i32 {
328 // CHECK: [[VAL_102:%.*]] = arith.constant 1 : i32
329 // CHECK: [[VAL_103:%.*]] = arith.constant 2 : i32
330 // CHECK: [[VAL_104:%.*]] = arith.constant 3 : i32
331 // CHECK: [[VAL_105:%.*]] = arith.constant 4 : i32
332 %0 = arith.constant 1 : i32
333 %1 = arith.constant 2 : i32
334 %2 = arith.constant 3 : i32
335 %3 = arith.constant 4 : i32
337 // CHECK: fir.select_type [[VAL_101]] : !fir.class<!fir.type<name(param1:i32){fld:!fir.char<1>}>> [#fir.type_is<!fir.int<4>>, ^bb1([[VAL_102]] : i32), #fir.type_is<!fir.int<8>>, ^bb2([[VAL_104]] : i32), #fir.class_is<!fir.int<2>>, ^bb3([[VAL_104]] : i32), #fir.type_is<!fir.int<1>>, ^bb4([[VAL_103]] : i32), unit, ^bb5]
338 fir.select_type %arg : !fir.class<!fir.type<name(param1:i32){fld:!fir.char<1>}>> [ #fir.type_is<!fir.int<4>>,^bb1(%0:i32), #fir.type_is<!fir.int<8>>,^bb2(%2:i32), #fir.class_is<!fir.int<2>>,^bb3(%2:i32), #fir.type_is<!fir.int<1>>,^bb4(%1:i32), unit,^bb5 ]
340 // CHECK: ^bb1([[VAL_106:%.*]]: i32):
341 // CHECK: return [[VAL_106]] : i32
342 // CHECK: ^bb2([[VAL_107:%.*]]: i32):
343 // CHECK: return [[VAL_107]] : i32
344 // CHECK: ^bb3([[VAL_108:%.*]]: i32):
345 // CHECK: return [[VAL_108]] : i32
346 // CHECK: ^bb4([[VAL_109:%.*]]: i32):
347 // CHECK: return [[VAL_109]] : i32
358 // CHECK: [[VAL_110:%.*]] = arith.constant 0 : i32
359 // CHECK: return [[VAL_110]] : i32
362 %zero = arith.constant 0 : i32
366 // CHECK-LABEL: func @bar_select_case(
367 // CHECK-SAME: [[VAL_111:%.*]]: i32, [[VAL_112:%.*]]: i32) -> i32 {
368 // CHECK: [[VAL_113:%.*]] = arith.constant 1 : i32
369 // CHECK: [[VAL_114:%.*]] = arith.constant 2 : i32
370 // CHECK: [[VAL_115:%.*]] = arith.constant 3 : i32
371 // CHECK: [[VAL_116:%.*]] = arith.constant 4 : i32
372 func.func @bar_select_case(%arg : i32, %arg2 : i32) -> i32 {
373 %0 = arith.constant 1 : i32
374 %1 = arith.constant 2 : i32
375 %2 = arith.constant 3 : i32
376 %3 = arith.constant 4 : i32
378 // CHECK: fir.select_case [[VAL_111]] : i32 [#fir.point, [[VAL_113]], ^bb1([[VAL_113]] : i32), #fir.lower, [[VAL_114]], ^bb2([[VAL_115]], [[VAL_111]], [[VAL_112]], [[VAL_114]] : i32, i32, i32, i32), #fir.interval, [[VAL_115]], [[VAL_116]], ^bb3([[VAL_115]], [[VAL_112]] : i32, i32), #fir.upper, [[VAL_111]], ^bb4([[VAL_114]] : i32), unit, ^bb5]
379 fir.select_case %arg : i32 [#fir.point, %0, ^bb1(%0:i32), #fir.lower, %1, ^bb2(%2,%arg,%arg2,%1:i32,i32,i32,i32), #fir.interval, %2, %3, ^bb3(%2,%arg2:i32,i32), #fir.upper, %arg, ^bb4(%1:i32), unit, ^bb5]
381 // CHECK: ^bb1([[VAL_117:%.*]]: i32):
382 // CHECK: return [[VAL_117]] : i32
383 // CHECK: ^bb2([[VAL_118:%.*]]: i32, [[VAL_119:%.*]]: i32, [[VAL_120:%.*]]: i32, [[VAL_121:%.*]]: i32):
384 // CHECK: [[VAL_122:%.*]] = arith.addi [[VAL_118]], [[VAL_119]] : i32
385 // CHECK: [[VAL_123:%.*]] = arith.muli [[VAL_122]], [[VAL_120]] : i32
386 // CHECK: [[VAL_124:%.*]] = arith.addi [[VAL_123]], [[VAL_121]] : i32
387 // CHECK: return [[VAL_124]] : i32
388 // CHECK: ^bb3([[VAL_125:%.*]]: i32, [[VAL_126:%.*]]: i32):
389 // CHECK: [[VAL_127:%.*]] = arith.addi [[VAL_125]], [[VAL_126]] : i32
390 // CHECK: return [[VAL_127]] : i32
391 // CHECK: ^bb4([[VAL_128:%.*]]: i32):
392 // CHECK: return [[VAL_128]] : i32
395 ^bb2(%b : i32, %b2:i32, %b3:i32, %b4:i32) :
396 %4 = arith.addi %b, %b2 : i32
397 %5 = arith.muli %4, %b3 : i32
398 %6 = arith.addi %5, %b4 : i32
400 ^bb3(%c : i32, %c2 : i32) :
401 %7 = arith.addi %c, %c2 : i32
407 // CHECK: [[VAL_129:%.*]] = arith.constant 0 : i32
408 // CHECK: return [[VAL_129]] : i32
411 %zero = arith.constant 0 : i32
415 // CHECK-LABEL: fir.global @global_var : i32 {
416 // CHECK: [[VAL_130:%.*]] = arith.constant 1 : i32
417 // CHECK: fir.has_value [[VAL_130]] : i32
419 fir.global @global_var : i32 {
420 %0 = arith.constant 1 : i32
421 fir.has_value %0 : i32
424 // CHECK-LABEL: fir.global @global_constant constant : i32 {
425 // CHECK: [[VAL_131:%.*]] = arith.constant 934 : i32
426 // CHECK: fir.has_value [[VAL_131]] : i32
428 fir.global @global_constant constant : i32 {
429 %0 = arith.constant 934 : i32
430 fir.has_value %0 : i32
433 // CHECK-LABEL: fir.global @global_derived : !fir.type<minez(f:i32)> {
434 // CHECK: fir.global_len "f", 1 : i32
435 // CHECK: [[VAL_132:%.*]] = fir.undefined !fir.type<minez(f:i32)>
436 // CHECK: fir.has_value [[VAL_132]] : !fir.type<minez(f:i32)>
438 fir.global @global_derived : !fir.type<minez(f:i32)> {
439 fir.global_len f, 1 : i32
440 %0 = fir.undefined !fir.type<minez>
441 fir.has_value %0 : !fir.type<minez>
444 // CHECK-LABEL: fir.global linkonce_odr @global_linkonce_odr : i32 {
445 // CHECK: [[VAL_130:%.*]] = arith.constant 1 : i32
446 // CHECK: fir.has_value [[VAL_130]] : i32
448 fir.global linkonce_odr @global_linkonce_odr : i32 {
449 %0 = arith.constant 1 : i32
450 fir.has_value %0 : i32
453 // CHECK-LABEL: fir.dispatch_table @dispatch_tbl {
454 // CHECK: fir.dt_entry "method", @method_impl
456 fir.dispatch_table @dispatch_tbl {
457 fir.dt_entry "method", @method_impl
460 // CHECK-LABEL: func @compare_complex(
461 // CHECK-SAME: [[VAL_151:%.*]]: !fir.complex<16>, [[VAL_152:%.*]]: !fir.complex<16>) {
462 func.func @compare_complex(%a : !fir.complex<16>, %b : !fir.complex<16>) {
464 // CHECK: [[VAL_153:%.*]] = fir.cmpc "false", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
465 // CHECK: [[VAL_154:%.*]] = fir.cmpc "oeq", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
466 // CHECK: [[VAL_155:%.*]] = fir.cmpc "ogt", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
467 // CHECK: [[VAL_156:%.*]] = fir.cmpc "oge", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
468 %d0 = fir.cmpc "false", %a, %b : !fir.complex<16>
469 %d1 = fir.cmpc "oeq", %a, %b : !fir.complex<16>
470 %d2 = fir.cmpc "ogt", %a, %b : !fir.complex<16>
471 %d3 = fir.cmpc "oge", %a, %b : !fir.complex<16>
473 // CHECK: [[VAL_157:%.*]] = fir.cmpc "olt", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
474 // CHECK: [[VAL_158:%.*]] = fir.cmpc "ole", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
475 // CHECK: [[VAL_159:%.*]] = fir.cmpc "one", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
476 // CHECK: [[VAL_160:%.*]] = fir.cmpc "ord", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
477 %a0 = fir.cmpc "olt", %a, %b : !fir.complex<16>
478 %a1 = fir.cmpc "ole", %a, %b : !fir.complex<16>
479 %a2 = fir.cmpc "one", %a, %b : !fir.complex<16>
480 %a3 = fir.cmpc "ord", %a, %b : !fir.complex<16>
482 // CHECK: [[VAL_161:%.*]] = fir.cmpc "ueq", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
483 // CHECK: [[VAL_162:%.*]] = fir.cmpc "ugt", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
484 // CHECK: [[VAL_163:%.*]] = fir.cmpc "uge", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
485 // CHECK: [[VAL_164:%.*]] = fir.cmpc "ult", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
486 %b0 = fir.cmpc "ueq", %a, %b : !fir.complex<16>
487 %b1 = fir.cmpc "ugt", %a, %b : !fir.complex<16>
488 %b2 = fir.cmpc "uge", %a, %b : !fir.complex<16>
489 %b3 = fir.cmpc "ult", %a, %b : !fir.complex<16>
491 // CHECK: [[VAL_165:%.*]] = fir.cmpc "ule", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
492 // CHECK: [[VAL_166:%.*]] = fir.cmpc "une", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
493 // CHECK: [[VAL_167:%.*]] = fir.cmpc "uno", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
494 // CHECK: [[VAL_168:%.*]] = fir.cmpc "true", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
495 %c0 = fir.cmpc "ule", %a, %b : !fir.complex<16>
496 %c1 = fir.cmpc "une", %a, %b : !fir.complex<16>
497 %c2 = fir.cmpc "uno", %a, %b : !fir.complex<16>
498 %c3 = fir.cmpc "true", %a, %b : !fir.complex<16>
504 // CHECK-LABEL: func @arith_real(
505 // CHECK-SAME: [[VAL_169:%.*]]: f128, [[VAL_170:%.*]]: f128) -> f128 {
506 func.func @arith_real(%a : f128, %b : f128) -> f128 {
508 // CHECK: [[VAL_171:%.*]] = arith.constant 1.0
509 // CHECK: [[VAL_172:%.*]] = fir.convert [[VAL_171]] : (f32) -> f128
510 // CHECK: [[VAL_173:%.*]] = arith.negf [[VAL_169]] : f128
511 // CHECK: [[VAL_174:%.*]] = arith.addf [[VAL_172]], [[VAL_173]] : f128
512 // CHECK: [[VAL_175:%.*]] = arith.subf [[VAL_174]], [[VAL_170]] : f128
513 // CHECK: [[VAL_176:%.*]] = arith.mulf [[VAL_173]], [[VAL_175]] : f128
514 // CHECK: [[VAL_177:%.*]] = arith.divf [[VAL_176]], [[VAL_169]] : f128
515 %c1 = arith.constant 1.0 : f32
516 %0 = fir.convert %c1 : (f32) -> f128
517 %1 = arith.negf %a : f128
518 %2 = arith.addf %0, %1 : f128
519 %3 = arith.subf %2, %b : f128
520 %4 = arith.mulf %1, %3 : f128
521 %5 = arith.divf %4, %a : f128
522 // CHECK: return [[VAL_177]] : f128
527 // CHECK-LABEL: func @arith_complex(
528 // CHECK-SAME: [[VAL_179:%.*]]: !fir.complex<16>, [[VAL_180:%.*]]: !fir.complex<16>) -> !fir.complex<16> {
529 func.func @arith_complex(%a : !fir.complex<16>, %b : !fir.complex<16>) -> !fir.complex<16> {
530 // CHECK: [[VAL_181:%.*]] = fir.negc [[VAL_179]] : !fir.complex<16>
531 // CHECK: [[VAL_182:%.*]] = fir.addc [[VAL_180]], [[VAL_181]] : !fir.complex<16>
532 // CHECK: [[VAL_183:%.*]] = fir.subc [[VAL_182]], [[VAL_180]] : !fir.complex<16>
533 // CHECK: [[VAL_184:%.*]] = fir.mulc [[VAL_181]], [[VAL_183]] : !fir.complex<16>
534 // CHECK: [[VAL_185:%.*]] = fir.divc [[VAL_184]], [[VAL_179]] : !fir.complex<16>
535 %1 = fir.negc %a : !fir.complex<16>
536 %2 = fir.addc %b, %1 : !fir.complex<16>
537 %3 = fir.subc %2, %b : !fir.complex<16>
538 %4 = fir.mulc %1, %3 : !fir.complex<16>
539 %5 = fir.divc %4, %a : !fir.complex<16>
540 // CHECK: return [[VAL_185]] : !fir.complex<16>
542 return %5 : !fir.complex<16>
545 // CHECK-LABEL: func @character_literal() -> !fir.char<1,13> {
546 func.func @character_literal() -> !fir.char<1,13> {
547 // CHECK: [[VAL_186:%.*]] = fir.string_lit "Hello, World!"(13) : !fir.char<1,13>
548 %0 = fir.string_lit "Hello, World!"(13) : !fir.char<1,13>
549 // CHECK: return [[VAL_186]] : !fir.char<1,13>
550 return %0 : !fir.char<1,13>
554 // CHECK-LABEL: func private @earlyexit2(i32) -> i1
555 func.func private @earlyexit2(%a : i32) -> i1
557 // CHECK-LABEL: func @early_exit(
558 // CHECK-SAME: [[VAL_187:%.*]]: i1, [[VAL_188:%.*]]: i32) -> i1 {
559 func.func @early_exit(%ok : i1, %k : i32) -> i1 {
560 // CHECK: [[VAL_189:%.*]] = arith.constant 1 : index
561 // CHECK: [[VAL_190:%.*]] = arith.constant 100 : index
562 %c1 = arith.constant 1 : index
563 %c100 = arith.constant 100 : index
565 // CHECK: %[[VAL_191:.*]]:2 = fir.iterate_while ([[VAL_192:%.*]] = [[VAL_189]] to [[VAL_190]] step [[VAL_189]]) and ([[VAL_193:%.*]] = [[VAL_187]]) iter_args([[VAL_194:%.*]] = [[VAL_188]]) -> (i32) {
566 // CHECK: [[VAL_195:%.*]] = func.call @earlyexit2([[VAL_194]]) : (i32) -> i1
567 // CHECK: fir.result [[VAL_195]], [[VAL_194]] : i1, i32
569 %newOk:2 = fir.iterate_while (%i = %c1 to %c100 step %c1) and (%ok_ = %ok) iter_args(%v = %k) -> (i32) {
570 %stop = func.call @earlyexit2(%v) : (i32) -> i1
571 fir.result %stop, %v : i1, i32
573 // CHECK: return %[[VAL_191]]#0 : i1
578 // CHECK-LABEL: @array_access
579 func.func @array_access(%arr : !fir.ref<!fir.array<?x?xf32>>) {
580 // CHECK-DAG: %[[c1:.*]] = arith.constant 100
581 // CHECK-DAG: %[[c2:.*]] = arith.constant 50
582 %c100 = arith.constant 100 : index
583 %c50 = arith.constant 50 : index
584 // CHECK: %[[sh:.*]] = fir.shape %[[c1]], %[[c2]] : {{.*}} -> !fir.shape<2>
585 %shape = fir.shape %c100, %c50 : (index, index) -> !fir.shape<2>
586 %c47 = arith.constant 47 : index
587 %c78 = arith.constant 78 : index
588 %c3 = arith.constant 3 : index
589 %c18 = arith.constant 18 : index
590 %c36 = arith.constant 36 : index
591 %c4 = arith.constant 4 : index
592 // CHECK: %[[sl:.*]] = fir.slice {{.*}} -> !fir.slice<2>
593 %slice = fir.slice %c47, %c78, %c3, %c18, %c36, %c4 : (index,index,index,index,index,index) -> !fir.slice<2>
594 %c0 = arith.constant 0 : index
595 %c99 = arith.constant 99 : index
596 %c1 = arith.constant 1 : index
597 fir.do_loop %i = %c0 to %c99 step %c1 {
598 %c49 = arith.constant 49 : index
599 fir.do_loop %j = %c0 to %c49 step %c1 {
600 // CHECK: fir.array_coor %{{.*}}(%[[sh]]) [%[[sl]]] %{{.*}}, %{{.*}} :
601 %p = fir.array_coor %arr(%shape)[%slice] %i, %j : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>, !fir.slice<2>, index, index) -> !fir.ref<f32>
602 %x = arith.constant 42.0 : f32
603 fir.store %x to %p : !fir.ref<f32>
609 // CHECK-LABEL: @test_is_present
610 func.func @test_is_present(%arg0: !fir.box<!fir.array<?xf32>>) -> i1 {
611 // CHECK: fir.is_present %{{.*}} : (!fir.box<!fir.array<?xf32>>) -> i1
612 %0 = fir.is_present %arg0 : (!fir.box<!fir.array<?xf32>>) -> i1
615 // CHECK-LABEL: @test_absent
616 func.func @test_absent() -> i1 {
617 // CHECK: fir.absent !fir.box<!fir.array<?xf32>>
618 %0 = fir.absent !fir.box<!fir.array<?xf32>>
619 %1 = fir.call @_QPfoo(%0) : (!fir.box<!fir.array<?xf32>>) -> i1
623 // CHECK-LABEL: @test_misc_ops(
624 // CHECK-SAME: [[ARR1:%.*]]: !fir.ref<!fir.array<?x?xf32>>, [[INDXM:%.*]]: index, [[INDXN:%.*]]: index, [[INDXO:%.*]]: index, [[INDXP:%.*]]: index)
625 func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
626 // CHECK: [[I10:%.*]] = arith.constant 10 : index
627 // CHECK: [[J20:%.*]] = arith.constant 20 : index
628 // CHECK: [[C2:%.*]] = arith.constant 2 : index
629 // CHECK: [[C9:%.*]] = arith.constant 9 : index
630 // CHECK: [[C1_I32:%.*]] = arith.constant 9 : i32
631 %i10 = arith.constant 10 : index
632 %j20 = arith.constant 20 : index
633 %c2 = arith.constant 2 : index
634 %c9 = arith.constant 9 : index
635 %c1_i32 = arith.constant 9 : i32
637 // CHECK: [[ARR2:%.*]] = fir.zero_bits !fir.array<10xi32>
638 // CHECK: [[ARR3:%.*]] = fir.insert_on_range [[ARR2]], [[C1_I32]] from (2) to (9) : (!fir.array<10xi32>, i32) -> !fir.array<10xi32>
639 // CHECK: fir.call @noret1([[ARR3]]) : (!fir.array<10xi32>) -> ()
640 %arr2 = fir.zero_bits !fir.array<10xi32>
641 %arr3 = fir.insert_on_range %arr2, %c1_i32 from (2) to (9) : (!fir.array<10xi32>, i32) -> !fir.array<10xi32>
642 fir.call @noret1(%arr3) : (!fir.array<10xi32>) -> ()
644 // CHECK: [[SHAPE:%.*]] = fir.shape_shift [[INDXM:%.*]], [[INDXN:%.*]], [[INDXO:%.*]], [[INDXP:%.*]] : (index, index, index, index) -> !fir.shapeshift<2>
645 // CHECK: [[AV1:%.*]] = fir.array_load [[ARR1]]([[SHAPE]]) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
646 // CHECK: [[FVAL:%.*]] = fir.array_fetch [[AV1]], [[I10]], [[J20]] : (!fir.array<?x?xf32>, index, index) -> f32
647 // CHECK: [[AV2:%.*]] = fir.array_update [[AV1]], [[FVAL]], [[I10]], [[J20]] : (!fir.array<?x?xf32>, f32, index, index) -> !fir.array<?x?xf32>
648 // CHECK: fir.array_merge_store [[AV1]], [[AV2]] to [[ARR1]] : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>
649 %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
650 %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
651 %f = fir.array_fetch %av1, %i10, %j20 : (!fir.array<?x?xf32>, index, index) -> f32
652 %av2 = fir.array_update %av1, %f, %i10, %j20 : (!fir.array<?x?xf32>, f32, index, index) -> !fir.array<?x?xf32>
653 fir.array_merge_store %av1, %av2 to %arr1 : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>
655 // CHECK: [[AV3:%.*]] = fir.array_load [[ARR1]]([[SHAPE]]) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
656 // CHECK: [[FVAL2:%.*]] = fir.array_fetch [[AV3]], [[I10]], [[J20]] : (!fir.array<?x?xf32>, index, index) -> f32
657 // CHECK: [[AV4:%.*]]:2 = fir.array_modify [[AV3]], [[I10]], [[J20]] : (!fir.array<?x?xf32>, index, index) -> (!fir.ref<f32>, !fir.array<?x?xf32>)
658 // CHECK: fir.store [[FVAL2]] to [[AV4]]#0 : !fir.ref<f32>
659 // CHECK: fir.array_merge_store [[AV3]], [[AV4]]#1 to [[ARR1]] : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>
660 %av3 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
661 %f2 = fir.array_fetch %av3, %i10, %j20 : (!fir.array<?x?xf32>, index, index) -> f32
662 %addr, %av4 = fir.array_modify %av3, %i10, %j20 : (!fir.array<?x?xf32>, index, index) -> (!fir.ref<f32>, !fir.array<?x?xf32>)
663 fir.store %f2 to %addr : !fir.ref<f32>
664 fir.array_merge_store %av3, %av4 to %arr1 : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>
668 // CHECK-LABEL: @test_const_complex
669 func.func @test_const_complex() {
670 // CHECK-DAG: {{%.*}} = fir.constc(#fir.real<2, i x3000>, #fir.real<2, i x4C40>) : !fir.complex<2>
671 // CHECK-DAG: {{%.*}} = fir.constc(#fir.real<3, i x3E80>, #fir.real<3, i x4202>) : !fir.complex<3>
672 // CHECK-DAG: {{%.*}} = fir.constc(#fir.real<4, i x3E800000>, #fir.real<4, i x42028000>) : !fir.complex<4>
673 // CHECK-DAG: {{%.*}} = fir.constc(#fir.real<8, i x3FD0000000000000>, #fir.real<8, i x4040500000000000>) : !fir.complex<8>
674 // CHECK-DAG: {{%.*}} = fir.constc(#fir.real<10, i x3FFD8000000000000000>, #fir.real<10, i x40048280000000000000>) : !fir.complex<10>
675 // CHECK-DAG: {{%.*}} = fir.constc(#fir.real<16, i x3FFD0000000000000000000000000000>, #fir.real<16, i x40040500000000000000000000000000>) : !fir.complex<16>
676 %c2 = fir.constc (#fir.real<2, 0.125>, #fir.real<2, 17.0>) : !fir.complex<2>
677 %c3 = fir.constc (#fir.real<3, 0.25>, #fir.real<3, 32.625>) : !fir.complex<3>
678 %c4 = fir.constc (#fir.real<4, 0.25>, #fir.real<4, 32.625>) : !fir.complex<4>
679 %c8 = fir.constc (#fir.real<8, 0.25>, #fir.real<8, 32.625>) : !fir.complex<8>
680 %c10 = fir.constc (#fir.real<10, 0.25>, #fir.real<10, 32.625>) : !fir.complex<10>
681 %c16 = fir.constc (#fir.real<16, 0.25>, #fir.real<16, 32.625>) : !fir.complex<16>
685 // CHECK-LABEL: @insert_on_range_multi_dim
686 // CHECK-SAME: %[[ARR:.*]]: !fir.array<10x20xi32>, %[[CST:.*]]: i32
687 func.func @insert_on_range_multi_dim(%arr : !fir.array<10x20xi32>, %cst : i32) {
688 // CHECK: fir.insert_on_range %[[ARR]], %[[CST]] from (2, 3) to (5, 6) : (!fir.array<10x20xi32>, i32) -> !fir.array<10x20xi32>
689 %arr3 = fir.insert_on_range %arr, %cst from (2, 3) to (5, 6) : (!fir.array<10x20xi32>, i32) -> !fir.array<10x20xi32>
693 // CHECK-LABEL: @test_shift
694 func.func @test_shift(%arg0: !fir.box<!fir.array<?xf32>>) -> !fir.ref<f32> {
695 %c4 = arith.constant 4 : index
696 %c100 = arith.constant 100 : index
697 // CHECK: fir.shift %{{.*}} : (index) -> !fir.shift<1>
698 %0 = fir.shift %c4 : (index) -> !fir.shift<1>
699 %1 = fir.array_coor %arg0(%0) %c100 : (!fir.box<!fir.array<?xf32>>, !fir.shift<1>, index) -> !fir.ref<f32>
700 return %1 : !fir.ref<f32>
703 func.func private @bar_rebox_test(!fir.box<!fir.array<?x?xf32>>)
704 // CHECK-LABEL: @test_rebox(
705 func.func @test_rebox(%arg0: !fir.box<!fir.array<?xf32>>) {
706 %c0 = arith.constant 0 : index
707 %c1 = arith.constant 1 : index
708 %c2 = arith.constant 2 : index
709 %c3 = arith.constant 3 : index
710 %c4 = arith.constant 4 : index
711 %c10 = arith.constant 10 : index
712 %c33 = arith.constant 33 : index
713 %0 = fir.slice %c10, %c33, %c2 : (index, index, index) -> !fir.slice<1>
714 %1 = fir.shift %c0 : (index) -> !fir.shift<1>
715 // CHECK: fir.rebox %{{.*}}(%{{.*}}) [%{{.*}}] : (!fir.box<!fir.array<?xf32>>, !fir.shift<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
716 %2 = fir.rebox %arg0(%1) [%0] : (!fir.box<!fir.array<?xf32>>, !fir.shift<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
717 %3 = fir.shape %c3, %c4 : (index, index) -> !fir.shape<2>
718 // CHECK: fir.rebox %{{.*}}(%{{.*}}) : (!fir.box<!fir.array<?xf32>>, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>>
719 %4 = fir.rebox %2(%3) : (!fir.box<!fir.array<?xf32>>, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>>
720 fir.call @bar_rebox_test(%4) : (!fir.box<!fir.array<?x?xf32>>) -> ()
724 func.func private @bar_rebox_test_char(!fir.box<!fir.array<?x!fir.char<1,?>>>)
725 // CHECK-LABEL: @test_rebox_char(
726 func.func @test_rebox_char(%arg0: !fir.box<!fir.array<?x!fir.char<1,20>>>) {
727 %c7_i64 = arith.constant 7 : i64
728 %c1_i64 = arith.constant 1 : i64
729 %c0 = arith.constant 0 : index
730 %c1 = arith.constant 1 : index
731 %0:3 = fir.box_dims %arg0, %c0 : (!fir.box<!fir.array<?x!fir.char<1,20>>>, index) -> (index, index, index)
732 %1 = fir.slice %c1, %0#1, %c1_i64 substr %c1_i64, %c7_i64 : (index, index, i64, i64, i64) -> !fir.slice<1>
733 // CHECK: fir.rebox %{{.*}} [%{{.*}}] : (!fir.box<!fir.array<?x!fir.char<1,20>>>, !fir.slice<1>) -> !fir.box<!fir.array<?x!fir.char<1,?>>>
734 %2 = fir.rebox %arg0 [%1] : (!fir.box<!fir.array<?x!fir.char<1,20>>>, !fir.slice<1>) -> !fir.box<!fir.array<?x!fir.char<1,?>>>
735 fir.call @bar_rebox_test_char(%2) : (!fir.box<!fir.array<?x!fir.char<1,?>>>) -> ()
740 func.func private @array_func() -> !fir.array<?x!fir.char<1,?>>
741 // CHECK-LABEL: @test_save_result(
742 func.func @test_save_result(%buffer: !fir.ref<!fir.array<?x!fir.char<1,?>>>) {
743 %c100 = arith.constant 100 : index
744 %c50 = arith.constant 50 : index
745 %shape = fir.shape %c100 : (index) -> !fir.shape<1>
746 %res = fir.call @array_func() : () -> !fir.array<?x!fir.char<1,?>>
747 // CHECK: fir.save_result %{{.*}} to %{{.*}}(%{{.*}}) typeparams %{{.*}} : !fir.array<?x!fir.char<1,?>>, !fir.ref<!fir.array<?x!fir.char<1,?>>>, !fir.shape<1>, index
748 fir.save_result %res to %buffer(%shape) typeparams %c50 : !fir.array<?x!fir.char<1,?>>, !fir.ref<!fir.array<?x!fir.char<1,?>>>, !fir.shape<1>, index
752 func.func @char_convert() {
753 %1 = fir.undefined i32
754 %2 = fir.undefined !fir.ref<!fir.char<1>>
755 %3 = fir.undefined !fir.ref<!fir.array<?x!fir.char<2,?>>>
756 // CHECK: fir.char_convert %{{.*}} for %{{.*}} to %{{.*}} : !fir.ref<!fir.char<1>>, i32, !fir.ref<!fir.array<?x!fir.char<2,?>>>
757 fir.char_convert %2 for %1 to %3 : !fir.ref<!fir.char<1>>, i32, !fir.ref<!fir.array<?x!fir.char<2,?>>>
761 func.func @slice_substr() {
762 %lb = arith.constant 0 : index
763 %ub = arith.constant 42 : index
764 %c1 = arith.constant 1 : index
765 %offset = arith.constant 10 : index
766 %0 = fir.slice %lb, %ub, %c1 substr %offset, %c1 : (index, index, index, index, index) -> !fir.slice<1>
767 // CHECK: fir.slice %{{.*}}, %{{.*}}, %{{.*}} substr %{{.*}}, %{{.*}} : (index, index, index, index, index) -> !fir.slice<1>
771 // Test load, store, coordinate_of with llvmptr type
772 // CHECK-LABEL: llvm_ptr_load_store_coordinate
773 // CHECK-SAME: (%[[ARG0:.*]]: !fir.ref<tuple<!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>>>, %[[ARG1:.*]]: !fir.ref<!fir.box<!fir.ptr<f32>>>)
774 func.func @llvm_ptr_load_store_coordinate(%arg0: !fir.ref<tuple<!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>>>, %arg1: !fir.ref<!fir.box<!fir.ptr<f32>>>) -> !fir.ref<!fir.box<!fir.ptr<f32>>> {
775 // CHECK-NEXT: %[[C0:.*]] = arith.constant 0 : i32
776 %c0_i32 = arith.constant 0 : i32
777 // CHECK-NEXT: %[[LLVMPTR:.*]] = fir.coordinate_of %[[ARG0]], %[[C0]] : (!fir.ref<tuple<!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>>>, i32) -> !fir.llvm_ptr<!fir.ref<!fir.box<!fir.ptr<f32>>>>
778 %0 = fir.coordinate_of %arg0, %c0_i32 : (!fir.ref<tuple<!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>>>, i32) -> !fir.llvm_ptr<!fir.ref<!fir.box<!fir.ptr<f32>>>>
779 // CHECK-NEXT: fir.store %[[ARG1]] to %[[LLVMPTR]] : !fir.llvm_ptr<!fir.ref<!fir.box<!fir.ptr<f32>>>>
780 fir.store %arg1 to %0 : !fir.llvm_ptr<!fir.ref<!fir.box<!fir.ptr<f32>>>>
781 // CHECK-NEXT: fir.load %[[LLVMPTR]] : !fir.llvm_ptr<!fir.ref<!fir.box<!fir.ptr<f32>>>>
782 %1 = fir.load %0 : !fir.llvm_ptr<!fir.ref<!fir.box<!fir.ptr<f32>>>>
783 return %1 : !fir.ref<!fir.box<!fir.ptr<f32>>>
786 func.func @array_access_ops(%a : !fir.ref<!fir.array<?x?xf32>>) {
787 %c1 = arith.constant 1 : index
788 %n = arith.constant 0 : index
789 %m = arith.constant 50 : index
790 %s = fir.shape %n, %m : (index, index) -> !fir.shape<2>
791 %v = fir.array_load %a(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32>
792 %p = fir.array_access %v, %c1, %c1 : (!fir.array<?x?xf32>, index, index) -> !fir.ref<f32>
793 // CHECK: %{{.*}} = fir.array_access %{{.*}}, %{{.*}}, %{{.*}} : (!fir.array<?x?xf32>, index, index) -> !fir.ref<f32>
797 func.func @array_amend_ops(%a : !fir.ref<!fir.array<?x?xf32>>) {
798 %c1 = arith.constant 1 : index
799 %n = arith.constant 0 : index
800 %m = arith.constant 50 : index
801 %s = fir.shape %n, %m : (index, index) -> !fir.shape<2>
802 %v = fir.array_load %a(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32>
803 %p = fir.array_access %v, %c1, %c1 : (!fir.array<?x?xf32>, index, index) -> !fir.ref<f32>
804 %res = fir.array_amend %v, %p : (!fir.array<?x?xf32>, !fir.ref<f32>) -> !fir.array<?x?xf32>
805 // CHECK: %{{.*}} = fir.array_amend %{{.*}}, %{{.*}} : (!fir.array<?x?xf32>, !fir.ref<f32>) -> !fir.array<?x?xf32>
809 func.func private @dispatch(%arg0: !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>, %arg1: i32) -> () {
810 // CHECK-LABEL: func.func private @dispatch(
811 // CHECK-SAME: %[[CLASS:.*]]: !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>, %[[INTARG:.*]]: i32)
812 fir.dispatch "proc1"(%arg0 : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) (%arg0 : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32}
813 // CHECK: fir.dispatch "proc1"(%[[CLASS]] : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) (%[[CLASS]] : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32}
815 fir.dispatch "proc2"(%arg0 : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>)
816 // CHECK: fir.dispatch "proc2"(%[[CLASS]] : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>)
818 fir.dispatch "proc3"(%arg0 : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) (%arg1, %arg0 : i32, !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) {pass_arg_pos = 1 : i32}
819 // CHECK: fir.dispatch "proc3"(%[[CLASS]] : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) (%[[INTARG]], %[[CLASS]] : i32, !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) {pass_arg_pos = 1 : i32}
824 // CHECK-LABEL: func.func @embox_tdesc(
825 // CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.array<10x!fir.type<derived_poly{a:i32,b:i32}>>>
826 func.func @embox_tdesc(%arg0: !fir.class<!fir.array<10x!fir.type<derived_poly{a:i32,b:i32}>>>) {
828 %c1_i32 = arith.constant 1 : i32
829 %1 = fir.convert %c1_i32 : (i32) -> index
830 %c10_i32 = arith.constant 10 : i32
831 %2 = fir.convert %c10_i32 : (i32) -> index
832 %c1 = arith.constant 1 : index
833 %3 = fir.convert %1 : (index) -> i32
834 %4:2 = fir.do_loop %arg2 = %1 to %2 step %c1 iter_args(%arg3 = %3) -> (index, i32) {
835 fir.store %arg3 to %0 : !fir.ref<i32>
836 %9 = fir.load %0 : !fir.ref<i32>
837 %10 = fir.convert %9 : (i32) -> i64
838 %c1_i64 = arith.constant 1 : i64
839 %11 = arith.subi %10, %c1_i64 : i64
840 %12 = fir.coordinate_of %arg0, %11 : (!fir.class<!fir.array<10x!fir.type<derived_poly{a:i32,b:i32}>>>, i64) -> !fir.ref<!fir.type<derived_poly{a:i32,b:i32}>>
841 %13 = fir.embox %12 source_box %arg0 : (!fir.ref<!fir.type<derived_poly{a:i32,b:i32}>>, !fir.class<!fir.array<10x!fir.type<derived_poly{a:i32,b:i32}>>>) -> !fir.class<!fir.type<derived_poly{a:i32,b:i32}>>
842 // CHECK: %{{.*}} = fir.embox %{{.*}} source_box %[[ARG0]] : (!fir.ref<!fir.type<derived_poly{a:i32,b:i32}>>, !fir.class<!fir.array<10x!fir.type<derived_poly{a:i32,b:i32}>>>) -> !fir.class<!fir.type<derived_poly{a:i32,b:i32}>>
843 %14 = arith.addi %arg2, %c1 : index
844 %15 = fir.convert %c1 : (index) -> i32
845 %16 = fir.load %0 : !fir.ref<i32>
846 %17 = arith.addi %16, %15 : i32
847 fir.result %14, %17 : index, i32
849 fir.store %4#1 to %0 : !fir.ref<i32>
853 func.func @test_fortran_var_attrs() {
854 %0 = fir.alloca !fir.heap<f32> {fortran_attrs = #fir.var_attrs<allocatable>}
855 %1 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<asynchronous>}
856 %2 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<bind_c>}
857 %3 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<contiguous>}
858 %4 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<intent_in>}
859 %5 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<intent_inout>}
860 %6 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<intent_out>}
861 %7 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<optional>}
862 %8 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<parameter>}
863 %9 = fir.alloca !fir.ptr<f32> {fortran_attrs = #fir.var_attrs<pointer>}
864 %10 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<target>}
865 %11 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<value>}
866 %12 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<volatile>}
867 %13 = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf32>>> {fortran_attrs = #fir.var_attrs<pointer, contiguous, volatile>}
869 // CHECK: fir.alloca !fir.heap<f32> {fortran_attrs = #fir.var_attrs<allocatable>}
870 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<asynchronous>}
871 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<bind_c>}
872 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<contiguous>}
873 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<intent_in>}
874 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<intent_inout>}
875 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<intent_out>}
876 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<optional>}
877 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<parameter>}
878 // CHECK: fir.alloca !fir.ptr<f32> {fortran_attrs = #fir.var_attrs<pointer>}
879 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<target>}
880 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<value>}
881 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<volatile>}
882 // CHECK: fir.alloca !fir.box<!fir.ptr<!fir.array<?xf32>>> {fortran_attrs = #fir.var_attrs<contiguous, pointer, volatile>}
885 func.func @test_box_typecode(%a: !fir.class<none>) {
886 %0 = fir.box_typecode %a : (!fir.class<none>) -> i32
890 // CHECK-LABEL: func.func @test_box_typecode(
891 // CHECK-SAME: %[[A:.*]]: !fir.class<none>)
892 // CHECK: %{{.*}} = fir.box_typecode %[[A]] : (!fir.class<none>) -> i32