diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp index 22193f0de88a..bc3086e28f75 100644 --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -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(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); } diff --git a/flang/test/Lower/Intrinsics/asind.f90 b/flang/test/Lower/Intrinsics/asind.f90 index 564fa955fa96..8d6198f53e4b 100644 --- a/flang/test/Lower/Intrinsics/asind.f90 +++ b/flang/test/Lower/Intrinsics/asind.f90 @@ -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 : f32 -! CHECK: %[[factor:.*]] = fir.convert %[[dfactor]] : (f64) -> f32 ! CHECK: %[[arg:.*]] = arith.mulf %[[result]], %[[factor]] fastmath : 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 : f64 -! CHECK: %[[arg:.*]] = arith.mulf %[[result]], %[[dfactor]] fastmath : f64 +! CHECK: %[[arg:.*]] = arith.mulf %[[result]], %[[factor]] fastmath : 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 : (f128) -> f128 +! CHECK: %[[arg:.*]] = arith.mulf %[[result]], %[[factor]] fastmath : f128