[Mlir-commits] [mlir] e3f80fe - [mlir][SPIR-V] Convert math.clampf to spirv.GLFClamp and math.ctpop to spirv.BitCount (#200454)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat May 30 02:15:22 PDT 2026


Author: Arseniy Obolenskiy
Date: 2026-05-30T11:15:17+02:00
New Revision: e3f80fe493c1e7d4701d6c08a57f106f99d15380

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

LOG: [mlir][SPIR-V] Convert math.clampf to spirv.GLFClamp and math.ctpop to spirv.BitCount (#200454)

Added: 
    

Modified: 
    mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
    mlir/test/Conversion/MathToSPIRV/math-to-fpclassify-spirv.mlir
    mlir/test/Conversion/MathToSPIRV/math-to-gl-spirv.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp b/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
index cf5ea9716b9f7..674fb1e586701 100644
--- a/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
+++ b/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
@@ -522,6 +522,7 @@ void populateMathToSPIRVPatterns(const SPIRVTypeConverter &typeConverter,
   // Core patterns
   patterns
       .add<CopySignPattern,
+           CheckedElementwiseOpPattern<math::CtPopOp, spirv::BitCountOp>,
            CheckedElementwiseOpPattern<math::IsInfOp, spirv::IsInfOp>,
            CheckedElementwiseOpPattern<math::IsNaNOp, spirv::IsNanOp>,
            CheckedElementwiseOpPattern<math::IsFiniteOp, spirv::IsFiniteOp>,
@@ -536,6 +537,7 @@ void populateMathToSPIRVPatterns(const SPIRVTypeConverter &typeConverter,
       CheckedElementwiseOpPattern<math::AbsIOp, spirv::GLSAbsOp>,
       CheckedElementwiseOpPattern<math::AtanOp, spirv::GLAtanOp>,
       CheckedElementwiseOpPattern<math::CeilOp, spirv::GLCeilOp>,
+      CheckedElementwiseOpPattern<math::ClampFOp, spirv::GLFClampOp>,
       CheckedElementwiseOpPattern<math::CosOp, spirv::GLCosOp>,
       CheckedElementwiseOpPattern<math::ExpOp, spirv::GLExpOp>,
       CheckedElementwiseOpPattern<math::Exp2Op, spirv::GLExp2Op>,

diff  --git a/mlir/test/Conversion/MathToSPIRV/math-to-fpclassify-spirv.mlir b/mlir/test/Conversion/MathToSPIRV/math-to-fpclassify-spirv.mlir
index 157a485826a33..5b875c97c17c9 100644
--- a/mlir/test/Conversion/MathToSPIRV/math-to-fpclassify-spirv.mlir
+++ b/mlir/test/Conversion/MathToSPIRV/math-to-fpclassify-spirv.mlir
@@ -29,4 +29,13 @@ module attributes {
     return
   }
 
+  // CHECK-LABEL: @ctpop
+  func.func @ctpop(%i: i32, %iv: vector<4xi32>) {
+    // CHECK: spirv.BitCount %{{.*}} : i32
+    %0 = math.ctpop %i : i32
+    // CHECK: spirv.BitCount %{{.*}} : vector<4xi32>
+    %1 = math.ctpop %iv : vector<4xi32>
+    return
+  }
+
 }

diff  --git a/mlir/test/Conversion/MathToSPIRV/math-to-gl-spirv.mlir b/mlir/test/Conversion/MathToSPIRV/math-to-gl-spirv.mlir
index 08d7822d04cc1..9dee79914b0dc 100644
--- a/mlir/test/Conversion/MathToSPIRV/math-to-gl-spirv.mlir
+++ b/mlir/test/Conversion/MathToSPIRV/math-to-gl-spirv.mlir
@@ -135,6 +135,21 @@ func.func @float32_ternary_vector(%a: vector<4xf32>, %b: vector<4xf32>,
   return
 }
 
+// CHECK-LABEL: @float32_clamp_scalar
+func.func @float32_clamp_scalar(%value: f32, %min: f32, %max: f32) {
+  // CHECK: spirv.GL.FClamp %{{.*}}, %{{.*}}, %{{.*}} : f32
+  %0 = math.clampf %value to [%min, %max] : f32
+  return
+}
+
+// CHECK-LABEL: @float32_clamp_vector
+func.func @float32_clamp_vector(%value: vector<4xf32>, %min: vector<4xf32>,
+                                %max: vector<4xf32>) {
+  // CHECK: spirv.GL.FClamp %{{.*}}, %{{.*}}, %{{.*}} : vector<4xf32>
+  %0 = math.clampf %value to [%min, %max] : vector<4xf32>
+  return
+}
+
 // CHECK-LABEL: @int_unary
 func.func @int_unary(%arg0: i32) {
   // CHECK: spirv.GL.SAbs %{{.*}}


        


More information about the Mlir-commits mailing list