Skip to content

[mlir][SPIR-V] Convert math.fpowi to spirv.CL.pown#196701

Merged
aobolensk merged 1 commit into
llvm:mainfrom
aobolensk:mlir-spirv-pown
May 9, 2026
Merged

[mlir][SPIR-V] Convert math.fpowi to spirv.CL.pown#196701
aobolensk merged 1 commit into
llvm:mainfrom
aobolensk:mlir-spirv-pown

Conversation

@aobolensk
Copy link
Copy Markdown
Contributor

No description provided.

@llvmorg-github-actions
Copy link
Copy Markdown

llvmorg-github-actions Bot commented May 9, 2026

@llvm/pr-subscribers-mlir-spirv

@llvm/pr-subscribers-mlir

Author: Arseniy Obolenskiy (aobolensk)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/196701.diff

2 Files Affected:

  • (modified) mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp (+21)
  • (modified) mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir (+14)
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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

✅ With the latest revision this PR passed the C/C++ code formatter.

@aobolensk aobolensk merged commit 615a7e0 into llvm:main May 9, 2026
10 checks passed
EuphoricThinking pushed a commit to EuphoricThinking/llvm-project that referenced this pull request May 14, 2026
pedroMVicente pushed a commit to pedroMVicente/llvm-project that referenced this pull request May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants