Skip to content

Commit 7215d50

Browse files
authored
[mlir][LLVMIR] Add sinh/cosh/tanh intrinsic ops (#111912)
This revision adds hyperbolic trigonometric sinh, cosh, and tanh intrinsic ops.
1 parent 1cb8314 commit 7215d50

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ def LLVM_SMaxOp : LLVM_BinarySameArgsIntrOpI<"smax">;
166166
def LLVM_SMinOp : LLVM_BinarySameArgsIntrOpI<"smin">;
167167
def LLVM_UMaxOp : LLVM_BinarySameArgsIntrOpI<"umax">;
168168
def LLVM_UMinOp : LLVM_BinarySameArgsIntrOpI<"umin">;
169+
def LLVM_SinhOp : LLVM_UnaryIntrOpF<"sinh">;
170+
def LLVM_CoshOp : LLVM_UnaryIntrOpF<"cosh">;
171+
def LLVM_TanhOp : LLVM_UnaryIntrOpF<"tanh">;
169172

170173
class LLVM_MemcpyIntrOpBase<string name> :
171174
LLVM_ZeroResultIntrOp<name, [0, 1, 2],

mlir/test/Target/LLVMIR/Import/intrinsic.ll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ define void @cos_test(float %0, <8 x float> %1) {
109109
%4 = call <8 x float> @llvm.cos.v8f32(<8 x float> %1)
110110
ret void
111111
}
112+
; CHECK-LABEL: llvm.func @hyperbolic_trig_test
113+
define void @hyperbolic_trig_test(float %0, <8 x float> %1) {
114+
; CHECK: llvm.intr.sinh(%{{.*}}) : (f32) -> f32
115+
%3 = call float @llvm.sinh.f32(float %0)
116+
; CHECK: llvm.intr.sinh(%{{.*}}) : (vector<8xf32>) -> vector<8xf32>
117+
%4 = call <8 x float> @llvm.sinh.v8f32(<8 x float> %1)
118+
119+
; CHECK: llvm.intr.cosh(%{{.*}}) : (f32) -> f32
120+
%5 = call float @llvm.cosh.f32(float %0)
121+
; CHECK: llvm.intr.cosh(%{{.*}}) : (vector<8xf32>) -> vector<8xf32>
122+
%6 = call <8 x float> @llvm.cosh.v8f32(<8 x float> %1)
123+
124+
; CHECK: llvm.intr.tanh(%{{.*}}) : (f32) -> f32
125+
%7 = call float @llvm.tanh.f32(float %0)
126+
; CHECK: llvm.intr.tanh(%{{.*}}) : (vector<8xf32>) -> vector<8xf32>
127+
%8 = call <8 x float> @llvm.tanh.v8f32(<8 x float> %1)
128+
ret void
129+
}
112130

113131
; CHECK-LABEL: llvm.func @copysign_test
114132
define void @copysign_test(float %0, float %1, <8 x float> %2, <8 x float> %3) {
@@ -959,6 +977,12 @@ declare float @llvm.floor.f32(float)
959977
declare <8 x float> @llvm.floor.v8f32(<8 x float>)
960978
declare float @llvm.cos.f32(float)
961979
declare <8 x float> @llvm.cos.v8f32(<8 x float>)
980+
declare float @llvm.sinh.f32(float)
981+
declare <8 x float> @llvm.sinh.v8f32(<8 x float>)
982+
declare float @llvm.cosh.f32(float)
983+
declare <8 x float> @llvm.cosh.v8f32(<8 x float>)
984+
declare float @llvm.tanh.f32(float)
985+
declare <8 x float> @llvm.tanh.v8f32(<8 x float>)
962986
declare float @llvm.copysign.f32(float, float)
963987
declare <8 x float> @llvm.copysign.v8f32(<8 x float>, <8 x float>)
964988
declare float @llvm.pow.f32(float, float)

mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,25 @@ llvm.func @cos_test(%arg0: f32, %arg1: vector<8xf32>) {
112112
llvm.return
113113
}
114114

115+
// CHECK-LABEL: @hyperbolic_trig_test
116+
llvm.func @hyperbolic_trig_test(%arg0: f32, %arg1: vector<8xf32>) {
117+
// CHECK: call float @llvm.sinh.f32
118+
llvm.intr.sinh(%arg0) : (f32) -> f32
119+
// CHECK: call <8 x float> @llvm.sinh.v8f32
120+
llvm.intr.sinh(%arg1) : (vector<8xf32>) -> vector<8xf32>
121+
122+
// CHECK: call float @llvm.cosh.f32
123+
llvm.intr.cosh(%arg0) : (f32) -> f32
124+
// CHECK: call <8 x float> @llvm.cosh.v8f32
125+
llvm.intr.cosh(%arg1) : (vector<8xf32>) -> vector<8xf32>
126+
127+
// CHECK: call float @llvm.tanh.f32
128+
llvm.intr.tanh(%arg0) : (f32) -> f32
129+
// CHECK: call <8 x float> @llvm.tanh.v8f32
130+
llvm.intr.tanh(%arg1) : (vector<8xf32>) -> vector<8xf32>
131+
llvm.return
132+
}
133+
115134
// CHECK-LABEL: @copysign_test
116135
llvm.func @copysign_test(%arg0: f32, %arg1: f32, %arg2: vector<8xf32>, %arg3: vector<8xf32>) {
117136
// CHECK: call float @llvm.copysign.f32

0 commit comments

Comments
 (0)