Skip to content

[SPIR-V] Reland "Fix OpGroupNonUniformBroadcast version requirement" #16854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions llvm-spirv/lib/SPIRV/libSPIRV/SPIRVInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ class SPIRVInstTemplateBase : public SPIRVInstruction {

/// Get operand as value.
/// If the operand is a literal, return it as a uint32 constant.
const SPIRVValue *getOpValue(int I) const {
return isOperandLiteral(I) ? Module->getLiteralAsConstant(Ops[I])
: getValue(Ops[I]);
}

SPIRVValue *getOpValue(int I) {
return isOperandLiteral(I) ? Module->getLiteralAsConstant(Ops[I])
: getValue(Ops[I]);
Expand All @@ -318,6 +323,9 @@ class SPIRVInstTemplateBase : public SPIRVInstruction {
return Operands;
}

virtual const SPIRVValue *getOperand(unsigned I) const {
return getOpValue(I);
}
virtual SPIRVValue *getOperand(unsigned I) { return getOpValue(I); }

bool hasExecScope() const { return SPIRV::hasExecScope(OpCode); }
Expand Down Expand Up @@ -2713,6 +2721,22 @@ class SPIRVGroupNonUniformBallotInst : public SPIRVInstTemplateBase {
SPIRVCapVec getRequiredCapability() const override {
return getVec(CapabilityGroupNonUniformBallot);
}

VersionNumber getRequiredSPIRVVersion() const override {
switch (OpCode) {
case OpGroupNonUniformBroadcast: {
assert(Ops.size() == 3 && "Expecting (Execution, Value, Id) operands");
if (!isConstantOpCode(getOperand(2)->getOpCode())) {
// Before version 1.5, Id must come from a constant instruction.
return VersionNumber::SPIRV_1_5;
}
break;
}
default:
break;
}
return VersionNumber::SPIRV_1_3;
}
};

#define _SPIRV_OP(x, ...) \
Expand Down
2 changes: 0 additions & 2 deletions llvm-spirv/test/transcoding/OpLessOrGreater.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
; TODO: Re-enable this test when support for SPIRV 1.5 is enabled.
; XFAIL:*
; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc -o %t.spv
; RUN: llvm-spirv %t.spv -to-text -o %t.spt
Expand Down
17 changes: 17 additions & 0 deletions llvm-spirv/test/transcoding/subgroup_spirv_1_5.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %clang_cc1 -triple spir-unknown-unknown -O1 -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header -emit-llvm-bc %s -o %t.bc
// RUN: not llvm-spirv --spirv-max-version=1.4 %t.bc 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
// RUN: llvm-spirv %t.bc -o %t.spv
// RUN: spirv-val %t.spv
// RUN: llvm-spirv -r %t.spv -o %t.rev.bc
// RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM

// Before SPIR-V 1.5, the Id operand of OpGroupNonUniformBroadcast must come from a constant instruction.
// CHECK-ERROR: RequiresVersion: Cannot fulfill SPIR-V version restriction:
// CHECK-ERROR-NEXT: SPIR-V version was restricted to at most 1.4 (66560) but a construct from the input requires SPIR-V version 1.5 (66816) or above

// CHECK-LLVM-LABEL: @test
// CHECK-LLVM: call spir_func i16 @_Z31sub_group_non_uniform_broadcasttj(i16 %a, i32 %id)

kernel void test(short a, uint id, global short *res) {
res[0] = sub_group_non_uniform_broadcast(a, id);
}
Loading