[flang] optimize asind
precision (#154350)
Part of https://github.com/llvm/llvm-project/issues/150452.
This commit is contained in:
parent
a5f1ddd115
commit
a0eb9958eb
@ -2841,10 +2841,11 @@ mlir::Value IntrinsicLibrary::genAsind(mlir::Type resultType,
|
||||
mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
|
||||
mlir::Value result =
|
||||
getRuntimeCallGenerator("asin", ftype)(builder, loc, {args[0]});
|
||||
llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
|
||||
mlir::Value dfactor = builder.createRealConstant(
|
||||
loc, mlir::Float64Type::get(context), llvm::APFloat(180.0) / pi);
|
||||
mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
|
||||
const llvm::fltSemantics &fltSem =
|
||||
llvm::cast<mlir::FloatType>(resultType).getFloatSemantics();
|
||||
llvm::APFloat pi = llvm::APFloat(fltSem, llvm::numbers::pis);
|
||||
mlir::Value factor = builder.createRealConstant(
|
||||
loc, resultType, llvm::APFloat(fltSem, "180.0") / pi);
|
||||
return mlir::arith::MulFOp::create(builder, loc, result, factor);
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
! REQUIRES: flang-supports-f128-math
|
||||
! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s --check-prefixes="CHECK"
|
||||
|
||||
function test_real4(x)
|
||||
@ -6,9 +7,8 @@ function test_real4(x)
|
||||
end function
|
||||
|
||||
! CHECK-LABEL: @_QPtest_real4
|
||||
! CHECK: %[[dfactor:.*]] = arith.constant 57.295779513082323 : f64
|
||||
! CHECK: %[[factor:.*]] = arith.constant 57.2957763 : f32
|
||||
! CHECK: %[[result:.*]] = math.asin %{{.*}} fastmath<contract> : f32
|
||||
! CHECK: %[[factor:.*]] = fir.convert %[[dfactor]] : (f64) -> f32
|
||||
! CHECK: %[[arg:.*]] = arith.mulf %[[result]], %[[factor]] fastmath<contract> : f32
|
||||
|
||||
function test_real8(x)
|
||||
@ -17,6 +17,16 @@ function test_real8(x)
|
||||
end function
|
||||
|
||||
! CHECK-LABEL: @_QPtest_real8
|
||||
! CHECK: %[[dfactor:.*]] = arith.constant 57.295779513082323 : f64
|
||||
! CHECK: %[[factor:.*]] = arith.constant 57.295779513082323 : f64
|
||||
! CHECK: %[[result:.*]] = math.asin %{{.*}} fastmath<contract> : f64
|
||||
! CHECK: %[[arg:.*]] = arith.mulf %[[result]], %[[dfactor]] fastmath<contract> : f64
|
||||
! CHECK: %[[arg:.*]] = arith.mulf %[[result]], %[[factor]] fastmath<contract> : f64
|
||||
|
||||
function test_real16(x)
|
||||
real(16) :: x, test_real16
|
||||
test_real16 = asind(x)
|
||||
end function
|
||||
|
||||
! CHECK-LABEL: @_QPtest_real16
|
||||
! CHECK: %[[factor:.*]] = arith.constant 57.295779513082320876798154814105{{.*}} : f128
|
||||
! CHECK: %[[result:.*]] = fir.call @_FortranAAsinF128({{.*}}) fastmath<contract> : (f128) -> f128
|
||||
! CHECK: %[[arg:.*]] = arith.mulf %[[result]], %[[factor]] fastmath<contract> : f128
|
||||
|
Loading…
x
Reference in New Issue
Block a user