1
-
2
1
// RUN: fir-opt %s --fir-to-scf | FileCheck %s
3
2
4
- // CHECK: func.func @_QFPtest_only(
5
- // CHECK: %[[ARG0:.*]]: !fir.ref<tuple<!fir.ref<f32>>>) {
6
- // CHECK: %[[VAL_0:.*]] = arith.constant 1 : i32
7
- // CHECK: %[[VAL_1:.*]] = arith.constant false
8
- // CHECK: %[[VAL_2:.*]] = arith.constant 0 : i32
9
- // CHECK: scf.if %[[VAL_1:.*]] {
10
- // CHECK: %[[VAL_3:.*]] = arith.addi %[[VAL_2:.*]], %[[VAL_0:.*]] : i32
3
+ // CHECK: func.func @test_only(%[[ARG0:.*]]: i1, %[[ARG1:.*]]: i32) {
4
+ // CHECK: scf.if %[[ARG0:.*]] {
5
+ // CHECK: %[[VAL_1:.*]] = arith.addi %[[ARG1:.*]], %[[ARG1:.*]] : i32
11
6
// CHECK: }
12
7
// CHECK: return
13
8
// CHECK: }
14
- func.func @_QFPtest_only(%arg0: !fir.ref<tuple<!fir.ref<f32>>>) {
15
- %c1_i32 = arith.constant 1 : i32
16
- %false = arith.constant false
17
- %c0_i32 = arith.constant 0 : i32
18
- fir.if %false {
19
- %0 = arith.addi %c0_i32, %c1_i32 : i32
9
+ func.func @test_only(%arg0 : i1, %arg1 : i32) {
10
+ fir.if %arg0 {
11
+ %0 = arith.addi %arg1, %arg1 : i32
20
12
}
21
13
return
22
14
}
23
15
24
- // CHECK: func.func @_QFPtest_else (
25
- // CHECK: %[[ARG0:.*]]: !fir.ref<tuple<!fir.ref<f32>>>) {
26
- // CHECK: %[[VAL_0:.*]] = arith.constant 1 : i32
16
+ // CHECK: func.func @test_else () {
27
17
// CHECK: %[[VAL_1:.*]] = arith.constant false
28
- // CHECK: %[[VAL_2:.*]] = arith.constant 0 : i32
29
- // CHECK: %[[VAL_3:.*]] = fir.dummy_scope : !fir.dscope
30
- // CHECK: %[[VAL_4:.*]] = fir.coordinate_of %[[ARG0:.*]], %[[VAL_2:.*]] : (!fir.ref<tuple<!fir.ref<f32>>>, i32) -> !fir.llvm_ptr<!fir.ref<f32>>
31
- // CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_4:.*]] : !fir.llvm_ptr<!fir.ref<f32>>
32
- // CHECK: %[[VAL_6:.*]] = fir.declare %[[VAL_5:.*]] {fortran_attrs = #fir.var_attrs<host_assoc>, uniq_name = "_QFEx"} : (!fir.ref<f32>) -> !fir.ref<f32>
33
- // CHECK: %[[VAL_7:.*]] = fir.address_of(@_QFFtest_else Esum) : !fir.ref<i32>
34
- // CHECK: %[[VAL_10:.*]] = fir.declare %[[VAL_7:.*]] {uniq_name = "_QFFtest_else Esum"} : (!fir.ref<i32>) -> !fir.ref<i32>
18
+ // CHECK: %[[VAL_2:.*]] = arith.constant 2 : i32
35
19
// CHECK: scf.if %[[VAL_1:.*]] {
36
- // CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_10:.*]] : !fir.ref<i32>
37
- // CHECK: %[[VAL_9:.*]] = arith.addi %[[VAL_8:.*]], %[[VAL_0:.*]] : i32
38
- // CHECK: fir.store %[[VAL_9:.*]] to %[[VAL_10:.*]] : !fir.ref<i32>
20
+ // CHECK: %[[VAL_3:.*]] = arith.constant 3 : i32
39
21
// CHECK: } else {
40
- // CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_10:.*]] : !fir.ref<i32>
41
- // CHECK: %[[VAL_9:.*]] = arith.addi %[[VAL_8:.*]], %c1_i32 : i32
42
- // CHECK: fir.store %[[VAL_9:.*]] to %[[VAL_10:.*]] : !fir.ref<i32>
22
+ // CHECK: %[[VAL_3:.*]] = arith.constant 3 : i32
43
23
// CHECK: }
44
24
// CHECK: return
45
25
// CHECK: }
46
- func.func @_QFPtest_else(%arg0: !fir.ref<tuple<!fir.ref<f32>>> {}) attributes {} {
47
- %c1_i32 = arith.constant 1 : i32
26
+ func.func @test_else () {
48
27
%false = arith.constant false
49
- %c0_i32 = arith.constant 0 : i32
50
- %0 = fir.dummy_scope : !fir.dscope
51
- %1 = fir.coordinate_of %arg0, %c0_i32 : (!fir.ref<tuple<!fir.ref<f32>>>, i32) -> !fir.llvm_ptr<!fir.ref<f32>>
52
- %2 = fir.load %1 : !fir.llvm_ptr<!fir.ref<f32>>
53
- %3 = fir.declare %2 {fortran_attrs = #fir.var_attrs<host_assoc>, uniq_name = " _QFEx"} : (!fir.ref<f32>) -> !fir.ref<f32>
54
- %4 = fir.address_of(@_QFFtest_elseEsum) : !fir.ref<i32>
55
- %5 = fir.declare %4 {uniq_name = " _QFFtest_elseEsum"} : (!fir.ref<i32>) -> !fir.ref<i32>
28
+ %1 = arith.constant 2 : i32
56
29
fir.if %false {
57
- %6 = fir.load %5 : !fir.ref<i32>
58
- %7 = arith.addi %6, %c1_i32 : i32
59
- fir.store %7 to %5 : !fir.ref<i32>
30
+ %2 = arith.constant 3 : i32
60
31
} else {
61
- %6 = fir.load %5 : !fir.ref<i32>
62
- %7 = arith.addi %6, %c1_i32 : i32
63
- fir.store %7 to %5 : !fir.ref<i32>
32
+ %3 = arith.constant 3 : i32
64
33
}
65
34
return
66
35
}
67
36
68
- // CHECK-LABEL: func.func @test_two_result() {
69
- // CHECK: %[[VAL_0:.*]] = arith.constant 10 : i32
70
- // CHECK: %[[VAL_1:.*]] = arith.constant 5 : i32
71
- // CHECK: %[[VAL_2:.*]] = arith.cmpi sgt, %[[VAL_0:.*]], %[[VAL_1:.*]] : i32
72
- // CHECK: %[[VAL_3:.*]] = arith.constant 3.140000e+00 : f32
73
- // CHECK: %[[VAL_4:.*]] = arith.constant 2.710000e+00 : f32
74
- // CHECK: %[[VAL_5:.*]] = arith.constant 1.000000e+00 : f32
75
- // CHECK: %[[VAL_6:.*]] = arith.constant 2.000000e+00 : f32
37
+ // CHECK-LABEL: func.func @test_two_result() {
38
+ // CHECK: %[[VAL_1:.*]] = arith.constant 2.000000e+00 : f32
39
+ // CHECK: %[[VAL_2:.*]] = arith.constant false
76
40
// CHECK: %[[RES:[0-9]+]]:2 = scf.if %[[VAL_2:.*]] -> (f32, f32) {
77
- // CHECK: scf.yield %[[VAL_3 :.*]], %[[VAL_4 :.*]] : f32, f32
41
+ // CHECK: scf.yield %[[VAL_1 :.*]], %[[VAL_1 :.*]] : f32, f32
78
42
// CHECK: } else {
79
- // CHECK: scf.yield %[[VAL_5 :.*]], %[[VAL_6 :.*]] : f32, f32
43
+ // CHECK: scf.yield %[[VAL_1 :.*]], %[[VAL_1 :.*]] : f32, f32
80
44
// CHECK: }
81
45
// CHECK: return
82
46
// CHECK: }
47
+
83
48
func.func @test_two_result() {
84
- %c10_i32 = arith.constant 10 : i32
85
- %c5_i32 = arith.constant 5 : i32
86
- %cmp = arith.cmpi sgt, %c10_i32, %c5_i32 : i32
87
- %c3_14_f32 = arith.constant 3.14 : f32
88
- %c2_71_f32 = arith.constant 2.71 : f32
89
- %c1_0_f32 = arith.constant 1.0 : f32
90
- %c2_0_f32 = arith.constant 2.0 : f32
49
+ %1 = arith.constant 2.0 : f32
50
+ %cmp = arith.constant false
91
51
%x, %y = fir.if %cmp -> (f32, f32) {
92
- fir.result %c3_14_f32 , %c2_71_f32 : f32, f32
52
+ fir.result %1 , %1 : f32, f32
93
53
} else {
94
- fir.result %c1_0_f32 , %c2_0_f32 : f32, f32
54
+ fir.result %1 , %1 : f32, f32
95
55
}
96
56
return
97
- }
57
+ }
0 commit comments