-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][llvmir] add llvm.sincos intrinsics #133311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Letu Ren <[email protected]>
@llvm/pr-subscribers-mlir-llvm @llvm/pr-subscribers-mlir Author: Letu Ren (FantasqueX) Changeshttps://llvm.org/docs/LangRef.html#llvm-frexp-intrinsic Full diff: https://github.com/llvm/llvm-project/pull/133311.diff 4 Files Affected:
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
index dfb35228cbd29..7cd9138eb2a98 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
@@ -121,7 +121,15 @@ def LLVM_CopySignOp : LLVM_BinarySameArgsIntrOpF<"copysign">;
def LLVM_ExpOp : LLVM_UnaryIntrOpF<"exp">;
def LLVM_Exp2Op : LLVM_UnaryIntrOpF<"exp2">;
def LLVM_Exp10Op : LLVM_UnaryIntrOpF<"exp10">;
-def LLVM_LoadExpOp: LLVM_PowFI<"ldexp">;
+def LLVM_LoadExpOp : LLVM_PowFI<"ldexp">;
+def LLVM_FractionExpOp : LLVM_TwoResultIntrOp<"frexp", [0, 1], [],
+ [Pure], /*requiresFastmath=*/1> {
+ let arguments =
+ (ins LLVM_ScalarOrVectorOf<LLVM_AnyFloat>:$val,
+ DefaultValuedAttr<LLVM_FastmathFlagsAttr, "{}">:$fastmathFlags);
+ let assemblyFormat = "`(` operands `)` attr-dict `:` "
+ "functional-type(operands, results)";
+}
def LLVM_FAbsOp : LLVM_UnaryIntrOpF<"fabs">;
def LLVM_FCeilOp : LLVM_UnaryIntrOpF<"ceil">;
def LLVM_FFloorOp : LLVM_UnaryIntrOpF<"floor">;
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
index cdb5ab5220e4f..1fa1d3be557db 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
@@ -448,6 +448,23 @@ class LLVM_OneResultIntrOp<string mnem, list<int> overloadedResults = [],
requiresFastmath, /*requiresOpBundles=*/0, immArgPositions,
immArgAttrNames>;
+// Base class for LLVM intrinsic operations returning two results. Places the
+// intrinsic into the LLVM dialect and prefixes its name with "intr.". This is
+// similar to LLVM_ZeroResultIntrOp but allows one to define Ops returning two
+// results. Additionally, the overloadedResults list should contain "0", "1"
+// if the result must be used to resolve overloaded intrinsics, or remain
+// empty otherwise.
+class LLVM_TwoResultIntrOp<string mnem, list<int> overloadedResults = [],
+ list<int> overloadedOperands = [],
+ list<Trait> traits = [],
+ bit requiresFastmath = 0,
+ list<int> immArgPositions = [],
+ list<string> immArgAttrNames = []>
+ : LLVM_IntrOp<mnem, overloadedResults, overloadedOperands, traits, 2,
+ /*requiresAccessGroup=*/0, /*requiresAliasAnalysis=*/0,
+ requiresFastmath, /*requiresOpBundles=*/0, immArgPositions,
+ immArgAttrNames>;
+
def LLVM_OneResultOpBuilder :
OpBuilder<(ins "Type":$resultType, "ValueRange":$operands,
CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes),
diff --git a/mlir/test/Target/LLVMIR/Import/intrinsic.ll b/mlir/test/Target/LLVMIR/Import/intrinsic.ll
index 02fea85b028b3..eeeb0194f10a3 100644
--- a/mlir/test/Target/LLVMIR/Import/intrinsic.ll
+++ b/mlir/test/Target/LLVMIR/Import/intrinsic.ll
@@ -60,6 +60,15 @@ define void @ldexp_test(float %0, <8 x float> %1, i32 %2) {
ret void
}
+; CHECK-LABEL: llvm.func @frexp_test
+define void @frexp_test(float %0, <8 x float> %1) {
+ ; CHECK: llvm.intr.frexp(%{{.*}}) : (f32) -> !llvm.struct<(f32, i32)>
+ %4 = call { float, i32 } @llvm.frexp.f32.i32(float %0)
+ ; CHECK: llvm.intr.frexp(%{{.*}}) : (vector<8xf32>) -> !llvm.struct<(vector<8xf32>, i32)>
+ %5 = call { <8 x float>, i32 } @llvm.frexp.v8f32.i32(<8 x float> %1)
+ ret void
+}
+
; CHECK-LABEL: llvm.func @log_test
define void @log_test(float %0, <8 x float> %1) {
; CHECK: llvm.intr.log(%{{.*}}) : (f32) -> f32
@@ -1088,6 +1097,8 @@ declare float @llvm.exp10.f32(float)
declare <8 x float> @llvm.exp10.v8f32(<8 x float>)
declare float @llvm.ldexp.f32.i32(float, i32)
declare <8 x float> @llvm.ldexp.v8f32.i32(<8 x float>, i32)
+declare { float, i32 } @llvm.frexp.f32.i32(float)
+declare { <8 x float>, i32 } @llvm.frexp.v8f32.i32(<8 x float>)
declare float @llvm.log.f32(float)
declare <8 x float> @llvm.log.v8f32(<8 x float>)
declare float @llvm.log10.f32(float)
diff --git a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
index d33f99d44eb88..271c0090e1869 100644
--- a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
@@ -58,6 +58,15 @@ llvm.func @ldexp_test(%arg0: f32, %arg1: vector<8xf32>, %arg2: i32) {
llvm.return
}
+// CHECK-LABEL: @frexp_test
+llvm.func @frexp_test(%arg0: f32, %arg1: vector<8xf32>) {
+ // CHECK: call { float, i32 } @llvm.frexp.f32.i32(float %{{.*}})
+ llvm.intr.frexp(%arg0) : (f32) -> !llvm.struct<(f32, i32)>
+ // CHECK: call { <8 x float>, i32 } @llvm.frexp.v8f32.i32(<8 x float> %{{.*}})
+ llvm.intr.frexp(%arg1) : (vector<8xf32>) -> !llvm.struct<(vector<8xf32>, i32)>
+ llvm.return
+}
+
// CHECK-LABEL: @log_test
llvm.func @log_test(%arg0: f32, %arg1: vector<8xf32>) {
// CHECK: call float @llvm.log.f32
@@ -1195,6 +1204,14 @@ llvm.func @experimental_constrained_fpext(%s: f32, %v: vector<4xf32>) {
// CHECK-DAG: declare i1 @llvm.is.fpclass.f32(float, i32 immarg)
// CHECK-DAG: declare float @llvm.exp.f32(float)
// CHECK-DAG: declare <8 x float> @llvm.exp.v8f32(<8 x float>) #0
+// CHECK-DAG: declare float @llvm.exp2.f32(float)
+// CHECK-DAG: declare <8 x float> @llvm.exp2.v8f32(<8 x float>)
+// CHECK-DAG: declare float @llvm.exp10.f32(float)
+// CHECK-DAG: declare <8 x float> @llvm.exp10.v8f32(<8 x float>)
+// CHECK-DAG: declare float @llvm.ldexp.f32.i32(float, i32)
+// CHECK-DAG: declare <8 x float> @llvm.ldexp.v8f32.i32(<8 x float>, i32)
+// CHECK-DAG: declare { float, i32 } @llvm.frexp.f32.i32(float)
+// CHECK-DAG: declare { <8 x float>, i32 } @llvm.frexp.v8f32.i32(<8 x float>)
// CHECK-DAG: declare float @llvm.log.f32(float)
// CHECK-DAG: declare <8 x float> @llvm.log.v8f32(<8 x float>) #0
// CHECK-DAG: declare float @llvm.log10.f32(float)
|
gysit
approved these changes
Mar 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
LGTM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://llvm.org/docs/LangRef.html#llvm-frexp-intrinsic