[Mlir-commits] [mlir] [mlir][spirv] Fix `fp8` and `bf16` leaking into unsupported ops (PR #199102)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu May 21 13:06:21 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Igor Wodiany (IgWod)
<details>
<summary>Changes</summary>
Including `SPIRV_AnyFloat` in the majority of types caused fp8 and bf16 to be allowed in ops that are not allowed by float8 and bfloat16 extensions. This patch tries to rectify to only allow fp8 and bf16 in ops allowed by the respective specs. Additional tests have been also added to increase the coverage with respect to those types.
Assisted-by: Codex + Claude Code
---
Patch is 30.20 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/199102.diff
12 Files Affected:
- (modified) mlir/include/mlir/Dialect/SPIRV/IR/SPIRVArithmeticOps.td (+3-3)
- (modified) mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td (+15-6)
- (modified) mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGroupOps.td (+2-2)
- (modified) mlir/include/mlir/Dialect/SPIRV/IR/SPIRVNonUniformOps.td (+9-9)
- (modified) mlir/lib/Dialect/SPIRV/IR/ImageOps.cpp (+10-6)
- (modified) mlir/test/Dialect/SPIRV/IR/arithmetic-ops.mlir (+9-1)
- (modified) mlir/test/Dialect/SPIRV/IR/atomic-ops.mlir (+16)
- (modified) mlir/test/Dialect/SPIRV/IR/composite-ops.mlir (+1-1)
- (modified) mlir/test/Dialect/SPIRV/IR/group-ops.mlir (+16)
- (modified) mlir/test/Dialect/SPIRV/IR/image-ops.mlir (+48)
- (modified) mlir/test/Dialect/SPIRV/IR/non-uniform-ops.mlir (+84-2)
- (modified) mlir/test/Dialect/SPIRV/IR/structure-ops.mlir (+1-1)
``````````diff
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVArithmeticOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVArithmeticOps.td
index 8a194bc288121..e1b94d6834f81 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVArithmeticOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVArithmeticOps.td
@@ -464,12 +464,12 @@ def SPIRV_DotOp : SPIRV_Op<"Dot",
}];
let arguments = (ins
- SPIRV_VectorOf<SPIRV_AnyFloat>:$vector1,
- SPIRV_VectorOf<SPIRV_AnyFloat>:$vector2
+ AnyTypeOf<[SPIRV_FloatVector, SPIRV_VectorOf<SPIRV_BFloat16KHR>]>:$vector1,
+ AnyTypeOf<[SPIRV_FloatVector, SPIRV_VectorOf<SPIRV_BFloat16KHR>]>:$vector2
);
let results = (outs
- SPIRV_AnyFloat:$result
+ AnyTypeOf<[SPIRV_Float, SPIRV_BFloat16KHR]>:$result
);
let assemblyFormat = "operands attr-dict `:` type($vector1) `->` type($result)";
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td
index e6e3d40e2d6df..6fa3822e9a235 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td
@@ -4301,7 +4301,13 @@ def SPIRV_Float : FloatOfWidths<[16, 32, 64]>;
def SPIRV_Float16or32 : FloatOfWidths<[16, 32]>;
def SPIRV_AnyFloat : AnyTypeOf<[SPIRV_Float, SPIRV_BFloat16KHR, SPIRV_Float8E4M3EXT, SPIRV_Float8E5M2EXT]>;
def SPIRV_Vector : VectorOfRankAndLengthAndType<[1], [2, 3, 4, 8, 16],
- [SPIRV_Bool, SPIRV_Integer, SPIRV_AnyFloat]>;
+ [SPIRV_Bool, SPIRV_Integer, SPIRV_Float]>;
+def SPIRV_FloatVector : VectorOfRankAndLengthAndType<[1], [2, 3, 4, 8, 16],
+ [SPIRV_Float]>;
+def SPIRV_ExtendedFloatVector : VectorOfRankAndLengthAndType<[1], [2, 3, 4, 8, 16],
+ [SPIRV_BFloat16KHR, SPIRV_Float8E4M3EXT,
+ SPIRV_Float8E5M2EXT]>;
+def SPIRV_AnyFloatVector : AnyTypeOf<[SPIRV_FloatVector, SPIRV_ExtendedFloatVector]>;
// Component type check is done in the type parser for the following SPIR-V
// dialect-specific types so we use "Any" here.
def SPIRV_AnyPtr : DialectType<SPIRV_Dialect, SPIRV_IsPtrType,
@@ -4330,17 +4336,19 @@ def SPIRV_AnyNamedBarrier : DialectType<SPIRV_Dialect, SPIRV_IsNamedBarrierType,
def SPIRV_AnyTensorArm : DialectType<SPIRV_Dialect, SPIRV_IsTensorArmType,
"any SPIR-V tensorArm type">;
-def SPIRV_Numerical : AnyTypeOf<[SPIRV_Integer, SPIRV_AnyFloat]>;
+def SPIRV_Numerical : AnyTypeOf<[SPIRV_Integer, SPIRV_Float]>;
def SPIRV_Scalar : AnyTypeOf<[SPIRV_Numerical, SPIRV_Bool]>;
def SPIRV_Aggregate : AnyTypeOf<[SPIRV_AnyArray, SPIRV_AnyRTArray, SPIRV_AnyStruct]>;
def SPIRV_Composite :
- AnyTypeOf<[SPIRV_Vector, SPIRV_AnyArray, SPIRV_AnyRTArray, SPIRV_AnyStruct,
- SPIRV_AnyCooperativeMatrix, SPIRV_AnyMatrix, SPIRV_AnyTensorArm]>;
+ AnyTypeOf<[SPIRV_Vector, SPIRV_ExtendedFloatVector, SPIRV_AnyArray,
+ SPIRV_AnyRTArray, SPIRV_AnyStruct, SPIRV_AnyCooperativeMatrix,
+ SPIRV_AnyMatrix, SPIRV_AnyTensorArm]>;
def SPIRV_Type : AnyTypeOf<[
SPIRV_Void, SPIRV_Bool, SPIRV_Integer, SPIRV_AnyFloat, SPIRV_Vector,
SPIRV_AnyPtr, SPIRV_AnyArray, SPIRV_AnyRTArray, SPIRV_AnyStruct,
SPIRV_AnyCooperativeMatrix, SPIRV_AnyMatrix, SPIRV_AnySampledImage,
- SPIRV_AnySampler, SPIRV_AnyImage, SPIRV_AnyTensorArm
+ SPIRV_AnySampler, SPIRV_AnyImage, SPIRV_AnyTensorArm,
+ SPIRV_AnyFloatVector
]>;
def SPIRV_SignedInt : SignedIntOfWidths<[8, 16, 32, 64]>;
@@ -4384,7 +4392,8 @@ def SPIRV_IOrUIVec4 : SPIRV_Vec4<SPIRV_SignlessOrUnsignedInt>;
def SPIRV_Int32Vec4 : SPIRV_Vec4<AnyI32>;
def SPIRV_SelectType : AnyTypeOf<[SPIRV_Scalar, SPIRV_Vector, SPIRV_AnyPtr,
- SPIRV_AnyMatrix, SPIRV_AnyArray, SPIRV_AnyStruct]>;
+ SPIRV_AnyMatrix, SPIRV_AnyArray, SPIRV_AnyStruct,
+ SPIRV_AnyFloat, SPIRV_AnyFloatVector]>;
//===----------------------------------------------------------------------===//
// SPIR-V OpTrait definitions
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGroupOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGroupOps.td
index 047686f781bcb..4cc7bb96cda88 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGroupOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGroupOps.td
@@ -123,12 +123,12 @@ def SPIRV_GroupBroadcastOp : SPIRV_Op<"GroupBroadcast",
let arguments = (ins
SPIRV_ScopeAttr:$execution_scope,
- SPIRV_Type:$value,
+ SPIRV_ScalarOrVector:$value,
SPIRV_ScalarOrVectorOf<SPIRV_Integer>:$localid
);
let results = (outs
- SPIRV_Type:$result
+ SPIRV_ScalarOrVector:$result
);
let assemblyFormat = [{
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVNonUniformOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVNonUniformOps.td
index 1a0ab0ff98a8a..0a0e91a4c49fb 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVNonUniformOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVNonUniformOps.td
@@ -263,12 +263,12 @@ def SPIRV_GroupNonUniformBroadcastOp : SPIRV_Op<"GroupNonUniformBroadcast", [
let arguments = (ins
SPIRV_ScopeAttr:$execution_scope,
- SPIRV_Type:$value,
+ SPIRV_ScalarOrVector:$value,
SPIRV_Integer:$id
);
let results = (outs
- SPIRV_Type:$result
+ SPIRV_ScalarOrVector:$result
);
let assemblyFormat = [{
@@ -318,11 +318,11 @@ def SPIRV_GroupNonUniformBroadcastFirstOp : SPIRV_Op<"GroupNonUniformBroadcastFi
let arguments = (ins
SPIRV_ScopeAttr:$execution_scope,
- AnyTypeOf<[SPIRV_ScalarOrVectorOf<SPIRV_Float>, SPIRV_ScalarOrVectorOf<SPIRV_Integer>, SPIRV_ScalarOrVectorOf<SPIRV_Bool>]>:$value
+ SPIRV_ScalarOrVector:$value
);
let results = (outs
- AnyTypeOf<[SPIRV_ScalarOrVectorOf<SPIRV_Float>, SPIRV_ScalarOrVectorOf<SPIRV_Integer>, SPIRV_ScalarOrVectorOf<SPIRV_Bool>]>:$result
+ SPIRV_ScalarOrVector:$result
);
let hasVerifier = 0;
@@ -1498,13 +1498,13 @@ def SPIRV_GroupNonUniformRotateKHROp : SPIRV_Op<"GroupNonUniformRotateKHR", [
let arguments = (ins
SPIRV_ScopeAttr:$execution_scope,
- AnyTypeOf<[SPIRV_ScalarOrVectorOf<SPIRV_Float>, SPIRV_ScalarOrVectorOf<SPIRV_Integer>, SPIRV_ScalarOrVectorOf<SPIRV_Bool>]>:$value,
+ SPIRV_ScalarOrVector:$value,
SPIRV_SignlessOrUnsignedInt:$delta,
Optional<SPIRV_SignlessOrUnsignedInt>:$cluster_size
);
let results = (outs
- AnyTypeOf<[SPIRV_ScalarOrVectorOf<SPIRV_Float>, SPIRV_ScalarOrVectorOf<SPIRV_Integer>, SPIRV_ScalarOrVectorOf<SPIRV_Bool>]>:$result
+ SPIRV_ScalarOrVector:$result
);
let assemblyFormat = [{
@@ -1670,7 +1670,7 @@ def SPIRV_GroupNonUniformAllEqualOp : SPIRV_Op<"GroupNonUniformAllEqual", [
let arguments = (ins
SPIRV_ScopeAttr:$execution_scope,
- AnyTypeOf<[SPIRV_ScalarOrVectorOf<SPIRV_Float>, SPIRV_ScalarOrVectorOf<SPIRV_Integer>, SPIRV_ScalarOrVectorOf<SPIRV_Bool>]>:$value
+ SPIRV_ScalarOrVector:$value
);
let results = (outs
@@ -1750,12 +1750,12 @@ def SPIRV_GroupNonUniformQuadSwapOp : SPIRV_Op<"GroupNonUniformQuadSwap", [
let arguments = (ins
SPIRV_ScopeAttr:$execution_scope,
- AnyTypeOf<[SPIRV_ScalarOrVectorOf<SPIRV_Float>, SPIRV_ScalarOrVectorOf<SPIRV_Integer>, SPIRV_ScalarOrVectorOf<SPIRV_Bool>]>:$value,
+ SPIRV_ScalarOrVector:$value,
SPIRV_QuadSwapDirectionAttr:$direction
);
let results = (outs
- AnyTypeOf<[SPIRV_ScalarOrVectorOf<SPIRV_Float>, SPIRV_ScalarOrVectorOf<SPIRV_Integer>, SPIRV_ScalarOrVectorOf<SPIRV_Bool>]>:$result
+ SPIRV_ScalarOrVector:$result
);
let hasVerifier = 0;
diff --git a/mlir/lib/Dialect/SPIRV/IR/ImageOps.cpp b/mlir/lib/Dialect/SPIRV/IR/ImageOps.cpp
index 6ea07330b70cb..43d94c86013b1 100644
--- a/mlir/lib/Dialect/SPIRV/IR/ImageOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/ImageOps.cpp
@@ -18,6 +18,10 @@ using namespace mlir;
// Common utility functions
//===----------------------------------------------------------------------===//
+static bool isCoreFloat(Type type) {
+ return isa<Float16Type, Float32Type, Float64Type>(type);
+}
+
// TODO: In the future we should model image operands better, so we can move
// some verification into ODS.
static LogicalResult verifyImageOperands(Operation *imageOp,
@@ -50,7 +54,7 @@ static LogicalResult verifyImageOperands(Operation *imageOp,
if (index + 1 > operands.size())
return imageOp->emitError("Bias operand requires 1 argument");
- if (!isa<FloatType>(operands[index].getType()))
+ if (!isCoreFloat(operands[index].getType()))
return imageOp->emitError("Bias must be a floating-point type scalar");
auto samplingOp = cast<spirv::SamplingOpInterface>(imageOp);
@@ -84,7 +88,7 @@ static LogicalResult verifyImageOperands(Operation *imageOp,
spirv::ImageType imageType;
if (isa<spirv::SamplingOpInterface>(imageOp)) {
- if (!isa<mlir::FloatType>(operands[index].getType()))
+ if (!isCoreFloat(operands[index].getType()))
return imageOp->emitError("for sampling operations, Lod must be a "
"floating-point type scalar");
@@ -157,12 +161,12 @@ static LogicalResult verifyImageOperands(Operation *imageOp,
"of components in coordinate, minus the array layer component, if "
"present");
- if (!isa<mlir::FloatType>(dXVector.getElementType()) ||
- !isa<mlir::FloatType>(dYVector.getElementType()))
+ if (!isCoreFloat(dXVector.getElementType()) ||
+ !isCoreFloat(dYVector.getElementType()))
return imageOp->emitError(
"Grad arguments must be a vector of floating-point type");
- } else if (isa<mlir::FloatType>(operands[index].getType()) &&
- isa<mlir::FloatType>(operands[index + 1].getType())) {
+ } else if (isCoreFloat(operands[index].getType()) &&
+ isCoreFloat(operands[index + 1].getType())) {
if (numberOfComponents != 1)
return imageOp->emitError(
"number of components of each Grad argument must equal the number "
diff --git a/mlir/test/Dialect/SPIRV/IR/arithmetic-ops.mlir b/mlir/test/Dialect/SPIRV/IR/arithmetic-ops.mlir
index 7f1b84123151a..52bb2d72bcebf 100644
--- a/mlir/test/Dialect/SPIRV/IR/arithmetic-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/arithmetic-ops.mlir
@@ -348,13 +348,21 @@ func.func @dot(%arg0: vector<4xf32>, %arg1: vector<4xf32>) -> f16 {
// -----
func.func @dot(%arg0: vector<4xi32>, %arg1: vector<4xi32>) -> i32 {
- // expected-error @+1 {{'spirv.Dot' op operand #0 must be fixed-length vector of 16/32/64-bit float or BFloat16 or Float8E4M3 or Float8E5M2 values of length 2/3/4/8/16}}
+ // expected-error @+1 {{op operand #0 must be vector of 16/32/64-bit float values of length 2/3/4/8/16 of ranks 1 or fixed-length vector of BFloat16 values of length 2/3/4/8/16 of ranks 1, but got 'vector<4xi32>'}}
%0 = spirv.Dot %arg0, %arg1 : vector<4xi32> -> i32
return %0 : i32
}
// -----
+func.func @dot(%arg0: vector<4xf8E4M3FN>, %arg1: vector<4xf8E4M3FN>) -> f8E4M3FN {
+ // expected-error @+1 {{op operand #0 must be vector of 16/32/64-bit float values of length 2/3/4/8/16 of ranks 1 or fixed-length vector of BFloat16 values of length 2/3/4/8/16 of ranks 1, but got 'vector<4xf8E4M3FN>'}}
+ %0 = spirv.Dot %arg0, %arg1 : vector<4xf8E4M3FN> -> f8E4M3FN
+ return %0 : f8E4M3FN
+}
+
+// -----
+
//===----------------------------------------------------------------------===//
// spirv.SMulExtended
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/SPIRV/IR/atomic-ops.mlir b/mlir/test/Dialect/SPIRV/IR/atomic-ops.mlir
index 845ea6c98ed67..feaa9123fd715 100644
--- a/mlir/test/Dialect/SPIRV/IR/atomic-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/atomic-ops.mlir
@@ -121,6 +121,22 @@ func.func @atomic_exchange(%ptr: !spirv.ptr<i32, Workgroup>, %value: i32) -> i32
// -----
+func.func @atomic_exchange_bf16(%ptr: !spirv.ptr<bf16, Workgroup>, %value: bf16) -> bf16 {
+ // expected-error @+1 {{'spirv.AtomicExchange' op operand #1 must be 8/16/32/64-bit integer or 16/32/64-bit float, but got 'bf16'}}
+ %0 = spirv.AtomicExchange <Workgroup> <Release> %ptr, %value : !spirv.ptr<bf16, Workgroup>
+ return %0: bf16
+}
+
+// -----
+
+func.func @atomic_exchange_float8(%ptr: !spirv.ptr<f8E4M3FN, Workgroup>, %value: f8E4M3FN) -> f8E4M3FN {
+ // expected-error @+1 {{'spirv.AtomicExchange' op operand #1 must be 8/16/32/64-bit integer or 16/32/64-bit float, but got 'f8E4M3FN'}}
+ %0 = spirv.AtomicExchange <Workgroup> <Release> %ptr, %value : !spirv.ptr<f8E4M3FN, Workgroup>
+ return %0: f8E4M3FN
+}
+
+// -----
+
func.func @atomic_exchange(%ptr: !spirv.ptr<i32, Workgroup>, %value: i64) -> i32 {
// expected-error @+1 {{'spirv.AtomicExchange' op failed to verify that `value` type matches pointee type of `pointer`}}
%0 = "spirv.AtomicExchange"(%ptr, %value) {memory_scope = #spirv.scope<Workgroup>, semantics = #spirv.memory_semantics<AcquireRelease>} : (!spirv.ptr<i32, Workgroup>, i64) -> (i32)
diff --git a/mlir/test/Dialect/SPIRV/IR/composite-ops.mlir b/mlir/test/Dialect/SPIRV/IR/composite-ops.mlir
index ef04b949c5219..478884f8dfd08 100644
--- a/mlir/test/Dialect/SPIRV/IR/composite-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/composite-ops.mlir
@@ -100,7 +100,7 @@ func.func @composite_construct_vector_wrong_count(%arg0: f32, %arg1: f32, %arg2
// -----
func.func @composite_construct_vector_rank_two(%arg0: vector<2x2xi1>, %arg1: vector<2x2xi1>) -> vector<4x2xi1> {
- // expected-error @+1 {{ op operand #0 must be variadic of void or bool or 8/16/32/64-bit integer or 16/32/64-bit float or BFloat16 or Float8E4M3 or Float8E5M2 or vector of bool or 8/16/32/64-bit integer or 16/32/64-bit float or BFloat16 or Float8E4M3 or Float8E5M2 values of length 2/3/4/8/16 of ranks 1 or any SPIR-V pointer type or any SPIR-V array type or any SPIR-V runtime array type or any SPIR-V struct type or any SPIR-V cooperative matrix type or any SPIR-V matrix type or any SPIR-V sampled image type or any SPIR-V sampler type or any SPIR-V image type or any SPIR-V tensorArm type, but got 'vector<2x2xi1>'}}
+ // expected-error @+1 {{op operand #0 must be variadic of void or bool or 8/16/32/64-bit integer or 16/32/64-bit float or BFloat16 or Float8E4M3 or Float8E5M2 or vector of bool or 8/16/32/64-bit integer or 16/32/64-bit float values of length 2/3/4/8/16 of ranks 1 or any SPIR-V pointer type or any SPIR-V array type or any SPIR-V runtime array type or any SPIR-V struct type or any SPIR-V cooperative matrix type or any SPIR-V matrix type or any SPIR-V sampled image type or any SPIR-V sampler type or any SPIR-V image type or any SPIR-V tensorArm type or vector of 16/32/64-bit float values of length 2/3/4/8/16 of ranks 1 or vector of BFloat16 or Float8E4M3 or Float8E5M2 values of length 2/3/4/8/16 of ranks 1, but got 'vector<2x2xi1>'}}
%0 = spirv.CompositeConstruct %arg0, %arg1 : (vector<2x2xi1>, vector<2x2xi1>) -> vector<4x2xi1>
return %0: vector<4x2xi1>
}
diff --git a/mlir/test/Dialect/SPIRV/IR/group-ops.mlir b/mlir/test/Dialect/SPIRV/IR/group-ops.mlir
index 1034b9f02ef52..7ecc57c315c4f 100644
--- a/mlir/test/Dialect/SPIRV/IR/group-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/group-ops.mlir
@@ -64,6 +64,22 @@ func.func @group_broadcast_negative_locid_vec4(%value: f32, %localid: vector<4xi
// -----
+func.func @group_broadcast_bf16(%value: bf16, %localid: i32 ) -> bf16 {
+ // expected-error @+1 {{op operand #0 must be 8/16/32/64-bit integer or 16/32/64-bit float or bool or vector of bool or 8/16/32/64-bit integer or 16/32/64-bit float values of length 2/3/4/8/16 of ranks 1, but got 'bf16'}}
+ %0 = spirv.GroupBroadcast <Workgroup> %value, %localid : bf16, i32
+ return %0: bf16
+}
+
+// -----
+
+func.func @group_broadcast_float8(%value: f8E4M3FN, %localid: i32 ) -> f8E4M3FN {
+ // expected-error @+1 {{op operand #0 must be 8/16/32/64-bit integer or 16/32/64-bit float or bool or vector of bool or 8/16/32/64-bit integer or 16/32/64-bit float values of length 2/3/4/8/16 of ranks 1, but got 'f8E4M3FN'}}
+ %0 = spirv.GroupBroadcast <Workgroup> %value, %localid : f8E4M3FN, i32
+ return %0: f8E4M3FN
+}
+
+// -----
+
//===----------------------------------------------------------------------===//
// spirv.KHR.SubgroupBallot
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/SPIRV/IR/image-ops.mlir b/mlir/test/Dialect/SPIRV/IR/image-ops.mlir
index 9b17ca54b628d..bef0857a222c2 100644
--- a/mlir/test/Dialect/SPIRV/IR/image-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/image-ops.mlir
@@ -365,6 +365,22 @@ func.func @bias_with_rect(%arg0 : !spirv.sampled_image<!spirv.image<f32, Rect, N
spirv.Return
}
+// -----
+
+func.func @bias_bfloat16(%arg0 : !spirv.sampled_image<!spirv.image<f32, Dim1D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, %arg1 : f32, %arg2 : bf16) -> () {
+ // expected-error @+1 {{Bias must be a floating-point type scalar}}
+ %0 = spirv.ImageSampleImplicitLod %arg0, %arg1 ["Bias"], %arg2 : !spirv.sampled_image<!spirv.image<f32, Dim1D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, f32, bf16 -> vector<4xf32>
+ spirv.Return
+}
+
+// -----
+
+func.func @bias_float8(%arg0 : !spirv.sampled_image<!spirv.image<f32, Dim1D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, %arg1 : f32, %arg2 : f8E4M3FN) -> () {
+ // expected-error @+1 {{Bias must be a floating-point type scalar}}
+ %0 = spirv.ImageSampleImplicitLod %arg0, %arg1 ["Bias"], %arg2 : !spirv.sampled_image<!spirv.image<f32, Dim1D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, f32, f8E4M3FN -> vector<4xf32>
+ spirv.Return
+}
+
// TODO: We cannot currently test Bias with MS != 0 as all implemented implicit operations already check for that.
// -----
@@ -403,6 +419,22 @@ func.func @lod_with_rect(%arg0 : !spirv.sampled_image<!spirv.image<f32, Rect, No
spirv.Return
}
+// -----
+
+func.func @lod_bfloat16(%arg0 : !spirv.sampled_image<!spirv.image<f32, Dim2D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, %arg1 : vector<2xf32>, %arg2 : bf16) -> () {
+ // expected-error @+1 {{for sampling operations, Lod must be a floating-point type scalar}}
+ %0 = spirv.ImageSampleExplicitLod %arg0, %arg1 ["Lod"], %arg2 : !spirv.sampled_image<!spirv.image<f32, Dim2D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, vector<2xf32>, bf16 -> vector<4xf32>
+ spirv.Return
+}
+
+// -----
+
+func.func @lod_float8(%arg0 : !spirv.sampled_image<!spirv.image<f32, Dim2D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, %arg1 : vector<2xf32>, %arg2 : f8E4M3FN) -> () {
+ // expected-error @+1 {{for sampling operations, Lod must be a floating-point type scalar}}
+ %0 = spirv.ImageSampleExplicitLod %arg0, %arg1 ["Lod"], %arg2 : !spirv.sampled_image<!spirv.image<f32, Dim2D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, vector<2xf32>, f8E4M3FN -> vector<4xf32>
+ spirv.Return
+}
+
// TODO: We cannot currently test Lod with MS != 0 as all implemented explicit operations already check for that.
// -----
@@ -457,6 +489,22 @@ func.func @gard_arg_wrong_type(%arg0 : !spirv.sampled_image<!spirv.image<f32, Di
// -----
+func.func @gard_arg_bfloat16(%arg0 : !spirv.sampled_image<!spirv.image<f32, Dim2D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, %arg1 : vector<2xf32>, %arg2 : vector<2xbf16>) -> () {
+ // expected-error @+1 {{Grad arguments must be a vector of floating-point type}}
+ %0 = spirv.ImageSampleExplicitLod %arg0, %arg1 ["Grad"], %arg2, %arg2 : !spirv.sampled_image<!spirv.image<f32, Dim2D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, vector<2xf32>, vector<2xbf16>, vector<2xbf16> -> vector<4xf32>
+ spirv.Return
+}
+
+// -----
+
+func.func @gard_arg_float8(%arg0 : !spirv.sampled_image<!spirv.image<f32, Dim2D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, %arg1 : vector<2xf32>, %arg2 : vector<2xf8E4M3FN>) -> () {
+ // expected-error @+1 {{Grad arguments must be a vector of floating-point type}}
+ %0 = spirv.ImageSampleExplicitLod %arg0, %arg1 ["Grad"], %arg2, %arg2 : !spirv.sampled_image<!spirv.image<f32, Dim2D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, vector<2xf32>, vector<2xf8E4M3FN>, vector<2xf8E4M3FN> -> vector<4xf32>
+ spirv.Return
+}
+
+...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/199102
More information about the Mlir-commits
mailing list