Debian Codegraph @

flang/test/Lower/Intrinsics/abs.f90

raw
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"
8
9 ! Test abs intrinsic for various types (int, float, complex)
10
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>
20 ! CHECK: return
21 integer :: a, b
22 b = abs(a)
23 end subroutine
24
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>
34 ! CHECK: return
35 integer(kind=16) :: a, b
36 b = abs(a)
37 end subroutine
38
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>
47 ! CHECK: return
48 real(kind=2) :: a, b
49 b = abs(a)
50 end subroutine
51
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>
60 ! CHECK: return
61 real(kind=3) :: a, b
62 b = abs(a)
63 end subroutine
64
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>
71 ! CHECK: return
72 real :: a, b
73 b = abs(a)
74 end subroutine
75
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>
82 ! CHECK: return
83 real(kind=8) :: a, b
84 b = abs(a)
85 end subroutine
86
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>
93 ! CHECK: return
94 real(kind=16) :: a, b
95 b = abs(a)
96 end subroutine
97
98 ! CMPLX-LABEL: func @_QPabs_testzr(
99 ! CMPLX-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.complex<4>>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f32>{{.*}}) {
100 subroutine abs_testzr(a, b)
101 ! CMPLX: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.complex<4>>
102 ! CMPLX-FAST: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.complex<4>) -> complex<f32>
103 ! CMPLX-FAST: %[[VAL_4:.*]] = complex.abs %[[VAL_3]] fastmath<contract> : complex<f32>
104 ! CMPLX-APPROX: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.complex<4>) -> complex<f32>
105 ! CMPLX-APPROX: %[[VAL_4:.*]] = complex.abs %[[VAL_3]] fastmath<contract,afn> : complex<f32>
106 ! CMPLX-PRECISE: %[[VAL_4:.*]] = fir.call @cabsf(%[[VAL_2]]) {{.*}}: (!fir.complex<4>) -> f32
107 ! CMPLX: fir.store %[[VAL_4]] to %[[VAL_1]] : !fir.ref<f32>
108 ! CMPLX: return
109 complex :: a
110 real :: b
111 b = abs(a)
112 end subroutine abs_testzr
113
114 ! CMPLX-LABEL: func @_QPabs_testzd(
115 ! CMPLX-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.complex<8>>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f64>{{.*}}) {
116 subroutine abs_testzd(a, b)
117 ! CMPLX: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.complex<8>>
118 ! CMPLX-FAST: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.complex<8>) -> complex<f64>
119 ! CMPLX-FAST: %[[VAL_4:.*]] = complex.abs %[[VAL_3]] fastmath<contract> : complex<f64>
120 ! CMPLX-APPROX: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.complex<8>) -> complex<f64>
121 ! CMPLX-APPROX: %[[VAL_4:.*]] = complex.abs %[[VAL_3]] fastmath<contract,afn> : complex<f64>
122 ! CMPLX-PRECISE: %[[VAL_4:.*]] = fir.call @cabs(%[[VAL_2]]) {{.*}}: (!fir.complex<8>) -> f64
123 ! CMPLX: fir.store %[[VAL_4]] to %[[VAL_1]] : !fir.ref<f64>
124 ! CMPLX: return
125 complex(kind=8) :: a
126 real(kind=8) :: b
127 b = abs(a)
128 end subroutine abs_testzd