[llvm-branch-commits] [flang] [flang] Implement `tanpi` (PR #149527)
@@ -8157,6 +8158,21 @@ mlir::Value IntrinsicLibrary::genTand(mlir::Type
resultType,
return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg});
}
+// TANPI
+mlir::Value IntrinsicLibrary::genTanpi(mlir::Type resultType,
+ llvm::ArrayRef args) {
+ assert(args.size() == 1);
+ mlir::MLIRContext *context = builder.getContext();
+ mlir::FunctionType ftype =
+ mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
+ llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
+ mlir::Value dfactor =
+ builder.createRealConstant(loc, mlir::Float64Type::get(context), pi);
+ mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
c8ef wrote:
Based on our discussion in #149525, I believe this patch is ready to go, too?
My current plan is to first implement the missing trigonometric pi functions,
and then address the constant pi problem. I'll open an issue to track this.
https://github.com/llvm/llvm-project/pull/149527
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang] Implement `tanpi` (PR #149527)
@@ -8157,6 +8158,21 @@ mlir::Value IntrinsicLibrary::genTand(mlir::Type
resultType,
return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg});
}
+// TANPI
+mlir::Value IntrinsicLibrary::genTanpi(mlir::Type resultType,
+ llvm::ArrayRef args) {
+ assert(args.size() == 1);
+ mlir::MLIRContext *context = builder.getContext();
+ mlir::FunctionType ftype =
+ mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
+ llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
+ mlir::Value dfactor =
+ builder.createRealConstant(loc, mlir::Float64Type::get(context), pi);
+ mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
tblah wrote:
See my comment on the other PR. Otherwise this looks okay.
https://github.com/llvm/llvm-project/pull/149527
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang] Implement `tanpi` (PR #149527)
llvmbot wrote:
@llvm/pr-subscribers-flang-semantics
Author: Connector Switch (c8ef)
Changes
---
Full diff: https://github.com/llvm/llvm-project/pull/149527.diff
4 Files Affected:
- (modified) flang/include/flang/Optimizer/Builder/IntrinsicCall.h (+1)
- (modified) flang/lib/Evaluate/intrinsics.cpp (+1)
- (modified) flang/lib/Optimizer/Builder/IntrinsicCall.cpp (+16)
- (added) flang/test/Lower/Intrinsics/tanpi.f90 (+22)
``diff
diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
index d84d3593ebca6..ab08415fe32c8 100644
--- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
@@ -439,6 +439,7 @@ struct IntrinsicLibrary {
mlir::ArrayRef args);
void genSystemClock(llvm::ArrayRef);
mlir::Value genTand(mlir::Type, llvm::ArrayRef);
+ mlir::Value genTanpi(mlir::Type, llvm::ArrayRef);
mlir::Value genTime(mlir::Type, llvm::ArrayRef);
mlir::Value genTrailz(mlir::Type, llvm::ArrayRef);
fir::ExtendedValue genTransfer(mlir::Type,
diff --git a/flang/lib/Evaluate/intrinsics.cpp
b/flang/lib/Evaluate/intrinsics.cpp
index d44239b41fa20..9c6d49dfda3e8 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -989,6 +989,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
{"tan", {{"x", SameFloating}}, SameFloating},
{"tand", {{"x", SameFloating}}, SameFloating},
{"tanh", {{"x", SameFloating}}, SameFloating},
+{"tanpi", {{"x", SameFloating}}, SameFloating},
{"team_number", {OptionalTEAM}, DefaultInt, Rank::scalar,
IntrinsicClass::transformationalFunction},
{"this_image",
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 823b1eb887992..c7758df695db2 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -942,6 +942,7 @@ static constexpr IntrinsicHandler handlers[]{
{{{"count", asAddr}, {"count_rate", asAddr}, {"count_max", asAddr}}},
/*isElemental=*/false},
{"tand", &I::genTand},
+{"tanpi", &I::genTanpi},
{"this_grid", &I::genThisGrid, {}, /*isElemental=*/false},
{"this_thread_block", &I::genThisThreadBlock, {}, /*isElemental=*/false},
{"this_warp", &I::genThisWarp, {}, /*isElemental=*/false},
@@ -8157,6 +8158,21 @@ mlir::Value IntrinsicLibrary::genTand(mlir::Type
resultType,
return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg});
}
+// TANPI
+mlir::Value IntrinsicLibrary::genTanpi(mlir::Type resultType,
+ llvm::ArrayRef args) {
+ assert(args.size() == 1);
+ mlir::MLIRContext *context = builder.getContext();
+ mlir::FunctionType ftype =
+ mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
+ llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
+ mlir::Value dfactor =
+ builder.createRealConstant(loc, mlir::Float64Type::get(context), pi);
+ mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
+ mlir::Value arg = builder.create(loc, args[0], factor);
+ return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg});
+}
+
// THIS_GRID
mlir::Value IntrinsicLibrary::genThisGrid(mlir::Type resultType,
llvm::ArrayRef args) {
diff --git a/flang/test/Lower/Intrinsics/tanpi.f90
b/flang/test/Lower/Intrinsics/tanpi.f90
new file mode 100644
index 0..9cc3ae6ef1563
--- /dev/null
+++ b/flang/test/Lower/Intrinsics/tanpi.f90
@@ -0,0 +1,22 @@
+! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s --check-prefixes="CHECK"
+
+function test_real4(x)
+ real :: x, test_real4
+ test_real4 = tanpi(x)
+end function
+
+! CHECK-LABEL: @_QPtest_real4
+! CHECK: %[[dfactor:.*]] = arith.constant 3.1415926535897931 : f64
+! CHECK: %[[factor:.*]] = fir.convert %[[dfactor]] : (f64) -> f32
+! CHECK: %[[mul:.*]] = arith.mulf %{{.*}}, %[[factor]] fastmath : f32
+! CHECK: %[[tan:.*]] = math.tan %[[mul]] fastmath : f32
+
+function test_real8(x)
+ real(8) :: x, test_real8
+ test_real8 = tanpi(x)
+end function
+
+! CHECK-LABEL: @_QPtest_real8
+! CHECK: %[[dfactor:.*]] = arith.constant 3.1415926535897931 : f64
+! CHECK: %[[mul:.*]] = arith.mulf %{{.*}}, %[[dfactor]] fastmath :
f64
+! CHECK: %[[tan:.*]] = math.tan %[[mul]] fastmath : f64
``
https://github.com/llvm/llvm-project/pull/149527
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang] Implement `tanpi` (PR #149527)
https://github.com/c8ef ready_for_review https://github.com/llvm/llvm-project/pull/149527 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang] Implement `tanpi` (PR #149527)
c8ef wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/149527?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#149527** https://app.graphite.dev/github/pr/llvm/llvm-project/149527?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/149527?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#149525** https://app.graphite.dev/github/pr/llvm/llvm-project/149525?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/149527 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang] Implement `tanpi` (PR #149527)
https://github.com/c8ef edited https://github.com/llvm/llvm-project/pull/149527 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang] Implement tanpi (PR #149527)
https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/149527
None
>From b1c844ef619540c36898b2194f7599f056c80805 Mon Sep 17 00:00:00 2001
From: c8ef
Date: Fri, 18 Jul 2025 15:04:52 +
Subject: [PATCH] [flang] Implement tanpi
---
.../flang/Optimizer/Builder/IntrinsicCall.h | 1 +
flang/lib/Evaluate/intrinsics.cpp | 1 +
flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 16 ++
flang/test/Lower/Intrinsics/tanpi.f90 | 22 +++
4 files changed, 40 insertions(+)
create mode 100644 flang/test/Lower/Intrinsics/tanpi.f90
diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
index d84d3593ebca6..ab08415fe32c8 100644
--- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
@@ -439,6 +439,7 @@ struct IntrinsicLibrary {
mlir::ArrayRef args);
void genSystemClock(llvm::ArrayRef);
mlir::Value genTand(mlir::Type, llvm::ArrayRef);
+ mlir::Value genTanpi(mlir::Type, llvm::ArrayRef);
mlir::Value genTime(mlir::Type, llvm::ArrayRef);
mlir::Value genTrailz(mlir::Type, llvm::ArrayRef);
fir::ExtendedValue genTransfer(mlir::Type,
diff --git a/flang/lib/Evaluate/intrinsics.cpp
b/flang/lib/Evaluate/intrinsics.cpp
index d44239b41fa20..9c6d49dfda3e8 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -989,6 +989,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
{"tan", {{"x", SameFloating}}, SameFloating},
{"tand", {{"x", SameFloating}}, SameFloating},
{"tanh", {{"x", SameFloating}}, SameFloating},
+{"tanpi", {{"x", SameFloating}}, SameFloating},
{"team_number", {OptionalTEAM}, DefaultInt, Rank::scalar,
IntrinsicClass::transformationalFunction},
{"this_image",
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 823b1eb887992..c7758df695db2 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -942,6 +942,7 @@ static constexpr IntrinsicHandler handlers[]{
{{{"count", asAddr}, {"count_rate", asAddr}, {"count_max", asAddr}}},
/*isElemental=*/false},
{"tand", &I::genTand},
+{"tanpi", &I::genTanpi},
{"this_grid", &I::genThisGrid, {}, /*isElemental=*/false},
{"this_thread_block", &I::genThisThreadBlock, {}, /*isElemental=*/false},
{"this_warp", &I::genThisWarp, {}, /*isElemental=*/false},
@@ -8157,6 +8158,21 @@ mlir::Value IntrinsicLibrary::genTand(mlir::Type
resultType,
return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg});
}
+// TANPI
+mlir::Value IntrinsicLibrary::genTanpi(mlir::Type resultType,
+ llvm::ArrayRef args) {
+ assert(args.size() == 1);
+ mlir::MLIRContext *context = builder.getContext();
+ mlir::FunctionType ftype =
+ mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
+ llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
+ mlir::Value dfactor =
+ builder.createRealConstant(loc, mlir::Float64Type::get(context), pi);
+ mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
+ mlir::Value arg = builder.create(loc, args[0], factor);
+ return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg});
+}
+
// THIS_GRID
mlir::Value IntrinsicLibrary::genThisGrid(mlir::Type resultType,
llvm::ArrayRef args) {
diff --git a/flang/test/Lower/Intrinsics/tanpi.f90
b/flang/test/Lower/Intrinsics/tanpi.f90
new file mode 100644
index 0..9cc3ae6ef1563
--- /dev/null
+++ b/flang/test/Lower/Intrinsics/tanpi.f90
@@ -0,0 +1,22 @@
+! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s --check-prefixes="CHECK"
+
+function test_real4(x)
+ real :: x, test_real4
+ test_real4 = tanpi(x)
+end function
+
+! CHECK-LABEL: @_QPtest_real4
+! CHECK: %[[dfactor:.*]] = arith.constant 3.1415926535897931 : f64
+! CHECK: %[[factor:.*]] = fir.convert %[[dfactor]] : (f64) -> f32
+! CHECK: %[[mul:.*]] = arith.mulf %{{.*}}, %[[factor]] fastmath : f32
+! CHECK: %[[tan:.*]] = math.tan %[[mul]] fastmath : f32
+
+function test_real8(x)
+ real(8) :: x, test_real8
+ test_real8 = tanpi(x)
+end function
+
+! CHECK-LABEL: @_QPtest_real8
+! CHECK: %[[dfactor:.*]] = arith.constant 3.1415926535897931 : f64
+! CHECK: %[[mul:.*]] = arith.mulf %{{.*}}, %[[dfactor]] fastmath :
f64
+! CHECK: %[[tan:.*]] = math.tan %[[mul]] fastmath : f64
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
