Skip to content

Commit 7cfad02

Browse files
committed
Add test and enable SPV_KHR_bit_instructions
1 parent 86375a2 commit 7cfad02

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ void SPIRV::RequirementHandler::checkSatisfiable(
506506
for (auto Ext : AllExtensions) {
507507
if (ST.canUseExtension(Ext))
508508
continue;
509-
LLVM_DEBUG(dbgs() << "Extension not suported: "
509+
LLVM_DEBUG(dbgs() << "Extension not supported: "
510510
<< getSymbolicOperandMnemonic(
511511
OperandCategory::ExtensionOperand, Ext)
512512
<< "\n");
@@ -745,7 +745,12 @@ void addInstrRequirements(const MachineInstr &MI,
745745
case SPIRV::OpBitFieldInsert:
746746
case SPIRV::OpBitFieldSExtract:
747747
case SPIRV::OpBitFieldUExtract:
748+
if (!ST.canUseExtension(SPIRV::Extension::SPV_KHR_bit_instructions)) {
749+
Reqs.addCapability(SPIRV::Capability::Shader);
750+
break;
751+
}
748752
Reqs.addExtension(SPIRV::Extension::SPV_KHR_bit_instructions);
753+
Reqs.addCapability(SPIRV::Capability::BitInstructions);
749754
break;
750755
case SPIRV::OpTypeRuntimeArray:
751756
Reqs.addCapability(SPIRV::Capability::Shader);

llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ cl::list<SPIRV::Extension::Extension> Extensions(
4141
clEnumValN(SPIRV::Extension::SPV_KHR_no_integer_wrap_decoration,
4242
"SPV_KHR_no_integer_wrap_decoration",
4343
"Adds decorations to indicate that a given instruction does "
44-
"not cause integer wrapping")));
44+
"not cause integer wrapping"),
45+
clEnumValN(SPIRV::Extension::SPV_KHR_bit_instructions,
46+
"SPV_KHR_bit_instructions",
47+
"This enables bit instructions to be used by SPIR-V modules "
48+
"without the requiring the Shader capability")));
4549

4650
// Compare version numbers, but allow 0 to mean unspecified.
4751
static bool isAtLeastVer(uint32_t Target, uint32_t VerToCompareTo) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s --spirv-extensions=SPV_KHR_bit_instructions -o - | FileCheck %s --check-prefix=CHECK-EXTENSION
2+
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-NO-EXTENSION
3+
4+
; CHECK-EXTENSION: OpCapability BitInstructions
5+
; CHECK-EXTENSION-NEXT: OpExtension "SPV_KHR_bit_instructions"
6+
; CHECK-EXTENSION-NOT: OpCabilitity Shader
7+
; CHECK-NO-EXTENSION: OpCapability Shader
8+
; CHECK-NO-EXTENSION-NOT: OpCabilitity BitInstructions
9+
; CHECK-NO-EXTENSION-NOT: OpExtension "SPV_KHR_bit_instructions"
10+
11+
12+
; CHECK-EXTENSION: %[[#int:]] = OpTypeInt 32
13+
; CHECK-EXTENSION: OpBitReverse %[[#int]]
14+
; CHECK-NO-EXTENSION: %[[#int:]] = OpTypeInt 32
15+
; CHECK-NO-EXTENSION: OpBitReverse %[[#int]]
16+
17+
define spir_kernel void @testBitRev(i32 %a, i32 %b, i32 %c, i32 addrspace(1)* nocapture %res) local_unnamed_addr {
18+
entry:
19+
%call = tail call i32 @llvm.bitreverse.i32(i32 %b)
20+
store i32 %call, i32 addrspace(1)* %res, align 4
21+
ret void
22+
}
23+
24+
declare i32 @llvm.bitreverse.i32(i32)

llvm/test/CodeGen/SPIRV/transcoding/OpBitReverse_i32.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
22

3-
; CHECK-SPIRV: OpCapability BitInstructions
4-
; CHECK-SPIRV-NEXT: OpExtension "SPV_KHR_bit_instructions"
5-
63
; CHECK-SPIRV: %[[#int:]] = OpTypeInt 32
74
; CHECK-SPIRV: OpBitReverse %[[#int]]
85

0 commit comments

Comments
 (0)