[Mlir-commits] [mlir] [mlir][SPIR-V] Add spirv.GL.Step and spirv.GL.SmoothStep ops (PR #206037)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jun 26 04:33:34 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Arseniy Obolenskiy (aobolensk)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/206037.diff
3 Files Affected:
- (modified) mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td (+52)
- (modified) mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp (+12)
- (modified) mlir/test/Dialect/SPIRV/IR/gl-ops.mlir (+44)
``````````diff
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
index e0b85e73cad99..34b49567deafe 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
@@ -1488,6 +1488,58 @@ def SPIRV_GLReflectOp : SPIRV_GLBinaryArithmeticOp<"Reflect", 71, SPIRV_Float, [
// ----
+def SPIRV_GLStepOp : SPIRV_GLBinaryArithmeticOp<"Step", 48, SPIRV_Float, [AlwaysSpeculatable]> {
+ let summary = "Return 0.0 if x < edge, else 1.0";
+
+ let description = [{
+ Result is 0.0 if x < edge; otherwise result is 1.0.
+
+ The operands must all be a scalar or vector whose component type is
+ floating-point.
+
+ Result Type and the type of all operands must be the same type. Results
+ are computed per component.
+
+ #### Example:
+
+ ```mlir
+ %2 = spirv.GL.Step %edge, %x : f32
+ %3 = spirv.GL.Step %edge, %x : vector<3xf32>
+ ```
+ }];
+}
+
+// ----
+
+def SPIRV_GLSmoothStepOp : SPIRV_GLTernaryArithmeticOp<"SmoothStep", 49, SPIRV_Float> {
+ let summary = "Return smooth Hermite interpolation between 0 and 1";
+
+ let description = [{
+ Result is 0.0 if x <= edge0 and 1.0 if x >= edge1 and performs smooth
+ Hermite interpolation between 0 and 1 when edge0 < x < edge1. This is
+ equivalent to:
+ t = clamp((x - edge0) / (edge1 - edge0), 0, 1)
+ t * t * (3 - 2 * t)
+
+ The resulting value is undefined if edge0 >= edge1.
+
+ The operands must all be a scalar or vector whose component type is
+ floating-point.
+
+ Result Type and the type of all operands must be the same type. Results
+ are computed per component.
+
+ #### Example:
+
+ ```mlir
+ %2 = spirv.GL.SmoothStep %edge0, %edge1, %x : f32
+ %3 = spirv.GL.SmoothStep %edge0, %edge1, %x : vector<3xf32>
+ ```
+ }];
+}
+
+// ----
+
def SPIRV_GLFindILsbOp : SPIRV_GLUnaryArithmeticOp<"FindILsb", 73, SPIRV_Integer, [AlwaysSpeculatable]> {
let summary = "Integer least-significant bit";
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
index f699055b5502f..c0393888af5c3 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
@@ -1294,6 +1294,18 @@ ParseResult spirv::GLNClampOp::parse(OpAsmParser &parser,
}
void spirv::GLNClampOp::print(OpAsmPrinter &p) { printOneResultOp(*this, p); }
+//===----------------------------------------------------------------------===//
+// spirv.GLSmoothStepOp
+//===----------------------------------------------------------------------===//
+
+ParseResult spirv::GLSmoothStepOp::parse(OpAsmParser &parser,
+ OperationState &result) {
+ return parseOneResultSameOperandTypeOp(parser, result);
+}
+void spirv::GLSmoothStepOp::print(OpAsmPrinter &p) {
+ printOneResultOp(*this, p);
+}
+
//===----------------------------------------------------------------------===//
// spirv.GLFmaOp
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
index 5665ae158d2e4..627c764feb6e6 100644
--- a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
@@ -839,6 +839,50 @@ func.func @reflect_invalid_type(%arg0 : i32, %arg1 : i32) {
// -----
+//===----------------------------------------------------------------------===//
+// spirv.GL.Step
+//===----------------------------------------------------------------------===//
+
+func.func @step_scalar(%edge : f32, %x : f32) {
+ %2 = spirv.GL.Step %edge, %x : f32
+ // CHECK: %{{.+}} = spirv.GL.Step %{{.+}}, %{{.+}} : f32
+ return
+}
+
+func.func @step_vector(%edge : vector<3xf32>, %x : vector<3xf32>) {
+ %2 = spirv.GL.Step %edge, %x : vector<3xf32>
+ // CHECK: %{{.+}} = spirv.GL.Step %{{.+}}, %{{.+}} : vector<3xf32>
+ return
+}
+
+// -----
+
+func.func @step_invalid_type(%edge : i32, %x : i32) {
+ // expected-error @+1 {{'spirv.GL.Step' op operand #0 must be 16/32/64-bit float or fixed-length vector of 16/32/64-bit float values}}
+ %0 = spirv.GL.Step %edge, %x : i32
+ return
+}
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.GL.SmoothStep
+//===----------------------------------------------------------------------===//
+
+func.func @smoothstep_scalar(%edge0 : f32, %edge1 : f32, %x : f32) {
+ // CHECK: spirv.GL.SmoothStep {{%[^,]*}}, {{%[^,]*}}, {{%[^,]*}} : f32
+ %2 = spirv.GL.SmoothStep %edge0, %edge1, %x : f32
+ return
+}
+
+func.func @smoothstep_vector(%edge0 : vector<3xf32>, %edge1 : vector<3xf32>, %x : vector<3xf32>) {
+ // CHECK: spirv.GL.SmoothStep {{%[^,]*}}, {{%[^,]*}}, {{%[^,]*}} : vector<3xf32>
+ %2 = spirv.GL.SmoothStep %edge0, %edge1, %x : vector<3xf32>
+ return
+}
+
+// -----
+
//===----------------------------------------------------------------------===//
// spirv.GL.Fract
//===----------------------------------------------------------------------===//
``````````
</details>
https://github.com/llvm/llvm-project/pull/206037
More information about the Mlir-commits
mailing list