1! RUN: bbc -emit-fir %s -o - | FileCheck %s
2
3! CHECK-LABEL: nearest_test1
4subroutine nearest_test1(x, s)
5    real :: x, s, res
6  ! CHECK: %[[res:.*]] = fir.alloca f32 {bindc_name = "res", uniq_name = "_QFnearest_test1Eres"}
7  ! CHECK: %[[x:.*]] = fir.load %arg0 : !fir.ref<f32>
8  ! CHECK: %[[s:.*]] = fir.load %arg1 : !fir.ref<f32>
9  ! CHECK: %[[zero:.*]] = arith.constant 0.000000e+00 : f32
10  ! CHECK: %[[cmp:.*]] = arith.cmpf ogt, %[[s]], %[[zero]] : f32
11  ! CHECK: %[[pos:.*]] = arith.select %[[cmp]], %true, %false : i1
12    res = nearest(x, s)
13  ! CHECK: %[[tmp:.*]] = fir.call @_FortranANearest4(%[[x]], %[[pos]]) : (f32, i1) -> f32
14  ! CHECK: fir.store %[[tmp]] to %[[res]] : !fir.ref<f32>
15  end subroutine nearest_test1
16
17  ! CHECK-LABEL: nearest_test2
18  subroutine nearest_test2(x, s)
19    real(kind=8) :: x, s, res
20  ! CHECK: %[[res:.*]] = fir.alloca f64 {bindc_name = "res", uniq_name = "_QFnearest_test2Eres"}
21  ! CHECK: %[[x:.*]] = fir.load %arg0 : !fir.ref<f64>
22  ! CHECK: %[[s:.*]] = fir.load %arg1 : !fir.ref<f64>
23  ! CHECK: %[[zero:.*]] = arith.constant 0.000000e+00 : f64
24  ! CHECK: %[[cmp:.*]] = arith.cmpf ogt, %[[s]], %[[zero]] : f64
25  ! CHECK: %[[pos:.*]] = arith.select %[[cmp]], %true, %false : i1
26    res = nearest(x, s)
27  ! CHECK: %[[tmp:.*]] = fir.call @_FortranANearest8(%[[x]], %[[pos]]) : (f64, i1) -> f64
28  ! CHECK: fir.store %[[tmp]] to %[[res]] : !fir.ref<f64>
29  end subroutine nearest_test2
30
31  ! CHECK-LABEL: nearest_test3
32  subroutine nearest_test3(x, s)
33    real(kind=10) :: x, s, res
34  ! CHECK: %[[res:.*]] = fir.alloca f80 {bindc_name = "res", uniq_name = "_QFnearest_test3Eres"}
35  ! CHECK: %[[x:.*]] = fir.load %arg0 : !fir.ref<f80>
36  ! CHECK: %[[s:.*]] = fir.load %arg1 : !fir.ref<f80>
37  ! CHECK: %[[zero:.*]] = arith.constant 0.000000e+00 : f80
38  ! CHECK: %[[cmp:.*]] = arith.cmpf ogt, %[[s]], %[[zero]] : f80
39  ! CHECK: %[[pos:.*]] = arith.select %[[cmp]], %true, %false : i1
40    res = nearest(x, s)
41  ! CHECK: %[[tmp:.*]] = fir.call @_FortranANearest10(%[[x]], %[[pos]]) : (f80, i1) -> f80
42  ! CHECK: fir.store %[[tmp]] to %[[res]] : !fir.ref<f80>
43  end subroutine nearest_test3
44
45  ! CHECK-LABEL: nearest_test4
46  subroutine nearest_test4(x, s)
47    real(kind=16) :: x, s, res
48  ! CHECK: %[[res:.*]] = fir.alloca f128 {bindc_name = "res", uniq_name = "_QFnearest_test4Eres"}
49  ! CHECK: %[[x:.*]] = fir.load %arg0 : !fir.ref<f128>
50  ! CHECK: %[[s:.*]] = fir.load %arg1 : !fir.ref<f128>
51  ! CHECK: %[[zero:.*]] = arith.constant 0.000000e+00 : f128
52  ! CHECK: %[[cmp:.*]] = arith.cmpf ogt, %[[s]], %[[zero]] : f128
53  ! CHECK: %[[pos:.*]] = arith.select %[[cmp]], %true, %false : i1
54    res = nearest(x, s)
55  ! CHECK: %[[tmp:.*]] = fir.call @_FortranANearest16(%[[x]], %[[pos]]) : (f128, i1) -> f128
56  ! CHECK: fir.store %[[tmp]] to %[[res]] : !fir.ref<f128>
57  end subroutine nearest_test4
58
59  ! CHECK-LABEL: nearest_test5
60  subroutine nearest_test5(x, s)
61    real(kind=16) :: x, res
62  ! CHECK: %[[res:.*]] = fir.alloca f128 {bindc_name = "res", uniq_name = "_QFnearest_test5Eres"}
63  ! CHECK: %[[x:.*]] = fir.load %arg0 : !fir.ref<f128>
64    real :: s
65  ! CHECK: %[[s:.*]] = fir.load %arg1 : !fir.ref<f32>
66  ! CHECK: %[[zero:.*]] = arith.constant 0.000000e+00 : f32
67  ! CHECK: %[[cmp:.*]] = arith.cmpf ogt, %[[s]], %[[zero]] : f32
68  ! CHECK: %[[pos:.*]] = arith.select %[[cmp]], %true, %false : i1
69    res = nearest(x, s)
70  ! CHECK: %[[tmp:.*]] = fir.call @_FortranANearest16(%[[x]], %[[pos]]) : (f128, i1) -> f128
71  ! CHECK: fir.store %[[tmp]] to %[[res]] : !fir.ref<f128>
72  end subroutine nearest_test5
73