[mlir][SPIR-V] Convert math.fpowi to spirv.CL.pown#196701
Merged
Merged
Conversation
|
@llvm/pr-subscribers-mlir-spirv @llvm/pr-subscribers-mlir Author: Arseniy Obolenskiy (aobolensk) ChangesFull diff: https://github.com/llvm/llvm-project/pull/196701.diff 2 Files Affected:
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
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
kuhar
approved these changes
May 9, 2026
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
This was referenced May 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.