brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.0 KiB · 7150cb2 Raw
130 lines · plain
1! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s --check-prefixes=CHECK,CMPLX,CMPLX-PRECISE,%if flang-supports-f128-math %{F128%} %else %{F64%}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,%if flang-supports-f128-math %{F128%} %else %{F64%}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_testi12! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32>{{.*}}, %[[VAL_1:.*]]: !fir.ref<i32>13subroutine abs_testi(a, b)14! CHECK:  %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>15! CHECK:  %[[VAL_3:.*]] = arith.constant 31 : i3216! CHECK:  %[[VAL_4:.*]] = arith.shrsi %[[VAL_2]], %[[VAL_3]] : i3217! CHECK:  %[[VAL_5:.*]] = arith.xori %[[VAL_2]], %[[VAL_4]] : i3218! CHECK:  %[[VAL_6:.*]] = arith.subi %[[VAL_5]], %[[VAL_4]] : i3219! CHECK:  fir.store %[[VAL_6]] to %[[VAL_1]] : !fir.ref<i32>20! CHECK:  return21  integer :: a, b22  b = abs(a)23end subroutine24 25! CHECK-LABEL: func @_QPabs_testi1626! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i128>{{.*}}, %[[VAL_1:.*]]: !fir.ref<i128>27subroutine abs_testi16(a, b)28! CHECK:  %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<i128>29! CHECK:  %[[VAL_3:.*]] = arith.constant 127 : i12830! CHECK:  %[[VAL_4:.*]] = arith.shrsi %[[VAL_2]], %[[VAL_3]] : i12831! CHECK:  %[[VAL_5:.*]] = arith.xori %[[VAL_2]], %[[VAL_4]] : i12832! CHECK:  %[[VAL_6:.*]] = arith.subi %[[VAL_5]], %[[VAL_4]] : i12833! CHECK:  fir.store %[[VAL_6]] to %[[VAL_1]] : !fir.ref<i128>34! CHECK:  return35  integer(kind=16) :: a, b36  b = abs(a)37end subroutine38 39! CHECK-LABEL: func @_QPabs_testh(40! CHECK-SAME:  %[[VAL_0:.*]]: !fir.ref<f16>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f16>{{.*}}) {41subroutine 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) -> f3244! CHECK: %[[VAL_3:.*]] = math.absf %[[VAL_2_1]] {{.*}}: f3245! CHECK: %[[VAL_3_1:.*]] = fir.convert %[[VAL_3]] : (f32) -> f1646! CHECK: fir.store %[[VAL_3_1]] to %[[VAL_1]] : !fir.ref<f16>47! CHECK: return48  real(kind=2) :: a, b49  b = abs(a)50end subroutine51 52! CHECK-LABEL: func @_QPabs_testb(53! CHECK-SAME:  %[[VAL_0:.*]]: !fir.ref<bf16>{{.*}}, %[[VAL_1:.*]]: !fir.ref<bf16>{{.*}}) {54subroutine 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) -> f3257! CHECK: %[[VAL_3:.*]] = math.absf %[[VAL_2_1]] {{.*}}: f3258! CHECK: %[[VAL_3_1:.*]] = fir.convert %[[VAL_3]] : (f32) -> bf1659! CHECK: fir.store %[[VAL_3_1]] to %[[VAL_1]] : !fir.ref<bf16>60! CHECK: return61  real(kind=3) :: a, b62  b = abs(a)63end subroutine64 65! CHECK-LABEL: func @_QPabs_testr(66! CHECK-SAME:  %[[VAL_0:.*]]: !fir.ref<f32>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f32>{{.*}}) {67subroutine abs_testr(a, b)68! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<f32>69! CHECK: %[[VAL_3:.*]] = math.absf %[[VAL_2]] {{.*}}: f3270! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<f32>71! CHECK: return72  real :: a, b73  b = abs(a)74end subroutine75 76! CHECK-LABEL: func @_QPabs_testd(77! CHECK-SAME:  %[[VAL_0:.*]]: !fir.ref<f64>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f64>{{.*}}) {78subroutine abs_testd(a, b)79! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<f64>80! CHECK: %[[VAL_3:.*]] = math.absf %[[VAL_2]] {{.*}}: f6481! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<f64>82! CHECK: return83  real(kind=8) :: a, b84  b = abs(a)85end subroutine86 87! CHECK-LABEL: func @_QPabs_testr16(88! F128-SAME:  %[[VAL_0:.*]]: !fir.ref<f128>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f128>{{.*}}) {89! F64-SAME:  %[[VAL_0:.*]]: !fir.ref<f64>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f64>{{.*}}) {90subroutine abs_testr16(a, b)91! F128: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<f128>92! F64: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<f64>93! F128: %[[VAL_3:.*]] = math.absf %[[VAL_2]] {{.*}}: f12894! F64: %[[VAL_3:.*]] = math.absf %[[VAL_2]] {{.*}}: f6495! F128: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<f128>96! F64: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<f64>97! CHECK: return98  integer, parameter :: rk = merge(16, 8, selected_real_kind(33, 4931)==16)99  real(kind=rk) :: a, b100  b = abs(a)101end subroutine102 103! CMPLX-LABEL: func @_QPabs_testzr(104! CMPLX-SAME:  %[[VAL_0:.*]]: !fir.ref<complex<f32>>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f32>{{.*}}) {105subroutine abs_testzr(a, b)106! CMPLX:  %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<complex<f32>>107! CMPLX-FAST: %[[VAL_4:.*]] = complex.abs %[[VAL_2]] fastmath<contract> : complex<f32>108! CMPLX-APPROX: %[[VAL_4:.*]] = complex.abs %[[VAL_2]] fastmath<contract,afn> : complex<f32>109! CMPLX-PRECISE:  %[[VAL_4:.*]] = fir.call @cabsf(%[[VAL_2]]) {{.*}}: (complex<f32>) -> f32110! CMPLX:  fir.store %[[VAL_4]] to %[[VAL_1]] : !fir.ref<f32>111! CMPLX:  return112  complex :: a113  real :: b114  b = abs(a)115end subroutine abs_testzr116 117! CMPLX-LABEL: func @_QPabs_testzd(118! CMPLX-SAME:  %[[VAL_0:.*]]: !fir.ref<complex<f64>>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f64>{{.*}}) {119subroutine abs_testzd(a, b)120! CMPLX:  %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<complex<f64>>121! CMPLX-FAST: %[[VAL_4:.*]] = complex.abs %[[VAL_2]] fastmath<contract> : complex<f64>122! CMPLX-APPROX: %[[VAL_4:.*]] = complex.abs %[[VAL_2]] fastmath<contract,afn> : complex<f64>123! CMPLX-PRECISE:  %[[VAL_4:.*]] = fir.call @cabs(%[[VAL_2]]) {{.*}}: (complex<f64>) -> f64124! CMPLX:  fir.store %[[VAL_4]] to %[[VAL_1]] : !fir.ref<f64>125! CMPLX:  return126  complex(kind=8) :: a127  real(kind=8) :: b128  b = abs(a)129end subroutine abs_testzd130