Skip to content

[mlir][spirv] Fix spirv.Select min version requirement #72173

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
Nov 13, 2023
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
4 changes: 4 additions & 0 deletions mlir/include/mlir/Dialect/SPIRV/IR/SPIRVLogicalOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,10 @@ def SPIRV_SelectOp : SPIRV_Op<"Select",
let assemblyFormat = [{
operands attr-dict `:` type($condition) `,` type($result)
}];

// These ops require dynamic availability specification based on operand and
// result types.
bit autogenAvailability = 0;
}

// -----
Expand Down
23 changes: 23 additions & 0 deletions mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
//
//===----------------------------------------------------------------------===//

#include "mlir/Dialect/SPIRV/IR/SPIRVEnums.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVTypes.h"
#include "mlir/Interfaces/CallInterfaces.h"

#include "SPIRVOpUtils.h"
Expand Down Expand Up @@ -429,6 +431,27 @@ LogicalResult SelectOp::verify() {
return success();
}

// Custom availability implementation is needed for spirv.Select given the
// syntax changes starting v1.4.
SmallVector<ArrayRef<spirv::Extension>, 1> SelectOp::getExtensions() {
return {};
}
SmallVector<ArrayRef<spirv::Capability>, 1> SelectOp::getCapabilities() {
return {};
}
std::optional<spirv::Version> SelectOp::getMinVersion() {
// Per the spec, "Before version 1.4, results are only computed per
// component."
if (isa<spirv::ScalarType>(getCondition().getType()) &&
isa<spirv::CompositeType>(getType()))
return Version::V_1_4;

return Version::V_1_0;
}
std::optional<spirv::Version> SelectOp::getMaxVersion() {
return Version::V_1_6;
}

//===----------------------------------------------------------------------===//
// spirv.mlir.selection
//===----------------------------------------------------------------------===//
Expand Down
10 changes: 10 additions & 0 deletions mlir/test/Dialect/SPIRV/Transforms/vce-deduction.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ spirv.module Logical GLSL450 attributes {
}
}

// CHECK: requires #spirv.vce<v1.4, [Shader], []>
spirv.module Logical GLSL450 attributes {
spirv.target_env = #spirv.target_env<#spirv.vce<v1.6, [Shader], []>, #spirv.resource_limits<>>
} {
spirv.func @select_with_scalar_condition(%predicate : i1, %a: vector<2xf32>, %b: vector<2xf32>) -> vector<2xf32> "None" {
%0 = spirv.Select %predicate, %a, %b : i1, vector<2xf32>
spirv.ReturnValue %0: vector<2xf32>
}
}

//===----------------------------------------------------------------------===//
// Capability
//===----------------------------------------------------------------------===//
Expand Down