• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Test the FIR operations
2
3// RUN: tco -emit-fir %s | tco -emit-fir | FileCheck %s
4// UNSUPPORTED: !fir
5
6// CHECK-LABEL: func private @it1() -> !fir.int<4>
7// CHECK: func private @box1() -> !fir.boxchar<2>
8// CHECK: func private @box2() -> !fir.boxproc<(i32, i32) -> i64>
9// CHECK: func private @box3() -> !fir.box<!fir.type<derived3{f:f32}>>
10func private @it1() -> !fir.int<4>
11func private @box1() -> !fir.boxchar<2>
12func private @box2() -> !fir.boxproc<(i32, i32) -> i64>
13func private @box3() -> !fir.box<!fir.type<derived3{f:f32}>>
14
15// Fortran SUBROUTINE and FUNCTION
16// CHECK-LABEL: func private @print_index3(index, index, index)
17// CHECK: func private @user_i64(i64)
18// CHECK: func private @user_tdesc(!fir.tdesc<!fir.type<x>>)
19func private @print_index3(index, index, index)
20func private @user_i64(i64)
21func private @user_tdesc(!fir.tdesc<!fir.type<x>>)
22
23// expect the void return to be omitted
24// CHECK-LABEL: func private @store_tuple(tuple<!fir.type<qq1{f1:i32}>>)
25// CHECK: func private @get_method_box() -> !fir.box<!fir.type<derived3{f:f32}>>
26// CHECK: func private @method_impl(!fir.box<!fir.type<derived3{f:f32}>>)
27func private @store_tuple(tuple<!fir.type<qq1{f1:i32}>>) -> ()
28func private @get_method_box() -> !fir.box<!fir.type<derived3{f:f32}>>
29func private @method_impl(!fir.box<!fir.type<derived3{f:f32}>>)
30
31// CHECK-LABEL: func private @nop()
32// CHECK-LABEL: func private @get_func() -> (() -> ())
33func private @nop()
34func private @get_func() -> (() -> ())
35
36// CHECK-LABEL:       func @instructions() {
37func @instructions() {
38// CHECK: [[VAL_0:%.*]] = fir.alloca !fir.array<10xi32>
39// CHECK: [[VAL_1:%.*]] = fir.load [[VAL_0]] : !fir.ref<!fir.array<10xi32>>
40// CHECK: [[VAL_2:%.*]] = fir.alloca i32
41// CHECK: [[VAL_3:%.*]] = constant 22 : i32
42  %0 = fir.alloca !fir.array<10xi32>
43  %1 = fir.load %0 : !fir.ref<!fir.array<10xi32>>
44  %2 = fir.alloca i32
45  %3 = constant 22 : i32
46
47// CHECK: fir.store [[VAL_3]] to [[VAL_2]] : !fir.ref<i32>
48// CHECK: [[VAL_4:%.*]] = fir.undefined i32
49// CHECK: [[VAL_5:%.*]] = fir.allocmem !fir.array<100xf32>
50// CHECK: [[VAL_6:%.*]] = fir.embox [[VAL_5]] : (!fir.heap<!fir.array<100xf32>>) -> !fir.box<!fir.array<100xf32>>
51  fir.store %3 to %2 : !fir.ref<i32>
52  %4 = fir.undefined i32
53  %5 = fir.allocmem !fir.array<100xf32>
54  %6 = fir.embox %5 : (!fir.heap<!fir.array<100xf32>>) -> !fir.box<!fir.array<100xf32>>
55
56// CHECK: [[VAL_7:%.*]] = fir.box_addr [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> !fir.ref<!fir.array<100xf32>>
57// CHECK: [[VAL_8:%.*]] = constant 0 : index
58// CHECK: [[VAL_9:%.*]]:3 = fir.box_dims [[VAL_6]], [[VAL_8]] : (!fir.box<!fir.array<100xf32>>, index) -> (index, index, index)
59// CHECK: fir.call @print_index3([[VAL_9]]#0, [[VAL_9]]#1, [[VAL_9]]#2) : (index, index, index) -> ()
60// CHECK: [[VAL_10:%.*]] = fir.call @it1() : () -> !fir.int<4>
61  %7 = fir.box_addr %6 : (!fir.box<!fir.array<100xf32>>) -> !fir.ref<!fir.array<100xf32>>
62  %c0 = constant 0 : index
63  %d1:3 = fir.box_dims %6, %c0 : (!fir.box<!fir.array<100xf32>>, index) -> (index, index, index)
64  fir.call @print_index3(%d1#0, %d1#1, %d1#2) : (index, index, index) -> ()
65  %8 = fir.call @it1() : () -> !fir.int<4>
66
67// CHECK: [[VAL_11:%.*]] = fir.box_elesize [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> i64
68// CHECK: [[VAL_12:%.*]] = fir.box_isalloc [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> i1
69// CHECK: [[VAL_13:%.*]] = fir.box_isarray [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> i1
70// CHECK: [[VAL_14:%.*]] = fir.box_isptr [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> i1
71// CHECK: [[VAL_15:%.*]] = fir.box_rank [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> i64
72  %9 = fir.box_elesize %6 : (!fir.box<!fir.array<100xf32>>) -> i64
73  %10 = fir.box_isalloc %6 : (!fir.box<!fir.array<100xf32>>) -> i1
74  %11 = fir.box_isarray %6 : (!fir.box<!fir.array<100xf32>>) -> i1
75  %12 = fir.box_isptr %6 : (!fir.box<!fir.array<100xf32>>) -> i1
76  %13 = fir.box_rank %6 : (!fir.box<!fir.array<100xf32>>) -> i64
77
78// CHECK: [[VAL_16:%.*]] = fir.box_tdesc [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> !fir.tdesc<!fir.array<100xf32>>
79// CHECK: [[VAL_17:%.*]] = fir.call @box1() : () -> !fir.boxchar<2>
80// CHECK: [[VAL_18:%.*]] = fir.boxchar_len [[VAL_17]] : (!fir.boxchar<2>) -> i32
81// CHECK: [[VAL_19:%.*]] = fir.call @box2() : () -> !fir.boxproc<(i32, i32) -> i64>
82// CHECK: [[VAL_20:%.*]] = fir.boxproc_host [[VAL_19]] : (!fir.boxproc<(i32, i32) -> i64>) -> !fir.ref<i32>
83  %14 = fir.box_tdesc %6 : (!fir.box<!fir.array<100xf32>>) -> !fir.tdesc<!fir.array<100xf32>>
84  %15 = fir.call @box1() : () -> !fir.boxchar<2>
85  %16 = fir.boxchar_len %15 : (!fir.boxchar<2>) -> i32
86  %17 = fir.call @box2() : () -> !fir.boxproc<(i32, i32) -> i64>
87  %18 = fir.boxproc_host %17 : (!fir.boxproc<(i32, i32) -> i64>) -> !fir.ref<i32>
88
89// CHECK: [[VAL_21:%.*]] = constant 10 : i32
90// CHECK: [[VAL_22:%.*]] = fir.coordinate_of [[VAL_5]], [[VAL_21]] : (!fir.heap<!fir.array<100xf32>>, i32) -> !fir.ref<f32>
91// CHECK: [[VAL_23:%.*]] = fir.field_index f, !fir.type<derived{f:f32}>
92// CHECK: [[VAL_24:%.*]] = fir.undefined !fir.type<derived{f:f32}>
93// CHECK: [[VAL_25:%.*]] = fir.extract_value [[VAL_24]], [[VAL_23]] : (!fir.type<derived{f:f32}>, !fir.field) -> f32
94  %19 = constant 10 : i32
95  %20 = fir.coordinate_of %5, %19 : (!fir.heap<!fir.array<100xf32>>, i32) -> !fir.ref<f32>
96  %21 = fir.field_index f, !fir.type<derived{f:f32}>
97  %22 = fir.undefined !fir.type<derived{f:f32}>
98  %23 = fir.extract_value %22, %21 : (!fir.type<derived{f:f32}>, !fir.field) -> f32
99
100// CHECK: [[VAL_26:%.*]] = constant 1 : i32
101// CHECK: [[VAL_27:%.*]] = fir.gendims [[VAL_26]], [[VAL_21]], [[VAL_26]] : (i32, i32, i32) -> !fir.dims<1>
102// CHECK: [[VAL_28:%.*]] = constant 1.0
103// CHECK: [[VAL_29:%.*]] = fir.insert_value [[VAL_24]], [[VAL_28]], [[VAL_23]] : (!fir.type<derived{f:f32}>, f32, !fir.field) -> !fir.type<derived{f:f32}>
104// CHECK: [[VAL_30:%.*]] = fir.len_param_index f, !fir.type<derived3{f:f32}>
105  %c1 = constant 1 : i32
106  %24 = fir.gendims %c1, %19, %c1 : (i32, i32, i32) -> !fir.dims<1>
107  %cf1 = constant 1.0 : f32
108  %25 = fir.insert_value %22, %cf1, %21 : (!fir.type<derived{f:f32}>, f32, !fir.field) -> !fir.type<derived{f:f32}>
109  %26 = fir.len_param_index f, !fir.type<derived3{f:f32}>
110
111// CHECK: [[VAL_31:%.*]] = fir.call @box3() : () -> !fir.box<!fir.type<derived3{f:f32}>>
112// CHECK: [[VAL_32:%.*]] = fir.dispatch "method"([[VAL_31]]) : (!fir.box<!fir.type<derived3{f:f32}>>) -> i32
113// CHECK: [[VAL_33:%.*]] = fir.convert [[VAL_32]] : (i32) -> i64
114// CHECK: [[VAL_34:%.*]] = fir.gentypedesc !fir.type<x>
115// CHECK: fir.call @user_tdesc([[VAL_34]]) : (!fir.tdesc<!fir.type<x>>) -> ()
116// CHECK: [[VAL_35:%.*]] = fir.no_reassoc [[VAL_33]] : i64
117  %27 = fir.call @box3() : () -> !fir.box<!fir.type<derived3{f:f32}>>
118  %28 = fir.dispatch "method"(%27) : (!fir.box<!fir.type<derived3{f:f32}>>) -> i32
119  %29 = fir.convert %28 : (i32) -> i64
120  %30 = fir.gentypedesc !fir.type<x>
121  fir.call @user_tdesc(%30) : (!fir.tdesc<!fir.type<x>>) -> ()
122  %31 = fir.no_reassoc %29 : i64
123
124// CHECK: fir.call @user_i64([[VAL_35]]) : (i64) -> ()
125// CHECK: fir.freemem [[VAL_5]] : !fir.heap<!fir.array<100xf32>>
126// CHECK: [[VAL_36:%.*]] = fir.call @get_func() : () -> (() -> ())
127// CHECK: fir.call [[VAL_36]]() : () -> ()
128// CHECK: [[VAL_37:%.*]] = fir.address_of(@it1) : !fir.ref<() -> !fir.int<4>>
129// CHECK: return
130// CHECK: }
131  fir.call @user_i64(%31) : (i64) -> ()
132  fir.freemem %5 : !fir.heap<!fir.array<100xf32>>
133  %32 = fir.call @get_func() : () -> (() -> ())
134  fir.call %32() : () -> ()
135  %33 = fir.address_of (@it1) : !fir.ref<() -> !fir.int<4>>
136  return
137}
138
139// CHECK-LABEL: func @boxing_match() {
140func @boxing_match() {
141// CHECK: [[VAL_38:%.*]] = fir.alloca i32
142// CHECK: [[VAL_39:%.*]] = fir.alloca !fir.type<qq2{f1:i32,f2:f64}>
143// CHECK: [[VAL_40:%.*]] = fir.alloca !fir.char<1>
144// CHECK: [[VAL_41:%.*]] = fir.alloca tuple<i32, f64>
145// CHECK: [[VAL_42:%.*]] = fir.embox [[VAL_38]] : (!fir.ref<i32>) -> !fir.box<i32>
146// CHECK: [[VAL_43:%.*]]:6 = fir.unbox [[VAL_42]] : (!fir.box<i32>) -> (!fir.ref<i32>, i32, i32, !fir.tdesc<i32>, i32, !fir.dims<0>)
147// CHECK: [[VAL_44:%.*]] = constant 8 : i32
148// CHECK: [[VAL_45:%.*]] = fir.undefined !fir.char<1>
149// CHECK: [[VAL_46:%.*]] = fir.emboxchar [[VAL_40]], [[VAL_44]] : (!fir.ref<!fir.char<1>>, i32) -> !fir.boxchar<1>
150// CHECK: [[VAL_47:%.*]]:2 = fir.unboxchar [[VAL_46]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1>>, i32)
151// CHECK: [[VAL_48:%.*]] = fir.undefined !fir.type<qq2{f1:i32,f2:f64}>
152// CHECK: [[VAL_49:%.*]] = constant 0 : i32
153// CHECK: [[VAL_50:%.*]] = constant 12 : i32
154// CHECK: [[VAL_51:%.*]] = fir.insert_value [[VAL_48]], [[VAL_50]], [[VAL_49]] : (!fir.type<qq2{f1:i32,f2:f64}>, i32, i32) -> !fir.type<qq2{f1:i32,f2:f64}>
155// CHECK: [[VAL_52:%.*]] = constant 1 : i32
156// CHECK: [[VAL_53:%.*]] = constant 4.213000e+01 : f64
157// CHECK: [[VAL_54:%.*]] = fir.insert_value [[VAL_48]], [[VAL_53]], [[VAL_52]] : (!fir.type<qq2{f1:i32,f2:f64}>, f64, i32) -> !fir.type<qq2{f1:i32,f2:f64}>
158// CHECK: fir.store [[VAL_54]] to [[VAL_39]] : !fir.ref<!fir.type<qq2{f1:i32,f2:f64}>>
159// CHECK: [[VAL_55:%.*]] = fir.emboxproc @method_impl, [[VAL_41]] : ((!fir.box<!fir.type<derived3{f:f32}>>) -> (), !fir.ref<tuple<i32, f64>>) -> !fir.boxproc<(!fir.box<!fir.type<derived3{f:f32}>>) -> ()>
160// 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}>>>)
161// CHECK: [[VAL_58:%.*]] = fir.call @box2() : () -> !fir.boxproc<(i32, i32) -> i64>
162// 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}>>>)
163// CHECK: [[VAL_61:%.*]] = fir.load [[VAL_60]] : !fir.ref<tuple<!fir.type<qq1{f1:i32}>>>
164// CHECK: fir.call @store_tuple([[VAL_61]]) : (tuple<!fir.type<qq1{f1:i32}>>) -> ()
165// CHECK: return
166// CHECK: }
167  %0 = fir.alloca i32
168  %d6 = fir.alloca !fir.type<qq2{f1:i32,f2:f64}>
169  %d3 = fir.alloca !fir.char<1>
170  %e6 = fir.alloca tuple<i32,f64>
171  %1 = fir.embox %0 : (!fir.ref<i32>) -> !fir.box<i32>
172  %2:6 = fir.unbox %1 : (!fir.box<i32>) -> (!fir.ref<i32>,i32,i32,!fir.tdesc<i32>,i32,!fir.dims<0>)
173  %c8 = constant 8 : i32
174  %3 = fir.undefined !fir.char<1>
175  %4 = fir.emboxchar %d3, %c8 : (!fir.ref<!fir.char<1>>, i32) -> !fir.boxchar<1>
176  %5:2 = fir.unboxchar %4 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1>>, i32)
177  %6 = fir.undefined !fir.type<qq2{f1:i32,f2:f64}>
178  %z = constant 0 : i32
179  %c12 = constant 12 : i32
180  %a2 = fir.insert_value %6, %c12, %z : (!fir.type<qq2{f1:i32,f2:f64}>, i32, i32) -> !fir.type<qq2{f1:i32,f2:f64}>
181  %z1 = constant 1 : i32
182  %c42 = constant 42.13 : f64
183  %a3 = fir.insert_value %6, %c42, %z1 : (!fir.type<qq2{f1:i32,f2:f64}>, f64, i32) -> !fir.type<qq2{f1:i32,f2:f64}>
184  fir.store %a3 to %d6 : !fir.ref<!fir.type<qq2{f1:i32,f2:f64}>>
185  %7 = fir.emboxproc @method_impl, %e6 : ((!fir.box<!fir.type<derived3{f:f32}>>) -> (), !fir.ref<tuple<i32,f64>>) -> !fir.boxproc<(!fir.box<!fir.type<derived3{f:f32}>>) -> ()>
186  %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}>>>)
187  %9 = fir.call @box2() : () -> !fir.boxproc<(i32, i32) -> i64>
188  %10:2 = fir.unboxproc %9 : (!fir.boxproc<(i32, i32) -> i64>) -> ((i32, i32) -> i64, !fir.ref<tuple<!fir.type<qq1{f1:i32}>>>)
189  %11 = fir.load %10#1 : !fir.ref<tuple<!fir.type<qq1{f1:i32}>>>
190  fir.call @store_tuple(%11) : (tuple<!fir.type<qq1{f1:i32}>>) -> ()
191  return
192}
193
194// CHECK-LABEL: func @loop() {
195func @loop() {
196// CHECK: [[VAL_62:%.*]] = constant 1 : index
197// CHECK: [[VAL_63:%.*]] = constant 10 : index
198// CHECK: [[VAL_64:%.*]] = constant true
199  %c1 = constant 1 : index
200  %c10 = constant 10 : index
201  %ct = constant true
202
203// CHECK: fir.do_loop [[VAL_65:%.*]] = [[VAL_62]] to [[VAL_63]] step [[VAL_62]] {
204// CHECK: fir.if [[VAL_64]] {
205// CHECK: fir.call @nop() : () -> ()
206// CHECK: } else {
207// CHECK: fir.call @nop() : () -> ()
208// CHECK: }
209// CHECK: }
210// CHECK: fir.unreachable
211// CHECK: }
212  fir.do_loop %i = %c1 to %c10 step %c1 {
213    fir.if %ct {
214      fir.call @nop() : () -> ()
215    } else {
216      fir.call @nop() : () -> ()
217    }
218  }
219  fir.unreachable
220}
221
222// CHECK: func @bar_select([[VAL_66:%.*]]: i32, [[VAL_67:%.*]]: i32) -> i32 {
223func @bar_select(%arg : i32, %arg2 : i32) -> i32 {
224// CHECK: [[VAL_68:%.*]] = constant 1 : i32
225// CHECK: [[VAL_69:%.*]] = constant 2 : i32
226// CHECK: [[VAL_70:%.*]] = constant 3 : i32
227// CHECK: [[VAL_71:%.*]] = constant 4 : i32
228  %0 = constant 1 : i32
229  %1 = constant 2 : i32
230  %2 = constant 3 : i32
231  %3 = constant 4 : i32
232
233// 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]
234// CHECK: ^bb1([[VAL_72:%.*]]: i32):
235// CHECK: return [[VAL_72]] : i32
236// CHECK: ^bb2([[VAL_73:%.*]]: i32, [[VAL_74:%.*]]: i32, [[VAL_75:%.*]]: i32):
237// CHECK: [[VAL_76:%.*]] = addi [[VAL_73]], [[VAL_74]] : i32
238// CHECK: [[VAL_77:%.*]] = addi [[VAL_76]], [[VAL_75]] : i32
239// CHECK: return [[VAL_77]] : i32
240// CHECK: ^bb3([[VAL_78:%.*]]: i32, [[VAL_79:%.*]]: i32):
241// CHECK: [[VAL_80:%.*]] = addi [[VAL_78]], [[VAL_79]] : i32
242// CHECK: return [[VAL_80]] : i32
243// CHECK: ^bb4([[VAL_81:%.*]]: i32):
244// CHECK: return [[VAL_81]] : i32
245// CHECK: ^bb5:
246// CHECK: [[VAL_82:%.*]] = constant 0 : i32
247// CHECK: return [[VAL_82]] : i32
248// CHECK: }
249  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 ]
250^bb1(%a : i32) :
251  return %a : i32
252^bb2(%b : i32, %b2 : i32, %b3:i32) :
253  %4 = addi %b, %b2 : i32
254  %5 = addi %4, %b3 : i32
255  return %5 : i32
256^bb3(%c:i32, %c2:i32) :
257  %6 = addi %c, %c2 : i32
258  return %6 : i32
259^bb4(%d : i32) :
260  return %d : i32
261^bb5 :
262  %zero = constant 0 : i32
263  return %zero : i32
264}
265
266// CHECK-LABEL: func @bar_select_rank(
267// CHECK-SAME: [[VAL_83:%.*]]: i32, [[VAL_84:%.*]]: i32) -> i32 {
268func @bar_select_rank(%arg : i32, %arg2 : i32) -> i32 {
269// CHECK: [[VAL_85:%.*]] = constant 1 : i32
270// CHECK: [[VAL_86:%.*]] = constant 2 : i32
271// CHECK: [[VAL_87:%.*]] = constant 3 : i32
272// CHECK: [[VAL_88:%.*]] = constant 4 : i32
273  %0 = constant 1 : i32
274  %1 = constant 2 : i32
275  %2 = constant 3 : i32
276  %3 = constant 4 : i32
277
278// 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]
279// CHECK: ^bb1([[VAL_89:%.*]]: i32):
280// CHECK: return [[VAL_89]] : i32
281// CHECK: ^bb2([[VAL_90:%.*]]: i32, [[VAL_91:%.*]]: i32, [[VAL_92:%.*]]: i32):
282// CHECK: [[VAL_93:%.*]] = addi [[VAL_90]], [[VAL_91]] : i32
283// CHECK: [[VAL_94:%.*]] = addi [[VAL_93]], [[VAL_92]] : i32
284// CHECK: return [[VAL_94]] : i32
285  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 ]
286^bb1(%a : i32) :
287  return %a : i32
288^bb2(%b : i32, %b2 : i32, %b3:i32) :
289  %4 = addi %b, %b2 : i32
290  %5 = addi %4, %b3 : i32
291  return %5 : i32
292
293// CHECK: ^bb3([[VAL_95:%.*]]: i32, [[VAL_96:%.*]]: i32):
294// CHECK: [[VAL_97:%.*]] = addi [[VAL_95]], [[VAL_96]] : i32
295// CHECK: return [[VAL_97]] : i32
296// CHECK: ^bb4([[VAL_98:%.*]]: i32):
297// CHECK: return [[VAL_98]] : i32
298^bb3(%c:i32, %c2:i32) :
299  %6 = addi %c, %c2 : i32
300  return %6 : i32
301^bb4(%d : i32) :
302  return %d : i32
303
304// CHECK: ^bb5:
305// CHECK: [[VAL_99:%.*]] = constant 0 : i32
306// CHECK: [[VAL_100:%.*]] = fir.call @get_method_box() : () -> !fir.box<!fir.type<derived3{f:f32}>>
307// CHECK: fir.dispatch "method"([[VAL_100]]) : (!fir.box<!fir.type<derived3{f:f32}>>) -> ()
308^bb5 :
309  %zero = constant 0 : i32
310  %7 = fir.call @get_method_box() : () -> !fir.box<!fir.type<derived3{f:f32}>>
311  fir.dispatch method(%7) : (!fir.box<!fir.type<derived3{f:f32}>>) -> ()
312
313// CHECK: return [[VAL_99]] : i32
314// CHECK: }
315  return %zero : i32
316}
317
318// CHECK-LABEL: func @bar_select_type(
319// CHECK-SAME: [[VAL_101:%.*]]: !fir.box<!fir.type<name(param1:i32){fld:!fir.char<1>}>>) -> i32 {
320func @bar_select_type(%arg : !fir.box<!fir.type<name(param1:i32){fld:!fir.char<1>}>>) -> i32 {
321
322// CHECK: [[VAL_102:%.*]] = constant 1 : i32
323// CHECK: [[VAL_103:%.*]] = constant 2 : i32
324// CHECK: [[VAL_104:%.*]] = constant 3 : i32
325// CHECK: [[VAL_105:%.*]] = constant 4 : i32
326  %0 = constant 1 : i32
327  %1 = constant 2 : i32
328  %2 = constant 3 : i32
329  %3 = constant 4 : i32
330
331// CHECK: fir.select_type [[VAL_101]] : !fir.box<!fir.type<name(param1:i32){fld:!fir.char<1>}>> [#fir.instance<!fir.int<4>>, ^bb1([[VAL_102]] : i32), #fir.instance<!fir.int<8>>, ^bb2([[VAL_104]] : i32), #fir.subsumed<!fir.int<2>>, ^bb3([[VAL_104]] : i32), #fir.instance<!fir.int<1>>, ^bb4([[VAL_103]] : i32), unit, ^bb5]
332  fir.select_type %arg : !fir.box<!fir.type<name(param1:i32){fld:!fir.char<1>}>> [ #fir.instance<!fir.int<4>>,^bb1(%0:i32), #fir.instance<!fir.int<8>>,^bb2(%2:i32), #fir.subsumed<!fir.int<2>>,^bb3(%2:i32), #fir.instance<!fir.int<1>>,^bb4(%1:i32), unit,^bb5 ]
333
334// CHECK: ^bb1([[VAL_106:%.*]]: i32):
335// CHECK: return [[VAL_106]] : i32
336// CHECK: ^bb2([[VAL_107:%.*]]: i32):
337// CHECK: return [[VAL_107]] : i32
338// CHECK: ^bb3([[VAL_108:%.*]]: i32):
339// CHECK: return [[VAL_108]] : i32
340// CHECK: ^bb4([[VAL_109:%.*]]: i32):
341// CHECK: return [[VAL_109]] : i32
342^bb1(%a : i32) :
343  return %a : i32
344^bb2(%b : i32) :
345  return %b : i32
346^bb3(%c : i32) :
347  return %c : i32
348^bb4(%d : i32) :
349  return %d : i32
350
351// CHECK: ^bb5:
352// CHECK: [[VAL_110:%.*]] = constant 0 : i32
353// CHECK: return [[VAL_110]] : i32
354// CHECK: }
355^bb5 :
356  %zero = constant 0 : i32
357  return %zero : i32
358}
359
360// CHECK-LABEL: func @bar_select_case(
361// CHECK-SAME: [[VAL_111:%.*]]: i32, [[VAL_112:%.*]]: i32) -> i32 {
362// CHECK: [[VAL_113:%.*]] = constant 1 : i32
363// CHECK: [[VAL_114:%.*]] = constant 2 : i32
364// CHECK: [[VAL_115:%.*]] = constant 3 : i32
365// CHECK: [[VAL_116:%.*]] = constant 4 : i32
366func @bar_select_case(%arg : i32, %arg2 : i32) -> i32 {
367  %0 = constant 1 : i32
368  %1 = constant 2 : i32
369  %2 = constant 3 : i32
370  %3 = constant 4 : i32
371
372// 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]
373  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]
374
375// CHECK: ^bb1([[VAL_117:%.*]]: i32):
376// CHECK: return [[VAL_117]] : i32
377// CHECK: ^bb2([[VAL_118:%.*]]: i32, [[VAL_119:%.*]]: i32, [[VAL_120:%.*]]: i32, [[VAL_121:%.*]]: i32):
378// CHECK: [[VAL_122:%.*]] = addi [[VAL_118]], [[VAL_119]] : i32
379// CHECK: [[VAL_123:%.*]] = muli [[VAL_122]], [[VAL_120]] : i32
380// CHECK: [[VAL_124:%.*]] = addi [[VAL_123]], [[VAL_121]] : i32
381// CHECK: return [[VAL_124]] : i32
382// CHECK: ^bb3([[VAL_125:%.*]]: i32, [[VAL_126:%.*]]: i32):
383// CHECK: [[VAL_127:%.*]] = addi [[VAL_125]], [[VAL_126]] : i32
384// CHECK: return [[VAL_127]] : i32
385// CHECK: ^bb4([[VAL_128:%.*]]: i32):
386// CHECK: return [[VAL_128]] : i32
387^bb1(%a : i32) :
388  return %a : i32
389^bb2(%b : i32, %b2:i32, %b3:i32, %b4:i32) :
390  %4 = addi %b, %b2 : i32
391  %5 = muli %4, %b3 : i32
392  %6 = addi %5, %b4 : i32
393  return %6 : i32
394^bb3(%c : i32, %c2 : i32) :
395  %7 = addi %c, %c2 : i32
396  return %7 : i32
397^bb4(%d : i32) :
398  return %d : i32
399
400// CHECK: ^bb5:
401// CHECK: [[VAL_129:%.*]] = constant 0 : i32
402// CHECK: return [[VAL_129]] : i32
403// CHECK: }
404^bb5 :
405  %zero = constant 0 : i32
406  return %zero : i32
407}
408
409// CHECK-LABEL: fir.global @global_var : i32 {
410// CHECK: [[VAL_130:%.*]] = constant 1 : i32
411// CHECK: fir.has_value [[VAL_130]] : i32
412// CHECK: }
413fir.global @global_var : i32 {
414  %0 = constant 1 : i32
415  fir.has_value %0 : i32
416}
417
418// CHECK-LABEL: fir.global @global_constant constant : i32 {
419// CHECK: [[VAL_131:%.*]] = constant 934 : i32
420// CHECK: fir.has_value [[VAL_131]] : i32
421// CHECK: }
422fir.global @global_constant constant : i32 {
423  %0 = constant 934 : i32
424  fir.has_value %0 : i32
425}
426
427// CHECK-LABEL: fir.global @global_derived : !fir.type<minez(f:i32)> {
428// CHECK: fir.global_len "f", 1 : i32
429// CHECK: [[VAL_132:%.*]] = fir.undefined !fir.type<minez(f:i32)>
430// CHECK: fir.has_value [[VAL_132]] : !fir.type<minez(f:i32)>
431// CHECK: }
432fir.global @global_derived : !fir.type<minez(f:i32)> {
433  fir.global_len f, 1 : i32
434  %0 = fir.undefined !fir.type<minez>
435  fir.has_value %0 : !fir.type<minez>
436}
437
438// CHECK-LABEL: fir.dispatch_table @dispatch_tbl {
439// CHECK: fir.dt_entry "method", @method_impl
440// CHECK: }
441fir.dispatch_table @dispatch_tbl {
442  fir.dt_entry "method", @method_impl
443}
444
445// CHECK-LABEL: func @compare_real(
446// CHECK-SAME: [[VAL_133:%.*]]: !fir.real<16>, [[VAL_134:%.*]]: !fir.real<16>) {
447func @compare_real(%a : !fir.real<16>, %b : !fir.real<16>) {
448
449// CHECK: [[VAL_135:%.*]] = fir.cmpf "false", [[VAL_133]], [[VAL_134]] : !fir.real<16>
450// CHECK: [[VAL_136:%.*]] = fir.cmpf "oeq", [[VAL_133]], [[VAL_134]] : !fir.real<16>
451// CHECK: [[VAL_137:%.*]] = fir.cmpf "ogt", [[VAL_133]], [[VAL_134]] : !fir.real<16>
452// CHECK: [[VAL_138:%.*]] = fir.cmpf "oge", [[VAL_133]], [[VAL_134]] : !fir.real<16>
453  %d0 = fir.cmpf "false", %a, %b : !fir.real<16>
454  %d1 = fir.cmpf "oeq", %a, %b : !fir.real<16>
455  %d2 = fir.cmpf "ogt", %a, %b : !fir.real<16>
456  %d3 = fir.cmpf "oge", %a, %b : !fir.real<16>
457
458// CHECK: [[VAL_139:%.*]] = fir.cmpf "olt", [[VAL_133]], [[VAL_134]] : !fir.real<16>
459// CHECK: [[VAL_140:%.*]] = fir.cmpf "ole", [[VAL_133]], [[VAL_134]] : !fir.real<16>
460// CHECK: [[VAL_141:%.*]] = fir.cmpf "one", [[VAL_133]], [[VAL_134]] : !fir.real<16>
461// CHECK: [[VAL_142:%.*]] = fir.cmpf "ord", [[VAL_133]], [[VAL_134]] : !fir.real<16>
462  %a0 = fir.cmpf "olt", %a, %b : !fir.real<16>
463  %a1 = fir.cmpf "ole", %a, %b : !fir.real<16>
464  %a2 = fir.cmpf "one", %a, %b : !fir.real<16>
465  %a3 = fir.cmpf "ord", %a, %b : !fir.real<16>
466
467// CHECK: [[VAL_143:%.*]] = fir.cmpf "ueq", [[VAL_133]], [[VAL_134]] : !fir.real<16>
468// CHECK: [[VAL_144:%.*]] = fir.cmpf "ugt", [[VAL_133]], [[VAL_134]] : !fir.real<16>
469// CHECK: [[VAL_145:%.*]] = fir.cmpf "uge", [[VAL_133]], [[VAL_134]] : !fir.real<16>
470// CHECK: [[VAL_146:%.*]] = fir.cmpf "ult", [[VAL_133]], [[VAL_134]] : !fir.real<16>
471  %b0 = fir.cmpf "ueq", %a, %b : !fir.real<16>
472  %b1 = fir.cmpf "ugt", %a, %b : !fir.real<16>
473  %b2 = fir.cmpf "uge", %a, %b : !fir.real<16>
474  %b3 = fir.cmpf "ult", %a, %b : !fir.real<16>
475
476// CHECK: [[VAL_147:%.*]] = fir.cmpf "ule", [[VAL_133]], [[VAL_134]] : !fir.real<16>
477// CHECK: [[VAL_148:%.*]] = fir.cmpf "une", [[VAL_133]], [[VAL_134]] : !fir.real<16>
478// CHECK: [[VAL_149:%.*]] = fir.cmpf "uno", [[VAL_133]], [[VAL_134]] : !fir.real<16>
479// CHECK: [[VAL_150:%.*]] = fir.cmpf "true", [[VAL_133]], [[VAL_134]] : !fir.real<16>
480  %c0 = fir.cmpf "ule", %a, %b : !fir.real<16>
481  %c1 = fir.cmpf "une", %a, %b : !fir.real<16>
482  %c2 = fir.cmpf "uno", %a, %b : !fir.real<16>
483  %c3 = fir.cmpf "true", %a, %b : !fir.real<16>
484
485// CHECK: return
486// CHECK: }
487  return
488}
489
490// CHECK-LABEL: func @compare_complex(
491// CHECK-SAME: [[VAL_151:%.*]]: !fir.complex<16>, [[VAL_152:%.*]]: !fir.complex<16>) {
492func @compare_complex(%a : !fir.complex<16>, %b : !fir.complex<16>) {
493
494// CHECK: [[VAL_153:%.*]] = fir.cmpc "false", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
495// CHECK: [[VAL_154:%.*]] = fir.cmpc "oeq", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
496// CHECK: [[VAL_155:%.*]] = fir.cmpc "ogt", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
497// CHECK: [[VAL_156:%.*]] = fir.cmpc "oge", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
498  %d0 = fir.cmpc "false", %a, %b : !fir.complex<16>
499  %d1 = fir.cmpc "oeq", %a, %b : !fir.complex<16>
500  %d2 = fir.cmpc "ogt", %a, %b : !fir.complex<16>
501  %d3 = fir.cmpc "oge", %a, %b : !fir.complex<16>
502
503// CHECK: [[VAL_157:%.*]] = fir.cmpc "olt", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
504// CHECK: [[VAL_158:%.*]] = fir.cmpc "ole", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
505// CHECK: [[VAL_159:%.*]] = fir.cmpc "one", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
506// CHECK: [[VAL_160:%.*]] = fir.cmpc "ord", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
507  %a0 = fir.cmpc "olt", %a, %b : !fir.complex<16>
508  %a1 = fir.cmpc "ole", %a, %b : !fir.complex<16>
509  %a2 = fir.cmpc "one", %a, %b : !fir.complex<16>
510  %a3 = fir.cmpc "ord", %a, %b : !fir.complex<16>
511
512// CHECK: [[VAL_161:%.*]] = fir.cmpc "ueq", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
513// CHECK: [[VAL_162:%.*]] = fir.cmpc "ugt", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
514// CHECK: [[VAL_163:%.*]] = fir.cmpc "uge", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
515// CHECK: [[VAL_164:%.*]] = fir.cmpc "ult", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
516  %b0 = fir.cmpc "ueq", %a, %b : !fir.complex<16>
517  %b1 = fir.cmpc "ugt", %a, %b : !fir.complex<16>
518  %b2 = fir.cmpc "uge", %a, %b : !fir.complex<16>
519  %b3 = fir.cmpc "ult", %a, %b : !fir.complex<16>
520
521// CHECK: [[VAL_165:%.*]] = fir.cmpc "ule", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
522// CHECK: [[VAL_166:%.*]] = fir.cmpc "une", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
523// CHECK: [[VAL_167:%.*]] = fir.cmpc "uno", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
524// CHECK: [[VAL_168:%.*]] = fir.cmpc "true", [[VAL_151]], [[VAL_152]] : !fir.complex<16>
525  %c0 = fir.cmpc "ule", %a, %b : !fir.complex<16>
526  %c1 = fir.cmpc "une", %a, %b : !fir.complex<16>
527  %c2 = fir.cmpc "uno", %a, %b : !fir.complex<16>
528  %c3 = fir.cmpc "true", %a, %b : !fir.complex<16>
529// CHECK: return
530// CHECK: }
531  return
532}
533
534// CHECK-LABEL: func @arith_real(
535// CHECK-SAME: [[VAL_169:%.*]]: !fir.real<16>, [[VAL_170:%.*]]: !fir.real<16>) -> !fir.real<16> {
536func @arith_real(%a : !fir.real<16>, %b : !fir.real<16>) -> !fir.real<16> {
537
538// CHECK: [[VAL_171:%.*]] = constant 1.0
539// CHECK: [[VAL_172:%.*]] = fir.convert [[VAL_171]] : (f32) -> !fir.real<16>
540// CHECK: [[VAL_173:%.*]] = fir.negf [[VAL_169]] : !fir.real<16>
541// CHECK: [[VAL_174:%.*]] = fir.addf [[VAL_172]], [[VAL_173]] : !fir.real<16>
542// CHECK: [[VAL_175:%.*]] = fir.subf [[VAL_174]], [[VAL_170]] : !fir.real<16>
543// CHECK: [[VAL_176:%.*]] = fir.mulf [[VAL_173]], [[VAL_175]] : !fir.real<16>
544// CHECK: [[VAL_177:%.*]] = fir.divf [[VAL_176]], [[VAL_169]] : !fir.real<16>
545  %c1 = constant 1.0 : f32
546  %0 = fir.convert %c1 : (f32) -> !fir.real<16>
547  %1 = fir.negf %a : !fir.real<16>
548  %2 = fir.addf %0, %1 : !fir.real<16>
549  %3 = fir.subf %2, %b : !fir.real<16>
550  %4 = fir.mulf %1, %3 : !fir.real<16>
551  %5 = fir.divf %4, %a : !fir.real<16>
552// CHECK: return [[VAL_177]] : !fir.real<16>
553// CHECK: }
554  return %5 : !fir.real<16>
555}
556
557// CHECK-LABEL: func @arith_complex(
558// CHECK-SAME: [[VAL_178:%.*]]: !fir.complex<16>, [[VAL_179:%.*]]: !fir.complex<16>) -> !fir.complex<16> {
559func @arith_complex(%a : !fir.complex<16>, %b : !fir.complex<16>) -> !fir.complex<16> {
560// CHECK: [[VAL_180:%.*]] = fir.negc [[VAL_178]] : !fir.complex<16>
561// CHECK: [[VAL_181:%.*]] = fir.addc [[VAL_179]], [[VAL_180]] : !fir.complex<16>
562// CHECK: [[VAL_182:%.*]] = fir.subc [[VAL_181]], [[VAL_179]] : !fir.complex<16>
563// CHECK: [[VAL_183:%.*]] = fir.mulc [[VAL_180]], [[VAL_182]] : !fir.complex<16>
564// CHECK: [[VAL_184:%.*]] = fir.divc [[VAL_183]], [[VAL_178]] : !fir.complex<16>
565  %1 = fir.negc %a : !fir.complex<16>
566  %2 = fir.addc %b, %1 : !fir.complex<16>
567  %3 = fir.subc %2, %b : !fir.complex<16>
568  %4 = fir.mulc %1, %3 : !fir.complex<16>
569  %5 = fir.divc %4, %a : !fir.complex<16>
570// CHECK: return [[VAL_184]] : !fir.complex<16>
571// CHECK: }
572  return %5 : !fir.complex<16>
573}
574
575// CHECK-LABEL: func @character_literal() -> !fir.array<13x!fir.char<1>> {
576func @character_literal() -> !fir.array<13 x !fir.char<1>> {
577// CHECK: [[VAL_185:%.*]] = fir.string_lit "Hello, World!"(13) : !fir.char<1>
578  %0 = fir.string_lit "Hello, World!"(13) : !fir.char<1>
579// CHECK: return [[VAL_185]] : !fir.array<13x!fir.char<1>>
580  return %0 : !fir.array<13 x !fir.char<1>>
581// CHECK: }
582}
583
584// CHECK-LABEL: func private @earlyexit2(i32) -> i1
585func private @earlyexit2(%a : i32) -> i1
586
587// CHECK-LABEL: func @early_exit(
588// CHECK-SAME: [[VAL_186:%.*]]: i1, [[VAL_187:%.*]]: i32) -> i1 {
589func @early_exit(%ok : i1, %k : i32) -> i1 {
590// CHECK: [[VAL_188:%.*]] = constant 1 : index
591// CHECK: [[VAL_189:%.*]] = constant 100 : index
592  %c1 = constant 1 : index
593  %c100 = constant 100 : index
594
595// CHECK: [[VAL_190:%.*]], [[VAL_191:%.*]] = fir.iterate_while ([[VAL_192:%.*]] = [[VAL_188]] to [[VAL_189]] step [[VAL_188]]) and ([[VAL_193:%.*]] = [[VAL_186]]) iter_args([[VAL_194:%.*]] = [[VAL_187]]) -> (i32) {
596// CHECK: [[VAL_195:%.*]] = call @earlyexit2([[VAL_194]]) : (i32) -> i1
597// CHECK: fir.result [[VAL_195]], [[VAL_194]] : i1, i32
598// CHECK: }
599  %newOk:2 = fir.iterate_while (%i = %c1 to %c100 step %c1) and (%ok_ = %ok) iter_args(%v = %k) -> (i32) {
600    %stop = call @earlyexit2(%v) : (i32) -> i1
601    fir.result %stop, %v : i1, i32
602  }
603// CHECK: return [[VAL_190]] : i1
604// CHECK: }
605  return %newOk#0 : i1
606}
607