Skip to content

Commit afa5592

Browse files
MochalovaAnvmaksimo
authored andcommitted
Add llvm.ctpop* intrinsic translation
Add llvm.ctpop.* translation to BitCount instruction Add test for this Signed-off-by: amochalo <anastasiya.mochalova@intel.com>
1 parent 5cd55b4 commit afa5592

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,6 +1964,7 @@ bool LLVMToSPIRV::isKnownIntrinsic(Intrinsic::ID Id) {
19641964
case Intrinsic::fabs:
19651965
case Intrinsic::abs:
19661966
case Intrinsic::ceil:
1967+
case Intrinsic::ctpop:
19671968
case Intrinsic::ctlz:
19681969
case Intrinsic::cttz:
19691970
case Intrinsic::expect:
@@ -2097,6 +2098,10 @@ SPIRVValue *LLVMToSPIRV::transIntrinsicInst(IntrinsicInst *II,
20972098
return BM->addExtInst(STy, BM->getExtInstSetId(SPIRVEIS_OpenCL), ExtOp, Ops,
20982099
BB);
20992100
}
2101+
case Intrinsic::ctpop: {
2102+
return BM->addUnaryInst(OpBitCount, transType(II->getType()),
2103+
transValue(II->getArgOperand(0), BB), BB);
2104+
}
21002105
case Intrinsic::ctlz:
21012106
case Intrinsic::cttz: {
21022107
SPIRVWord ExtOp = II->getIntrinsicID() == Intrinsic::ctlz ? OpenCLLIB::Clz

llvm-spirv/test/ctpop.ll

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s
3+
; RUN: llvm-spirv %t.bc -o %t.spv
4+
; RUN: spirv-val %t.spv
5+
6+
7+
; CHECK: BitCount {{[0-9]+}} {{[0-9]+}} {{[0-9]+}}
8+
; CHECK: BitCount {{[0-9]+}} {{[0-9]+}} {{[0-9]+}}
9+
; CHECK: BitCount {{[0-9]+}} {{[0-9]+}} {{[0-9]+}}
10+
; CHECK: BitCount {{[0-9]+}} {{[0-9]+}} {{[0-9]+}}
11+
; CHECK: BitCount {{[0-9]+}} {{[0-9]+}} {{[0-9]+}}
12+
13+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
14+
target triple = "spir64-unknown-linux-sycldevice"
15+
16+
; Function Attrs: norecurse nounwind readnone
17+
define dso_local spir_kernel void @test(i8 %x8, i16 %x16, i32 %x32, i64 %x64, <2 x i32> %x2i32) local_unnamed_addr #0 !kernel_arg_buffer_location !5 {
18+
entry:
19+
%0 = tail call i8 @llvm.ctpop.i8(i8 %x8) #2
20+
%1 = tail call i16 @llvm.ctpop.i16(i16 %x16) #2
21+
%2 = tail call i32 @llvm.ctpop.i32(i32 %x32) #2
22+
%3 = tail call i64 @llvm.ctpop.i64(i64 %x64) #2
23+
%4 = tail call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %x2i32) #2
24+
ret void
25+
}
26+
27+
; Function Attrs: inaccessiblememonly nounwind willreturn
28+
declare i8 @llvm.ctpop.i8(i8 ) #1
29+
30+
; Function Attrs: inaccessiblememonly nounwind willreturn
31+
declare i16 @llvm.ctpop.i16(i16 ) #1
32+
33+
; Function Attrs: inaccessiblememonly nounwind willreturn
34+
declare i32 @llvm.ctpop.i32(i32 ) #1
35+
36+
; Function Attrs: inaccessiblememonly nounwind willreturn
37+
declare i64 @llvm.ctpop.i64(i64 ) #1
38+
39+
; Function Attrs: inaccessiblememonly nounwind willreturn
40+
declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> ) #1
41+
42+
attributes #0 = { norecurse nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-module-id"="test.cl" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" }
43+
44+
!llvm.module.flags = !{!0}
45+
!opencl.ocl.version = !{!1}
46+
!opencl.spir.version = !{!2, !2}
47+
!spirv.Source = !{!3}
48+
!llvm.ident = !{!4}
49+
50+
!0 = !{i32 1, !"wchar_size", i32 4}
51+
!1 = !{i32 1, i32 0}
52+
!2 = !{i32 1, i32 2}
53+
!3 = !{i32 4, i32 100000}
54+
!4 = !{!"clang version 12.0.0 (https://github.com/c199914007/llvm.git 0051629b5f4d81af1b049da17bce0b00f03998f8)"}
55+
!5 = !{i32 -1}

0 commit comments

Comments
 (0)