[Mlir-commits] [mlir] [mlir][SPIR-V] Convert math.fpowi to spirv.CL.pown (PR #196701)
Arseniy Obolenskiy
llvmlistbot at llvm.org
Sat May 9 00:50:04 PDT 2026
https://github.com/aobolensk created https://github.com/llvm/llvm-project/pull/196701
None
>From 0b031d3d5b94c6d8e3f2b43b34f84b7c2ba6cece Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Sat, 9 May 2026 09:49:14 +0200
Subject: [PATCH] [mlir][SPIR-V] Convert math.fpowi to spirv.CL.pown
---
.../Conversion/MathToSPIRV/MathToSPIRV.cpp | 21 +++++++++++++++++++
.../MathToSPIRV/math-to-opencl-spirv.mlir | 14 +++++++++++++
2 files changed, 35 insertions(+)
diff --git a/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp b/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
index ea6be76373573..d517065715e2c 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;
@@ -557,6 +577,7 @@ void populateMathToSPIRVPatterns(const SPIRVTypeConverter &typeConverter,
CheckedElementwiseOpPattern<math::FmaOp, spirv::CLFmaOp>,
CheckedElementwiseOpPattern<math::LogOp, spirv::CLLogOp>,
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