[Mlir-commits] [mlir] 04450c8 - [mlir][SPIR-V] Add CL copysign, fdim, fmod and hypot ops (#203880)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jun 25 09:23:57 PDT 2026
Author: Arseniy Obolenskiy
Date: 2026-06-25T18:23:53+02:00
New Revision: 04450c8cd86e7bbfab42cbeb919d31d8668366a8
URL: https://github.com/llvm/llvm-project/commit/04450c8cd86e7bbfab42cbeb919d31d8668366a8
DIFF: https://github.com/llvm/llvm-project/commit/04450c8cd86e7bbfab42cbeb919d31d8668366a8.diff
LOG: [mlir][SPIR-V] Add CL copysign, fdim, fmod and hypot ops (#203880)
Added:
Modified:
mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
mlir/test/Target/SPIRV/ocl-ops.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
index 617b41893c216..7c1ca28f728e9 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.";
@@ -562,6 +583,73 @@ def SPIRV_CLFMinOp : SPIRV_CLBinaryArithmeticOp<"fmin", 28, SPIRV_Float> {
// -----
+def SPIRV_CLFdimOp : SPIRV_CLBinaryArithmeticOp<"fdim", 24, SPIRV_Float> {
+ let summary = "Compute the positive
diff erence 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 e57da6efb13a6..da470f4e08109 100644
--- a/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
@@ -860,6 +860,26 @@ func.func @rootn_wrong_type_vec(%arg0 : vector<3xf32>, %arg1 : vector<2xi32>) ->
// -----
+//===----------------------------------------------------------------------===//
+// 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.expm1
//===----------------------------------------------------------------------===//
@@ -880,6 +900,66 @@ func.func @expm1(%arg0 : vector<4xf16>) -> () {
// -----
+//===----------------------------------------------------------------------===//
+// 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
+}
+
+// -----
+
//===----------------------------------------------------------------------===//
// spirv.CL.log1p
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Target/SPIRV/ocl-ops.mlir b/mlir/test/Target/SPIRV/ocl-ops.mlir
index 3ece17e309af2..3359dfd4f0428 100644
--- a/mlir/test/Target/SPIRV/ocl-ops.mlir
+++ b/mlir/test/Target/SPIRV/ocl-ops.mlir
@@ -43,8 +43,16 @@ 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.expm1 {{%.*}} : f32
%expm1 = spirv.CL.expm1 %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
// CHECK: {{%.*}} = spirv.CL.log1p {{%.*}} : f32
%log1p = spirv.CL.log1p %arg0 : f32
spirv.Return
More information about the Mlir-commits
mailing list