[Mlir-commits] [mlir] [mlir][SPIR-V] Add CL copysign, fdim, fmod and hypot ops (PR #203880)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Jun 15 05:06:52 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Arseniy Obolenskiy (aobolensk)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/203880.diff
3 Files Affected:
- (modified) mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td (+88)
- (modified) mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir (+80)
- (modified) mlir/test/Target/SPIRV/ocl-ops.mlir (+8)
``````````diff
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
index 8972a03bedb2f..58fe643d2916a 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
@@ -319,6 +319,27 @@ def SPIRV_CLCeilOp : SPIRV_CLUnaryArithmeticOp<"ceil", 12, SPIRV_Float> {
// -----
+def SPIRV_CLCopysignOp : SPIRV_CLBinaryArithmeticOp<"copysign", 13, SPIRV_Float> {
+ let summary = "Computes the value with the magnitude of x and the sign of y.";
+
+ let description = [{
+ Result Type, x and y must be floating-point or vector(2,3,4,8,16) of
+ floating-point values.
+
+ All of the operands, including the Result Type operand, must be of the
+ same type.
+
+ #### Example:
+
+ ```mlir
+ %2 = spirv.CL.copysign %0, %1 : f32
+ %3 = spirv.CL.copysign %0, %1 : vector<3xf16>
+ ```
+ }];
+}
+
+// -----
+
def SPIRV_CLCosOp : SPIRV_CLUnaryArithmeticOp<"cos", 14, SPIRV_Float> {
let summary = "Compute the cosine of x radians.";
@@ -541,6 +562,73 @@ def SPIRV_CLFMinOp : SPIRV_CLBinaryArithmeticOp<"fmin", 28, SPIRV_Float> {
// -----
+def SPIRV_CLFdimOp : SPIRV_CLBinaryArithmeticOp<"fdim", 24, SPIRV_Float> {
+ let summary = "Compute the positive difference between x and y.";
+
+ let description = [{
+ Returns x - y if x > y, otherwise it returns +0.0.
+
+ Result Type, x and y must be floating-point or vector(2,3,4,8,16) of
+ floating-point values.
+
+ All of the operands, including the Result Type operand, must be of the
+ same type.
+
+ #### Example:
+
+ ```mlir
+ %2 = spirv.CL.fdim %0, %1 : f32
+ %3 = spirv.CL.fdim %0, %1 : vector<3xf16>
+ ```
+ }];
+}
+
+// -----
+
+def SPIRV_CLFmodOp : SPIRV_CLBinaryArithmeticOp<"fmod", 29, SPIRV_Float> {
+ let summary = [{
+ Modulus. Returns x - y * trunc(x / y), with the same sign as x.
+ }];
+
+ let description = [{
+ Result Type, x and y must be floating-point or vector(2,3,4,8,16) of
+ floating-point values.
+
+ All of the operands, including the Result Type operand, must be of the
+ same type.
+
+ #### Example:
+
+ ```mlir
+ %2 = spirv.CL.fmod %0, %1 : f32
+ %3 = spirv.CL.fmod %0, %1 : vector<3xf16>
+ ```
+ }];
+}
+
+// -----
+
+def SPIRV_CLHypotOp : SPIRV_CLBinaryArithmeticOp<"hypot", 32, SPIRV_Float> {
+ let summary = "Compute the square root of x^2 + y^2.";
+
+ let description = [{
+ Result Type, x and y must be floating-point or vector(2,3,4,8,16) of
+ floating-point values.
+
+ All of the operands, including the Result Type operand, must be of the
+ same type.
+
+ #### Example:
+
+ ```mlir
+ %2 = spirv.CL.hypot %0, %1 : f32
+ %3 = spirv.CL.hypot %0, %1 : vector<3xf16>
+ ```
+ }];
+}
+
+// -----
+
def SPIRV_CLFloorOp : SPIRV_CLUnaryArithmeticOp<"floor", 25, SPIRV_Float> {
let summary = [{
Round x to the integral value using the round to negative infinity
diff --git a/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir b/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
index 997c36077b497..e010475f241ff 100644
--- a/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
@@ -857,3 +857,83 @@ func.func @rootn_wrong_type_vec(%arg0 : vector<3xf32>, %arg1 : vector<2xi32>) ->
%0 = spirv.CL.rootn %arg0, %arg1 : vector<3xf32>, vector<2xi32> -> vector<3xf32>
return
}
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.CL.copysign
+//===----------------------------------------------------------------------===//
+
+func.func @copysign(%arg0 : f32, %arg1 : f32) -> () {
+ // CHECK: spirv.CL.copysign {{%.*}}, {{%.*}} : f32
+ %2 = spirv.CL.copysign %arg0, %arg1 : f32
+ return
+}
+
+// -----
+
+func.func @copysign(%arg0 : vector<4xf16>, %arg1 : vector<4xf16>) -> () {
+ // CHECK: spirv.CL.copysign {{%.*}}, {{%.*}} : vector<4xf16>
+ %2 = spirv.CL.copysign %arg0, %arg1 : vector<4xf16>
+ return
+}
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.CL.fdim
+//===----------------------------------------------------------------------===//
+
+func.func @fdim(%arg0 : f32, %arg1 : f32) -> () {
+ // CHECK: spirv.CL.fdim {{%.*}}, {{%.*}} : f32
+ %2 = spirv.CL.fdim %arg0, %arg1 : f32
+ return
+}
+
+// -----
+
+func.func @fdim(%arg0 : vector<4xf16>, %arg1 : vector<4xf16>) -> () {
+ // CHECK: spirv.CL.fdim {{%.*}}, {{%.*}} : vector<4xf16>
+ %2 = spirv.CL.fdim %arg0, %arg1 : vector<4xf16>
+ return
+}
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.CL.fmod
+//===----------------------------------------------------------------------===//
+
+func.func @fmod(%arg0 : f32, %arg1 : f32) -> () {
+ // CHECK: spirv.CL.fmod {{%.*}}, {{%.*}} : f32
+ %2 = spirv.CL.fmod %arg0, %arg1 : f32
+ return
+}
+
+// -----
+
+func.func @fmod(%arg0 : vector<4xf16>, %arg1 : vector<4xf16>) -> () {
+ // CHECK: spirv.CL.fmod {{%.*}}, {{%.*}} : vector<4xf16>
+ %2 = spirv.CL.fmod %arg0, %arg1 : vector<4xf16>
+ return
+}
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.CL.hypot
+//===----------------------------------------------------------------------===//
+
+func.func @hypot(%arg0 : f32, %arg1 : f32) -> () {
+ // CHECK: spirv.CL.hypot {{%.*}}, {{%.*}} : f32
+ %2 = spirv.CL.hypot %arg0, %arg1 : f32
+ return
+}
+
+// -----
+
+func.func @hypot(%arg0 : vector<4xf16>, %arg1 : vector<4xf16>) -> () {
+ // CHECK: spirv.CL.hypot {{%.*}}, {{%.*}} : vector<4xf16>
+ %2 = spirv.CL.hypot %arg0, %arg1 : vector<4xf16>
+ return
+}
diff --git a/mlir/test/Target/SPIRV/ocl-ops.mlir b/mlir/test/Target/SPIRV/ocl-ops.mlir
index 71fed716aa360..1f3236c767501 100644
--- a/mlir/test/Target/SPIRV/ocl-ops.mlir
+++ b/mlir/test/Target/SPIRV/ocl-ops.mlir
@@ -43,6 +43,14 @@ spirv.module Physical64 OpenCL requires #spirv.vce<v1.0, [Kernel, Addresses, Vec
%11 = spirv.CL.trunc %arg0 : f32
// CHECK: {{%.*}} = spirv.CL.cbrt {{%.*}} : f32
%12 = spirv.CL.cbrt %arg0 : f32
+ // CHECK: {{%.*}} = spirv.CL.copysign {{%.*}}, {{%.*}} : f32
+ %copysign = spirv.CL.copysign %arg0, %arg0 : f32
+ // CHECK: {{%.*}} = spirv.CL.fdim {{%.*}}, {{%.*}} : f32
+ %fdim = spirv.CL.fdim %arg0, %arg0 : f32
+ // CHECK: {{%.*}} = spirv.CL.fmod {{%.*}}, {{%.*}} : f32
+ %fmod = spirv.CL.fmod %arg0, %arg0 : f32
+ // CHECK: {{%.*}} = spirv.CL.hypot {{%.*}}, {{%.*}} : f32
+ %hypot = spirv.CL.hypot %arg0, %arg0 : f32
spirv.Return
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/203880
More information about the Mlir-commits
mailing list