1 ! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s --check-prefixes="CHECK,CMPLX,CMPLX-PRECISE"
2 ! RUN: bbc -emit-fir -hlfir=false --math-runtime=precise %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-PRECISE"
3 ! RUN: bbc --force-mlir-complex -emit-fir -hlfir=false %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-FAST"
4 ! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir %s -o - | FileCheck %s --check-prefixes="CHECK,CMPLX,CMPLX-PRECISE"
5 ! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -mllvm --math-runtime=precise %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-PRECISE"
6 ! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -mllvm --force-mlir-complex %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-FAST"
7 ! RUN: %flang_fc1 -fapprox-func -emit-fir -flang-deprecated-no-hlfir %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-APPROX"
9 ! Test abs intrinsic for various types (int, float, complex)
11 ! CHECK-LABEL: func @_QPabs_testi
12 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32>{{.*}}, %[[VAL_1:.*]]: !fir.ref<i32>
13 subroutine abs_testi(a
, b
)
14 ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
15 ! CHECK: %[[VAL_3:.*]] = arith.constant 31 : i32
16 ! CHECK: %[[VAL_4:.*]] = arith.shrsi %[[VAL_2]], %[[VAL_3]] : i32
17 ! CHECK: %[[VAL_5:.*]] = arith.xori %[[VAL_2]], %[[VAL_4]] : i32
18 ! CHECK: %[[VAL_6:.*]] = arith.subi %[[VAL_5]], %[[VAL_4]] : i32
19 ! CHECK: fir.store %[[VAL_6]] to %[[VAL_1]] : !fir.ref<i32>
25 ! CHECK-LABEL: func @_QPabs_testi16
26 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i128>{{.*}}, %[[VAL_1:.*]]: !fir.ref<i128>
27 subroutine abs_testi16(a
, b
)
28 ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<i128>
29 ! CHECK: %[[VAL_3:.*]] = arith.constant 127 : i128
30 ! CHECK: %[[VAL_4:.*]] = arith.shrsi %[[VAL_2]], %[[VAL_3]] : i128
31 ! CHECK: %[[VAL_5:.*]] = arith.xori %[[VAL_2]], %[[VAL_4]] : i128
32 ! CHECK: %[[VAL_6:.*]] = arith.subi %[[VAL_5]], %[[VAL_4]] : i128
33 ! CHECK: fir.store %[[VAL_6]] to %[[VAL_1]] : !fir.ref<i128>
35 integer(kind
=16) :: a
, b
39 ! CHECK-LABEL: func @_QPabs_testh(
40 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f16>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f16>{{.*}}) {
41 subroutine abs_testh(a
, b
)
42 ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<f16>
43 ! CHECK: %[[VAL_2_1:.*]] = fir.convert %[[VAL_2]] : (f16) -> f32
44 ! CHECK: %[[VAL_3:.*]] = math.absf %[[VAL_2_1]] {{.*}}: f32
45 ! CHECK: %[[VAL_3_1:.*]] = fir.convert %[[VAL_3]] : (f32) -> f16
46 ! CHECK: fir.store %[[VAL_3_1]] to %[[VAL_1]] : !fir.ref<f16>
52 ! CHECK-LABEL: func @_QPabs_testb(
53 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<bf16>{{.*}}, %[[VAL_1:.*]]: !fir.ref<bf16>{{.*}}) {
54 subroutine abs_testb(a
, b
)
55 ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<bf16>
56 ! CHECK: %[[VAL_2_1:.*]] = fir.convert %[[VAL_2]] : (bf16) -> f32
57 ! CHECK: %[[VAL_3:.*]] = math.absf %[[VAL_2_1]] {{.*}}: f32
58 ! CHECK: %[[VAL_3_1:.*]] = fir.convert %[[VAL_3]] : (f32) -> bf16
59 ! CHECK: fir.store %[[VAL_3_1]] to %[[VAL_1]] : !fir.ref<bf16>
65 ! CHECK-LABEL: func @_QPabs_testr(
66 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f32>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f32>{{.*}}) {
67 subroutine abs_testr(a
, b
)
68 ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<f32>
69 ! CHECK: %[[VAL_3:.*]] = math.absf %[[VAL_2]] {{.*}}: f32
70 ! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<f32>
76 ! CHECK-LABEL: func @_QPabs_testd(
77 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f64>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f64>{{.*}}) {
78 subroutine abs_testd(a
, b
)
79 ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<f64>
80 ! CHECK: %[[VAL_3:.*]] = math.absf %[[VAL_2]] {{.*}}: f64
81 ! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<f64>
87 ! CHECK-LABEL: func @_QPabs_testr16(
88 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f128>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f128>{{.*}}) {
89 subroutine abs_testr16(a
, b
)
90 ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<f128>
91 ! CHECK: %[[VAL_3:.*]] = math.absf %[[VAL_2]] {{.*}}: f128
92 ! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<f128>
98 ! CMPLX-LABEL: func @_QPabs_testzr(
99 ! CMPLX-SAME: %[[VAL_0:.*]]: !fir.ref<complex<f32>>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f32>{{.*}}) {
100 subroutine abs_testzr(a
, b
)
101 ! CMPLX: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<complex<f32>>
102 ! CMPLX-FAST: %[[VAL_4:.*]] = complex.abs %[[VAL_2]] fastmath<contract> : complex<f32>
103 ! CMPLX-APPROX: %[[VAL_4:.*]] = complex.abs %[[VAL_2]] fastmath<contract,afn> : complex<f32>
104 ! CMPLX-PRECISE: %[[VAL_4:.*]] = fir.call @cabsf(%[[VAL_2]]) {{.*}}: (complex<f32>) -> f32
105 ! CMPLX: fir.store %[[VAL_4]] to %[[VAL_1]] : !fir.ref<f32>
110 end subroutine abs_testzr
112 ! CMPLX-LABEL: func @_QPabs_testzd(
113 ! CMPLX-SAME: %[[VAL_0:.*]]: !fir.ref<complex<f64>>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f64>{{.*}}) {
114 subroutine abs_testzd(a
, b
)
115 ! CMPLX: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<complex<f64>>
116 ! CMPLX-FAST: %[[VAL_4:.*]] = complex.abs %[[VAL_2]] fastmath<contract> : complex<f64>
117 ! CMPLX-APPROX: %[[VAL_4:.*]] = complex.abs %[[VAL_2]] fastmath<contract,afn> : complex<f64>
118 ! CMPLX-PRECISE: %[[VAL_4:.*]] = fir.call @cabs(%[[VAL_2]]) {{.*}}: (complex<f64>) -> f64
119 ! CMPLX: fir.store %[[VAL_4]] to %[[VAL_1]] : !fir.ref<f64>
124 end subroutine abs_testzd