[Mlir-commits] [mlir] 16042c9 - [mlir][SPIR-V] Add MathToSPIRV conversion for copysign on OpenCL targets (#205994)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Jul 22 03:33:46 PDT 2026


Author: Arseniy Obolenskiy
Date: 2026-07-22T12:33:42+02:00
New Revision: 16042c9480b4c9147d35f4e56b609c4189eb4f6f

URL: https://github.com/llvm/llvm-project/commit/16042c9480b4c9147d35f4e56b609c4189eb4f6f
DIFF: https://github.com/llvm/llvm-project/commit/16042c9480b4c9147d35f4e56b609c4189eb4f6f.diff

LOG: [mlir][SPIR-V] Add MathToSPIRV conversion for copysign on OpenCL targets (#205994)

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 61dddaf5155d3..e451f4316d4e3 100644
--- a/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
+++ b/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
@@ -128,6 +128,12 @@ struct CopySignPattern final : public OpConversionPattern<math::CopySignOp> {
         failed(res))
       return res;
 
+    // Defer to the CL copysign op on Kernel targets.
+    auto &typeConverter = *getTypeConverter<SPIRVTypeConverter>();
+    if (typeConverter.getTargetEnv().allows(spirv::Capability::Kernel))
+      return rewriter.notifyMatchFailure(copySignOp,
+                                         "Kernel target has native CL op");
+
     Type type = getTypeConverter()->convertType(copySignOp.getType());
     if (!type)
       return failure();
@@ -684,6 +690,7 @@ void populateMathToSPIRVPatterns(const SPIRVTypeConverter &typeConverter,
       CheckedElementwiseOpPattern<math::Atan2Op, spirv::CLAtan2Op>,
       CheckedElementwiseOpPattern<math::CbrtOp, spirv::CLCbrtOp>,
       CheckedElementwiseOpPattern<math::CeilOp, spirv::CLCeilOp>,
+      CheckedElementwiseOpPattern<math::CopySignOp, spirv::CLCopysignOp>,
       CheckedElementwiseOpPattern<math::CosOp, spirv::CLCosOp>,
       CheckedElementwiseOpPattern<math::ErfOp, spirv::CLErfOp>,
       CheckedElementwiseOpPattern<math::ErfcOp, spirv::CLErfcOp>,

diff  --git a/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir b/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir
index 9830f3a5d055e..faa509851a2e2 100644
--- a/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir
+++ b/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir
@@ -132,6 +132,8 @@ func.func @float32_binary_scalar(%lhs: f32, %rhs: f32) {
   %0 = math.atan2 %lhs, %rhs : f32
   // CHECK: spirv.CL.pow %{{.*}}: f32
   %1 = math.powf %lhs, %rhs : f32
+  // CHECK: spirv.CL.copysign %{{.*}}, %{{.*}}: f32
+  %copysign = math.copysign %lhs, %rhs : f32
   return
 }
 
@@ -141,6 +143,8 @@ func.func @float32_binary_vector(%lhs: vector<4xf32>, %rhs: vector<4xf32>) {
   %0 = math.atan2 %lhs, %rhs : vector<4xf32>
   // CHECK: spirv.CL.pow %{{.*}}: vector<4xf32>
   %1 = math.powf %lhs, %rhs : vector<4xf32>
+  // CHECK: spirv.CL.copysign %{{.*}}, %{{.*}}: vector<4xf32>
+  %copysign = math.copysign %lhs, %rhs : vector<4xf32>
   return
 }
 


        


More information about the Mlir-commits mailing list