Skip to content

Commit

Permalink
Add test and enable SPV_KHR_bit_instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
pmatos committed Sep 20, 2023
1 parent 86375a2 commit 7cfad02
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
7 changes: 6 additions & 1 deletion llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ void SPIRV::RequirementHandler::checkSatisfiable(
for (auto Ext : AllExtensions) {
if (ST.canUseExtension(Ext))
continue;
LLVM_DEBUG(dbgs() << "Extension not suported: "
LLVM_DEBUG(dbgs() << "Extension not supported: "
<< getSymbolicOperandMnemonic(
OperandCategory::ExtensionOperand, Ext)
<< "\n");
Expand Down Expand Up @@ -745,7 +745,12 @@ void addInstrRequirements(const MachineInstr &MI,
case SPIRV::OpBitFieldInsert:
case SPIRV::OpBitFieldSExtract:
case SPIRV::OpBitFieldUExtract:
if (!ST.canUseExtension(SPIRV::Extension::SPV_KHR_bit_instructions)) {
Reqs.addCapability(SPIRV::Capability::Shader);
break;
}
Reqs.addExtension(SPIRV::Extension::SPV_KHR_bit_instructions);
Reqs.addCapability(SPIRV::Capability::BitInstructions);
break;
case SPIRV::OpTypeRuntimeArray:
Reqs.addCapability(SPIRV::Capability::Shader);
Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ cl::list<SPIRV::Extension::Extension> Extensions(
clEnumValN(SPIRV::Extension::SPV_KHR_no_integer_wrap_decoration,
"SPV_KHR_no_integer_wrap_decoration",
"Adds decorations to indicate that a given instruction does "
"not cause integer wrapping")));
"not cause integer wrapping"),
clEnumValN(SPIRV::Extension::SPV_KHR_bit_instructions,
"SPV_KHR_bit_instructions",
"This enables bit instructions to be used by SPIR-V modules "
"without the requiring the Shader capability")));

// Compare version numbers, but allow 0 to mean unspecified.
static bool isAtLeastVer(uint32_t Target, uint32_t VerToCompareTo) {
Expand Down
24 changes: 24 additions & 0 deletions llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_bit_instructions.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s --spirv-extensions=SPV_KHR_bit_instructions -o - | FileCheck %s --check-prefix=CHECK-EXTENSION
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-NO-EXTENSION

; CHECK-EXTENSION: OpCapability BitInstructions
; CHECK-EXTENSION-NEXT: OpExtension "SPV_KHR_bit_instructions"
; CHECK-EXTENSION-NOT: OpCabilitity Shader
; CHECK-NO-EXTENSION: OpCapability Shader
; CHECK-NO-EXTENSION-NOT: OpCabilitity BitInstructions
; CHECK-NO-EXTENSION-NOT: OpExtension "SPV_KHR_bit_instructions"


; CHECK-EXTENSION: %[[#int:]] = OpTypeInt 32
; CHECK-EXTENSION: OpBitReverse %[[#int]]
; CHECK-NO-EXTENSION: %[[#int:]] = OpTypeInt 32
; CHECK-NO-EXTENSION: OpBitReverse %[[#int]]

define spir_kernel void @testBitRev(i32 %a, i32 %b, i32 %c, i32 addrspace(1)* nocapture %res) local_unnamed_addr {
entry:
%call = tail call i32 @llvm.bitreverse.i32(i32 %b)
store i32 %call, i32 addrspace(1)* %res, align 4
ret void
}

declare i32 @llvm.bitreverse.i32(i32)
3 changes: 0 additions & 3 deletions llvm/test/CodeGen/SPIRV/transcoding/OpBitReverse_i32.ll
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV

; CHECK-SPIRV: OpCapability BitInstructions
; CHECK-SPIRV-NEXT: OpExtension "SPV_KHR_bit_instructions"

; CHECK-SPIRV: %[[#int:]] = OpTypeInt 32
; CHECK-SPIRV: OpBitReverse %[[#int]]

Expand Down

0 comments on commit 7cfad02

Please sign in to comment.