Skip to content

Commit 0337510

Browse files
authored
Translate llvm.ldexp.* intrinsics. (#3608)
Add translation for `llvm.ldexp.*` intrinsics which are mapped to OpenCL extended instructions.
1 parent 564a562 commit 0337510

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

lib/SPIRV/SPIRVUtil.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,7 @@ bool checkTypeForSPIRVExtendedInstLowering(IntrinsicInst *II, SPIRVModule *BM) {
19581958
case Intrinsic::fabs:
19591959
case Intrinsic::floor:
19601960
case Intrinsic::fma:
1961+
case Intrinsic::ldexp:
19611962
case Intrinsic::log:
19621963
case Intrinsic::log10:
19631964
case Intrinsic::log2:

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4163,6 +4163,8 @@ static SPIRVWord getBuiltinIdForIntrinsic(Intrinsic::ID IID) {
41634163
return OpenCLLIB::Floor;
41644164
case Intrinsic::fma:
41654165
return OpenCLLIB::Fma;
4166+
case Intrinsic::ldexp:
4167+
return OpenCLLIB::Ldexp;
41664168
case Intrinsic::frexp:
41674169
return OpenCLLIB::Frexp;
41684170
case Intrinsic::log:
@@ -4463,6 +4465,7 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
44634465
// Binary FP intrinsics
44644466
case Intrinsic::atan2:
44654467
case Intrinsic::copysign:
4468+
case Intrinsic::ldexp:
44664469
case Intrinsic::pow:
44674470
case Intrinsic::powi:
44684471
case Intrinsic::maximumnum:

test/llvm-intrinsics/fp-intrinsics.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,17 @@ entry:
482482
}
483483

484484
declare {double, double} @llvm.modf.f64(double)
485+
486+
; CHECK: Function
487+
; CHECK: FunctionParameter {{[0-9]+}} [[x:[0-9]+]]
488+
; CHECK: FunctionParameter {{[0-9]+}} [[exp:[0-9]+]]
489+
; CHECK: ExtInst [[var1]] {{[0-9]+}} [[extinst_id]] ldexp [[x]] [[exp]]
490+
; CHECK: FunctionEnd
491+
492+
define spir_func float @TestLdexp(float %x, i32 %exp) {
493+
entry:
494+
%t = tail call float @llvm.ldexp.f32.i32(float %x, i32 %exp)
495+
ret float %t
496+
}
497+
498+
declare float @llvm.ldexp.f32.i32(float, i32)

0 commit comments

Comments
 (0)