Skip to content

Commit 372bd07

Browse files
svenvhsys-ce-bb
authored andcommitted
Only require Shader capability if unavoidable (#2141)
Requiring the `Shader` capability for any module that uses `llvm.bitreverse` is problematic for OpenCL execution environments. Only require the `Shader` capability if we cannot use the `BitInstructions` capability. Fixes KhronosGroup/SPIRV-LLVM-Translator#2139 Original commit: KhronosGroup/SPIRV-LLVM-Translator@8701279
1 parent f7d0459 commit 372bd07

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3679,7 +3679,9 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
36793679
return nullptr;
36803680
}
36813681
case Intrinsic::bitreverse: {
3682-
BM->addCapability(CapabilityShader);
3682+
if (!BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_bit_instructions)) {
3683+
BM->addCapability(CapabilityShader);
3684+
}
36833685
SPIRVType *Ty = transType(II->getType());
36843686
SPIRVValue *Op = transValue(II->getArgOperand(0), BB);
36853687
return BM->addUnaryInst(OpBitReverse, Ty, Op, BB);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
3+
; RUN: llvm-spirv %t.bc -spirv-text --spirv-ext=-SPV_KHR_bit_instructions -o %t.txt
4+
; RUN: FileCheck < %t.txt %s --check-prefixes=CHECK-COMMON,CHECK-WITHOUT-EXT
5+
6+
; RUN: llvm-spirv %t.bc -spirv-text --spirv-ext=+SPV_KHR_bit_instructions -o %t.txt
7+
; RUN: FileCheck < %t.txt %s --check-prefixes=CHECK-COMMON,CHECK-WITH-EXT
8+
9+
; CHECK-WITHOUT-EXT: Capability Shader
10+
11+
; CHECK-WITH-EXT-NOT: Capability Shader
12+
; CHECK-WITH-EXT: Capability BitInstructions
13+
; CHECK-WITH-EXT-NOT: Capability Shader
14+
; CHECK-WITH-EXT: Extension "SPV_KHR_bit_instructions"
15+
16+
; CHECK-COMMON: 4 BitReverse
17+
18+
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
19+
target triple = "spir-unknown-unknown"
20+
21+
; Function Attrs: nounwind
22+
define spir_kernel void @TestSatPacked(i32 %0, i32 %1) #0 {
23+
%3 = call i32 @llvm.bitreverse.i32(i32 %0)
24+
ret void
25+
}
26+
27+
declare i32 @llvm.bitreverse.i32(i32) #1
28+
29+
attributes #0 = { nounwind }
30+
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
31+
32+
!spirv.MemoryModel = !{!0}
33+
!spirv.Source = !{!1}
34+
!opencl.spir.version = !{!2}
35+
!opencl.ocl.version = !{!2}
36+
!opencl.used.extensions = !{!3}
37+
!opencl.used.optional.core.features = !{!3}
38+
39+
!0 = !{i32 2, i32 2}
40+
!1 = !{i32 3, i32 102000}
41+
!2 = !{i32 1, i32 2}
42+
!3 = !{}

0 commit comments

Comments
 (0)