Skip to content

Commit 9479076

Browse files
linehillsys-ce-bb
authored andcommitted
Add translation for Intrinsic::{atan,acos,asin,cosh,sinh,tanh} (#2657)
Add translation for atan, acos, asin, cosh, sinh and tanh LLVM intrinsics which are mapped to corresponding OpenCL extended instructions. Original commit: KhronosGroup/SPIRV-LLVM-Translator@95605477e7fe635
1 parent e7bfe86 commit 9479076

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVUtil.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,9 +1848,13 @@ std::string decodeSPIRVTypeName(StringRef Name,
18481848
// Returns true if type(s) and number of elements (if vector) is valid
18491849
bool checkTypeForSPIRVExtendedInstLowering(IntrinsicInst *II, SPIRVModule *BM) {
18501850
switch (II->getIntrinsicID()) {
1851+
case Intrinsic::acos:
1852+
case Intrinsic::asin:
1853+
case Intrinsic::atan:
18511854
case Intrinsic::ceil:
18521855
case Intrinsic::copysign:
18531856
case Intrinsic::cos:
1857+
case Intrinsic::cosh:
18541858
case Intrinsic::exp:
18551859
case Intrinsic::exp2:
18561860
case Intrinsic::fabs:
@@ -1870,8 +1874,10 @@ bool checkTypeForSPIRVExtendedInstLowering(IntrinsicInst *II, SPIRVModule *BM) {
18701874
case Intrinsic::round:
18711875
case Intrinsic::roundeven:
18721876
case Intrinsic::sin:
1877+
case Intrinsic::sinh:
18731878
case Intrinsic::sqrt:
18741879
case Intrinsic::tan:
1880+
case Intrinsic::tanh:
18751881
case Intrinsic::trunc: {
18761882
// Although some of the intrinsics above take multiple arguments, it is
18771883
// sufficient to check arg 0 because the LLVM Verifier will have checked

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,12 +3885,20 @@ static SPIRVWord getBuiltinIdForIntrinsic(Intrinsic::ID IID) {
38853885
// and assume that the operations have no side effects (FP status flags
38863886
// aren't maintained), so the OpenCL builtin behavior should be
38873887
// acceptable.
3888+
case Intrinsic::acos:
3889+
return OpenCLLIB::Acos;
3890+
case Intrinsic::asin:
3891+
return OpenCLLIB::Asin;
3892+
case Intrinsic::atan:
3893+
return OpenCLLIB::Atan;
38883894
case Intrinsic::ceil:
38893895
return OpenCLLIB::Ceil;
38903896
case Intrinsic::copysign:
38913897
return OpenCLLIB::Copysign;
38923898
case Intrinsic::cos:
38933899
return OpenCLLIB::Cos;
3900+
case Intrinsic::cosh:
3901+
return OpenCLLIB::Cosh;
38943902
case Intrinsic::exp:
38953903
return OpenCLLIB::Exp;
38963904
case Intrinsic::exp2:
@@ -3931,10 +3939,14 @@ static SPIRVWord getBuiltinIdForIntrinsic(Intrinsic::ID IID) {
39313939
return OpenCLLIB::Rint;
39323940
case Intrinsic::sin:
39333941
return OpenCLLIB::Sin;
3942+
case Intrinsic::sinh:
3943+
return OpenCLLIB::Sinh;
39343944
case Intrinsic::sqrt:
39353945
return OpenCLLIB::Sqrt;
39363946
case Intrinsic::tan:
39373947
return OpenCLLIB::Tan;
3948+
case Intrinsic::tanh:
3949+
return OpenCLLIB::Tanh;
39383950
case Intrinsic::trunc:
39393951
return OpenCLLIB::Trunc;
39403952
default:
@@ -4067,8 +4079,12 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
40674079
}
40684080

40694081
// Unary FP intrinsic
4082+
case Intrinsic::acos:
4083+
case Intrinsic::asin:
4084+
case Intrinsic::atan:
40704085
case Intrinsic::ceil:
40714086
case Intrinsic::cos:
4087+
case Intrinsic::cosh:
40724088
case Intrinsic::exp:
40734089
case Intrinsic::exp2:
40744090
case Intrinsic::fabs:
@@ -4081,8 +4097,10 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
40814097
case Intrinsic::round:
40824098
case Intrinsic::roundeven:
40834099
case Intrinsic::sin:
4100+
case Intrinsic::sinh:
40844101
case Intrinsic::sqrt:
40854102
case Intrinsic::tan:
4103+
case Intrinsic::tanh:
40864104
case Intrinsic::trunc: {
40874105
if (!checkTypeForSPIRVExtendedInstLowering(II, BM))
40884106
break;

llvm-spirv/test/llvm-intrinsics/fp-intrinsics.ll

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,81 @@ entry:
344344
}
345345

346346
declare float @llvm.fma.f32(float, float, float)
347+
348+
; CHECK: Function
349+
; CHECK: FunctionParameter {{[0-9]+}} [[x:[0-9]+]]
350+
; CHECK: ExtInst [[var1]] {{[0-9]+}} [[extinst_id]] acos [[x]]
351+
; CHECK: FunctionEnd
352+
353+
define spir_func float @TestAcos(float %x) {
354+
entry:
355+
%t = tail call float @llvm.acos.f32(float %x)
356+
ret float %t
357+
}
358+
359+
declare float @llvm.acos.f32(float)
360+
361+
; CHECK: Function
362+
; CHECK: FunctionParameter {{[0-9]+}} [[x:[0-9]+]]
363+
; CHECK: ExtInst [[var1]] {{[0-9]+}} [[extinst_id]] asin [[x]]
364+
; CHECK: FunctionEnd
365+
366+
define spir_func float @TestAsin(float %x) {
367+
entry:
368+
%t = tail call float @llvm.asin.f32(float %x)
369+
ret float %t
370+
}
371+
372+
declare float @llvm.asin.f32(float)
373+
374+
; CHECK: Function
375+
; CHECK: FunctionParameter {{[0-9]+}} [[x:[0-9]+]]
376+
; CHECK: ExtInst [[var1]] {{[0-9]+}} [[extinst_id]] atan [[x]]
377+
; CHECK: FunctionEnd
378+
379+
define spir_func float @TestAtan(float %x) {
380+
entry:
381+
%t = tail call float @llvm.atan.f32(float %x)
382+
ret float %t
383+
}
384+
385+
declare float @llvm.atan.f32(float)
386+
387+
; CHECK: Function
388+
; CHECK: FunctionParameter {{[0-9]+}} [[x:[0-9]+]]
389+
; CHECK: ExtInst [[var1]] {{[0-9]+}} [[extinst_id]] cosh [[x]]
390+
; CHECK: FunctionEnd
391+
392+
define spir_func float @TestCosh(float %x) {
393+
entry:
394+
%t = tail call float @llvm.cosh.f32(float %x)
395+
ret float %t
396+
}
397+
398+
declare float @llvm.cosh.f32(float)
399+
400+
; CHECK: Function
401+
; CHECK: FunctionParameter {{[0-9]+}} [[x:[0-9]+]]
402+
; CHECK: ExtInst [[var1]] {{[0-9]+}} [[extinst_id]] sinh [[x]]
403+
; CHECK: FunctionEnd
404+
405+
define spir_func float @TestSinh(float %x) {
406+
entry:
407+
%t = tail call float @llvm.sinh.f32(float %x)
408+
ret float %t
409+
}
410+
411+
declare float @llvm.sinh.f32(float)
412+
413+
; CHECK: Function
414+
; CHECK: FunctionParameter {{[0-9]+}} [[x:[0-9]+]]
415+
; CHECK: ExtInst [[var1]] {{[0-9]+}} [[extinst_id]] tanh [[x]]
416+
; CHECK: FunctionEnd
417+
418+
define spir_func float @TestTanh(float %x) {
419+
entry:
420+
%t = tail call float @llvm.tanh.f32(float %x)
421+
ret float %t
422+
}
423+
424+
declare float @llvm.tanh.f32(float)

0 commit comments

Comments
 (0)