[Mlir-commits] [mlir] f2fd0d6 - [mlir][SPIR-V] Add spirv.GL.Step and spirv.GL.SmoothStep ops (#206037)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Jul 1 04:03:28 PDT 2026


Author: Arseniy Obolenskiy
Date: 2026-07-01T13:03:23+02:00
New Revision: f2fd0d648987f0187a7e57bca17bf10ef2d289d8

URL: https://github.com/llvm/llvm-project/commit/f2fd0d648987f0187a7e57bca17bf10ef2d289d8
DIFF: https://github.com/llvm/llvm-project/commit/f2fd0d648987f0187a7e57bca17bf10ef2d289d8.diff

LOG: [mlir][SPIR-V] Add spirv.GL.Step and spirv.GL.SmoothStep ops (#206037)

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
    mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
    mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
    mlir/test/Target/SPIRV/gl-ops.mlir

Removed: 
    


################################################################################
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
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/test/Target/SPIRV/gl-ops.mlir b/mlir/test/Target/SPIRV/gl-ops.mlir
index bc17ff82cc441..41364dca31af3 100644
--- a/mlir/test/Target/SPIRV/gl-ops.mlir
+++ b/mlir/test/Target/SPIRV/gl-ops.mlir
@@ -174,4 +174,16 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Linkage], []> {
     %1 = spirv.GL.PackSnorm4x8 %0 : vector<4xf32> -> i32
     spirv.Return
   }
+
+  spirv.func @step(%arg0 : f32, %arg1 : f32) "None" {
+    // CHECK: spirv.GL.Step {{%[^,]*}}, {{%[^,]*}} : f32
+    %0 = spirv.GL.Step %arg0, %arg1 : f32
+    spirv.Return
+  }
+
+  spirv.func @smoothstep(%arg0 : f32, %arg1 : f32, %arg2 : f32) "None" {
+    // CHECK: spirv.GL.SmoothStep {{%[^,]*}}, {{%[^,]*}}, {{%[^,]*}} : f32
+    %0 = spirv.GL.SmoothStep %arg0, %arg1, %arg2 : f32
+    spirv.Return
+  }
 }


        


More information about the Mlir-commits mailing list