Skip to content

[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 1 commit into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -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">;
Expand Down
17 changes: 17 additions & 0 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 11 additions & 0 deletions mlir/test/Target/LLVMIR/Import/intrinsic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down