Skip to content

Commit 3de3ce1

Browse files
bwlodarczjsji
authored andcommitted
Add support for llvm.lround.* (#2904)
Original commit: KhronosGroup/SPIRV-LLVM-Translator@8ef84d23d874791
1 parent 6387666 commit 3de3ce1

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4220,6 +4220,14 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
42204220
return BM->addExtInst(STy, BM->getExtInstSetId(SPIRVEIS_OpenCL), ExtOp, Ops,
42214221
BB);
42224222
}
4223+
case Intrinsic::lround: {
4224+
SPIRVType *SourceTy = transType(II->getArgOperand(0)->getType());
4225+
SPIRVType *DestTy = transType(II->getType());
4226+
SPIRVValue *Rounded = BM->addExtInst(
4227+
SourceTy, BM->getExtInstSetId(SPIRVEIS_OpenCL), OpenCLLIB::Round,
4228+
{transValue(II->getArgOperand(0), BB)}, BB);
4229+
return BM->addUnaryInst(OpConvertFToS, DestTy, Rounded, BB);
4230+
}
42234231
case Intrinsic::frexp: {
42244232
if (!checkTypeForSPIRVExtendedInstLowering(II, BM))
42254233
break;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; REQUIRES: spirv-dis
2+
; RUN: llvm-as %s -o %t.bc
3+
; RUN: llvm-spirv %t.bc -o %t.spv
4+
; RUN: spirv-dis --raw-id %t.spv | FileCheck --check-prefix CHECK-SPIRV %s
5+
; RUN: spirv-val %t.spv
6+
7+
; CHECK-SPIRV: [[opencl:%[0-9]+]] = OpExtInstImport "OpenCL.std"
8+
; CHECK-SPIRV-DAG: [[i32:%[0-9]+]] = OpTypeInt 32 0
9+
; CHECK-SPIRV-DAG: [[i64:%[0-9]+]] = OpTypeInt 64 0
10+
; CHECK-SPIRV-DAG: [[f32:%[0-9]+]] = OpTypeFloat 32
11+
; CHECK-SPIRV-DAG: [[f64:%[0-9]+]] = OpTypeFloat 64
12+
; CHECK-SPIRV: [[rounded_f32:%[0-9]+]] = OpExtInst [[f32]] [[opencl]] round
13+
; CHECK-SPIRV: OpConvertFToS [[i32]] [[rounded_f32]]
14+
; CHECK-SPIRV: [[rounded_f64:%[0-9]+]] = OpExtInst [[f64]] [[opencl]] round
15+
; CHECK-SPIRV: OpConvertFToS [[i64]] [[rounded_f64]]
16+
17+
target triple = "spir64-unknown-unknown"
18+
19+
define spir_func i32 @test_0(float %arg0) {
20+
entry:
21+
%0 = call i32 @llvm.lround.i32.f32(float %arg0)
22+
ret i32 %0
23+
}
24+
25+
define spir_func i64 @test_1(double %arg0) {
26+
entry:
27+
%0 = call i64 @llvm.lround.i64.f64(double %arg0)
28+
ret i64 %0
29+
}
30+
31+
declare i32 @llvm.lround.i32.f32(float)
32+
declare i64 @llvm.lround.i64.f64(double)

0 commit comments

Comments
 (0)