[Mlir-commits] [mlir] [mlir][SPIR-V] Convert math.clampf to spirv.GLFClamp and math.ctpop to spirv.BitCount (PR #200454)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri May 29 09:49:17 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-spirv
Author: Arseniy Obolenskiy (aobolensk)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/200454.diff
3 Files Affected:
- (modified) mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp (+2)
- (modified) mlir/test/Conversion/MathToSPIRV/math-to-fpclassify-spirv.mlir (+9)
- (modified) mlir/test/Conversion/MathToSPIRV/math-to-gl-spirv.mlir (+15)
``````````diff
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 %{{.*}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/200454
More information about the Mlir-commits
mailing list