[Mlir-commits] [mlir] 615a7e0 - [mlir][SPIR-V] Convert math.fpowi to spirv.CL.pown (#196701)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat May 9 12:03:39 PDT 2026
Author: Arseniy Obolenskiy
Date: 2026-05-09T21:03:35+02:00
New Revision: 615a7e0f772bb3ef09b5b008075ad665876ce27a
URL: https://github.com/llvm/llvm-project/commit/615a7e0f772bb3ef09b5b008075ad665876ce27a
DIFF: https://github.com/llvm/llvm-project/commit/615a7e0f772bb3ef09b5b008075ad665876ce27a.diff
LOG: [mlir][SPIR-V] Convert math.fpowi to spirv.CL.pown (#196701)
Added:
Modified:
mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp b/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
index ea6be76373573..8d850e01d5e62 100644
--- a/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
+++ b/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
@@ -445,6 +445,26 @@ struct PowFOpPattern final : public OpConversionPattern<math::PowFOp> {
}
};
+/// Converts math.fpowi to spirv.CL.pown.
+struct PowIOpPattern final : public OpConversionPattern<math::FPowIOp> {
+ using Base::Base;
+
+ LogicalResult
+ matchAndRewrite(math::FPowIOp op, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ if (LogicalResult res = checkSourceOpTypes(rewriter, op); failed(res))
+ return res;
+
+ Type dstType = getTypeConverter()->convertType(op.getType());
+ if (!dstType)
+ return failure();
+
+ rewriter.replaceOpWithNewOp<spirv::CLPownOp>(op, dstType, adaptor.getLhs(),
+ adaptor.getRhs());
+ return success();
+ }
+};
+
/// Converts math.round to GLSL SPIRV extended ops.
struct RoundOpPattern final : public OpConversionPattern<math::RoundOp> {
using Base::Base;
@@ -556,7 +576,7 @@ void populateMathToSPIRVPatterns(const SPIRVTypeConverter &typeConverter,
CheckedElementwiseOpPattern<math::FloorOp, spirv::CLFloorOp>,
CheckedElementwiseOpPattern<math::FmaOp, spirv::CLFmaOp>,
CheckedElementwiseOpPattern<math::LogOp, spirv::CLLogOp>,
- CheckedElementwiseOpPattern<math::PowFOp, spirv::CLPowOp>,
+ CheckedElementwiseOpPattern<math::PowFOp, spirv::CLPowOp>, PowIOpPattern,
CheckedElementwiseOpPattern<math::RoundEvenOp, spirv::CLRintOp>,
CheckedElementwiseOpPattern<math::RoundOp, spirv::CLRoundOp>,
CheckedElementwiseOpPattern<math::RsqrtOp, spirv::CLRsqrtOp>,
diff --git a/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir b/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir
index dae1b43402718..037f69e63a2dc 100644
--- a/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir
+++ b/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir
@@ -140,6 +140,20 @@ func.func @float32_binary_vector(%lhs: vector<4xf32>, %rhs: vector<4xf32>) {
return
}
+// CHECK-LABEL: @fpowi_scalar
+func.func @fpowi_scalar(%base: f32, %power: i32) -> f32 {
+ // CHECK: spirv.CL.pown %{{.*}}, %{{.*}} : f32, i32 -> f32
+ %0 = math.fpowi %base, %power : f32, i32
+ return %0 : f32
+}
+
+// CHECK-LABEL: @fpowi_vector
+func.func @fpowi_vector(%base: vector<4xf32>, %power: vector<4xi32>) -> vector<4xf32> {
+ // CHECK: spirv.CL.pown %{{.*}}, %{{.*}} : vector<4xf32>, vector<4xi32> -> vector<4xf32>
+ %0 = math.fpowi %base, %power : vector<4xf32>, vector<4xi32>
+ return %0 : vector<4xf32>
+}
+
// CHECK-LABEL: @float32_ternary_scalar
func.func @float32_ternary_scalar(%a: f32, %b: f32, %c: f32) {
// CHECK: spirv.CL.fma %{{.*}}: f32
More information about the Mlir-commits
mailing list