Skip to content

Commit 5400893

Browse files
author
git apple-llvm automerger
committed
Merge commit '465f2f649a1f' from llvm.org/main into next
2 parents 1eafacb + 465f2f6 commit 5400893

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8192,10 +8192,11 @@ mlir::Value IntrinsicLibrary::genSind(mlir::Type resultType,
81928192
mlir::MLIRContext *context = builder.getContext();
81938193
mlir::FunctionType ftype =
81948194
mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
8195-
llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
8196-
mlir::Value dfactor = builder.createRealConstant(
8197-
loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0));
8198-
mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
8195+
const llvm::fltSemantics &fltSem =
8196+
llvm::cast<mlir::FloatType>(resultType).getFloatSemantics();
8197+
llvm::APFloat pi = llvm::APFloat(fltSem, llvm::numbers::pis);
8198+
mlir::Value factor = builder.createRealConstant(
8199+
loc, resultType, pi / llvm::APFloat(fltSem, "180.0"));
81998200
mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor);
82008201
return getRuntimeCallGenerator("sin", ftype)(builder, loc, {arg});
82018202
}

flang/test/Lower/Intrinsics/sind.f90

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
! REQUIRES: flang-supports-f128-math
12
! RUN: bbc -emit-fir %s -o - | FileCheck %s --check-prefixes="CHECK,CHECK-FAST"
23
! RUN: bbc --math-runtime=precise -emit-fir %s -o - | FileCheck %s --check-prefixes="CHECK,CHECK-PRECISE"
34
! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s --check-prefixes="CHECK,CHECK-FAST"
@@ -8,8 +9,7 @@ function test_real4(x)
89
end function
910

1011
! CHECK-LABEL: @_QPtest_real4
11-
! CHECK: %[[dfactor:.*]] = arith.constant 0.017453292519943295 : f64
12-
! CHECK: %[[factor:.*]] = fir.convert %[[dfactor]] : (f64) -> f32
12+
! CHECK: %[[factor:.*]] = arith.constant 0.0174532924 : f32
1313
! CHECK: %[[arg:.*]] = arith.mulf %{{[A-Za-z0-9._]+}}, %[[factor]] fastmath<contract> : f32
1414
! CHECK-PRECISE: %{{.*}} = fir.call @sinf(%[[arg]]) fastmath<contract> : (f32) -> f32
1515
! CHECK-FAST: %{{.*}} = math.sin %[[arg]] fastmath<contract> : f32
@@ -24,3 +24,13 @@ function test_real8(x)
2424
! CHECK: %[[arg:.*]] = arith.mulf %{{[A-Za-z0-9._]+}}, %[[factor]] fastmath<contract> : f64
2525
! CHECK-PRECISE: %{{.*}} = fir.call @sin(%[[arg]]) fastmath<contract> : (f64) -> f64
2626
! CHECK-FAST: %{{.*}} = math.sin %[[arg]] fastmath<contract> : f64
27+
28+
function test_real16(x)
29+
real(16) :: x, test_real16
30+
test_real16 = sind(x)
31+
end function
32+
33+
! CHECK-LABEL: @_QPtest_real16
34+
! CHECK: %[[factor:.*]] = arith.constant 0.0174532925199432957692369076848861{{.*}} : f128
35+
! CHECK: %[[arg:.*]] = arith.mulf %{{[A-Za-z0-9._]+}}, %[[factor]] fastmath<contract> : f128
36+
! CHECK: %[[result:.*]] = fir.call @_FortranASinF128({{.*}}) fastmath<contract> : (f128) -> f128

0 commit comments

Comments
 (0)