Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / Intrinsics / bessel_jn.f90
blob9e0698a5986fe59e76399d9346e137f5f7b51cdd
1 ! RUN: bbc -emit-fir %s -o - --math-runtime=fast | FileCheck --check-prefixes=ALL %s
2 ! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %s -o - | FileCheck --check-prefixes=ALL %s
3 ! RUN: bbc -emit-fir %s -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL %s
4 ! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %s -o - | FileCheck --check-prefixes=ALL %s
5 ! RUN: bbc -emit-fir %s -o - --math-runtime=precise | FileCheck --check-prefixes=ALL %s
6 ! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %s -o - | FileCheck --check-prefixes=ALL %s
8 ! ALL-LABEL: @_QPtest_real4
9 ! ALL-SAME: (%[[argx:.*]]: !fir.ref<f32>{{.*}}, %[[argn:.*]]: !fir.ref<i32>{{.*}}) -> f32
10 function test_real4(x, n)
11 real :: x, test_real4
12 integer :: n
14 ! ALL-DAG: %[[x:.*]] = fir.load %[[argx]] : !fir.ref<f32>
15 ! ALL-DAG: %[[n:.*]] = fir.load %[[argn]] : !fir.ref<i32>
16 ! ALL: fir.call @jnf(%[[n]], %[[x]]) {{.*}} : (i32, f32) -> f32
17 test_real4 = bessel_jn(n, x)
18 end function
20 ! ALL-LABEL: @_QPtest_real8
21 ! ALL-SAME: (%[[argx:.*]]: !fir.ref<f64>{{.*}}, %[[argn:.*]]: !fir.ref<i32>{{.*}}) -> f64
22 function test_real8(x, n)
23 real(8) :: x, test_real8
24 integer :: n
26 ! ALL-DAG: %[[x:.*]] = fir.load %[[argx]] : !fir.ref<f64>
27 ! ALL-DAG: %[[n:.*]] = fir.load %[[argn]] : !fir.ref<i32>
28 ! ALL: fir.call @jn(%[[n]], %[[x]]) {{.*}} : (i32, f64) -> f64
29 test_real8 = bessel_jn(n, x)
30 end function
32 ! ALL-LABEL: @_QPtest_transformational_real4
33 ! ALL-SAME: %[[argx:.*]]: !fir.ref<f32>{{.*}}, %[[argn1:.*]]: !fir.ref<i32>{{.*}}, %[[argn2:.*]]: !fir.ref<i32>{{.*}}
34 subroutine test_transformational_real4(x, n1, n2, r)
35 real(4) :: x
36 integer :: n1, n2
37 real(4) :: r(:)
39 ! ALL-DAG: %[[zero:.*]] = arith.constant 0{{.*}} : f32
40 ! ALL-DAG: %[[one:.*]] = arith.constant 1 : i32
41 ! ALL-DAG: %[[r:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xf32>>>
42 ! ALL-DAG: %[[x:.*]] = fir.load %[[argx]] : !fir.ref<f32>
43 ! ALL-DAG: %[[n1:.*]] = fir.load %[[argn1]] : !fir.ref<i32>
44 ! ALL-DAG: %[[n2:.*]] = fir.load %[[argn2]] : !fir.ref<i32>
45 ! ALL-DAG: %[[xeq0:.*]] = arith.cmpf ueq, %[[x]], %[[zero]] : f32
46 ! ALL-DAG: %[[n1ltn2:.*]] = arith.cmpi slt, %[[n1]], %[[n2]] : i32
47 ! ALL-DAG: %[[n1eqn2:.*]] = arith.cmpi eq, %[[n1]], %[[n2]] : i32
48 ! ALL: fir.if %[[xeq0]] {
49 ! ALL: %[[resxeq0:.*]] = fir.convert %[[r]] {{.*}}
50 ! ALL: fir.call @_FortranABesselJnX0_4(%[[resxeq0]], %[[n1]], %[[n2]], {{.*}}, {{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, i32, i32, !fir.ref<i8>, i32) -> none
51 ! ALL-NEXT: } else {
52 ! ALL-NEXT: fir.if %[[n1ltn2]] {
53 ! ALL-DAG: %[[n2_1:.*]] = arith.subi %[[n2]], %[[one]] : i32
54 ! ALL-DAG: %[[bn2:.*]] = fir.call @jnf(%[[n2]], %[[x]]) {{.*}} : (i32, f32) -> f32
55 ! ALL-DAG: %[[bn2_1:.*]] = fir.call @jnf(%[[n2_1]], %[[x]]) {{.*}} : (i32, f32) -> f32
56 ! ALL-DAG: %[[resn1ltn2:.*]] = fir.convert %[[r]] {{.*}}
57 ! ALL: fir.call @_FortranABesselJn_4(%[[resn1ltn2]], %[[n1]], %[[n2]], %[[x]], %[[bn2]], %[[bn2_1]], {{.*}}, {{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, i32, i32, f32, f32, f32, !fir.ref<i8>, i32) -> none
58 ! ALL-NEXT: } else {
59 ! ALL-NEXT: fir.if %[[n1eqn2]] {
60 ! ALL-DAG: %[[bn2:.*]] = fir.call @jnf(%[[n2]], %[[x]]) {{.*}} : (i32, f32) -> f32
61 ! ALL-DAG: %[[resn1eqn2:.*]] = fir.convert %[[r]] {{.*}}
62 ! ALL: fir.call @_FortranABesselJn_4(%[[resn1eqn2]], %[[n1]], %[[n2]], %[[x]], %[[bn2]], %[[zero]], {{.*}}, {{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, i32, i32, f32, f32, f32, !fir.ref<i8>, i32) -> none
63 ! ALL-NEXT: } else {
64 ! ALL-DAG: %[[resn1gtn2:.*]] = fir.convert %[[r]] {{.*}}
65 ! ALL: fir.call @_FortranABesselJn_4(%[[resn1gtn2]], %[[n1]], %[[n2]], %[[x]], %[[zero]], %[[zero]], {{.*}}, {{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, i32, i32, f32, f32, f32, !fir.ref<i8>, i32) -> none
66 ! ALL-NEXT: }
67 ! ALL-NEXT: }
68 ! ALL-NEXT: }
69 r = bessel_jn(n1, n2, x)
70 ! ALL: %[[box:.*]] = fir.load %[[r]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
71 ! ALL: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.heap<!fir.array<?xf32>>
72 ! ALL: fir.freemem %[[addr]] : !fir.heap<!fir.array<?xf32>>
73 end subroutine test_transformational_real4
75 ! ALL-LABEL: @_QPtest_transformational_real8
76 ! ALL-SAME: %[[argx:.*]]: !fir.ref<f64>{{.*}}, %[[argn1:.*]]: !fir.ref<i32>{{.*}}, %[[argn2:.*]]: !fir.ref<i32>{{.*}}
77 subroutine test_transformational_real8(x, n1, n2, r)
78 real(8) :: x
79 integer :: n1, n2
80 real(8) :: r(:)
82 ! ALL-DAG: %[[zero:.*]] = arith.constant 0{{.*}} : f64
83 ! ALL-DAG: %[[one:.*]] = arith.constant 1 : i32
84 ! ALL-DAG: %[[r:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xf64>>>
85 ! ALL-DAG: %[[x:.*]] = fir.load %[[argx]] : !fir.ref<f64>
86 ! ALL-DAG: %[[n1:.*]] = fir.load %[[argn1]] : !fir.ref<i32>
87 ! ALL-DAG: %[[n2:.*]] = fir.load %[[argn2]] : !fir.ref<i32>
88 ! ALL-DAG: %[[xeq0:.*]] = arith.cmpf ueq, %[[x]], %[[zero]] : f64
89 ! ALL-DAG: %[[n1ltn2:.*]] = arith.cmpi slt, %[[n1]], %[[n2]] : i32
90 ! ALL-DAG: %[[n1eqn2:.*]] = arith.cmpi eq, %[[n1]], %[[n2]] : i32
91 ! ALL: fir.if %[[xeq0]] {
92 ! ALL: %[[resxeq0:.*]] = fir.convert %[[r]] {{.*}}
93 ! ALL: fir.call @_FortranABesselJnX0_8(%[[resxeq0]], %[[n1]], %[[n2]], {{.*}}, {{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, i32, i32, !fir.ref<i8>, i32) -> none
94 ! ALL-NEXT: } else {
95 ! ALL-NEXT: fir.if %[[n1ltn2]] {
96 ! ALL-DAG: %[[n2_1:.*]] = arith.subi %[[n2]], %[[one]] : i32
97 ! ALL-DAG: %[[bn2:.*]] = fir.call @jn(%[[n2]], %[[x]]) {{.*}} : (i32, f64) -> f64
98 ! ALL-DAG: %[[bn2_1:.*]] = fir.call @jn(%[[n2_1]], %[[x]]) {{.*}} : (i32, f64) -> f64
99 ! ALL-DAG: %[[resn1ltn2:.*]] = fir.convert %[[r]] {{.*}}
100 ! ALL: fir.call @_FortranABesselJn_8(%[[resn1ltn2]], %[[n1]], %[[n2]], %[[x]], %[[bn2]], %[[bn2_1]], {{.*}}, {{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, i32, i32, f64, f64, f64, !fir.ref<i8>, i32) -> none
101 ! ALL-NEXT: } else {
102 ! ALL-NEXT: fir.if %[[n1eqn2]] {
103 ! ALL-DAG: %[[bn2:.*]] = fir.call @jn(%[[n2]], %[[x]]) {{.*}} : (i32, f64) -> f64
104 ! ALL-DAG: %[[resn1eqn2:.*]] = fir.convert %[[r]] {{.*}}
105 ! ALL: fir.call @_FortranABesselJn_8(%[[resn1eqn2]], %[[n1]], %[[n2]], %[[x]], %[[bn2]], %[[zero]], {{.*}}, {{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, i32, i32, f64, f64, f64, !fir.ref<i8>, i32) -> none
106 ! ALL-NEXT: } else {
107 ! ALL-DAG: %[[resn1gtn2:.*]] = fir.convert %[[r]] {{.*}}
108 ! ALL: fir.call @_FortranABesselJn_8(%[[resn1gtn2]], %[[n1]], %[[n2]], %[[x]], %[[zero]], %[[zero]], {{.*}}, {{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, i32, i32, f64, f64, f64, !fir.ref<i8>, i32) -> none
109 ! ALL-NEXT: }
110 ! ALL-NEXT: }
111 ! ALL-NEXT: }
112 r = bessel_jn(n1, n2, x)
113 ! ALL: %[[box:.*]] = fir.load %[[r]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf64>>>>
114 ! ALL: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.heap<!fir.array<?xf64>>>) -> !fir.heap<!fir.array<?xf64>>
115 ! ALL: fir.freemem %[[addr]] : !fir.heap<!fir.array<?xf64>>
116 end subroutine test_transformational_real8