[Mlir-commits] [mlir] [mlir][SPIR-V] Add CL.{exp2, exp10, log2, log10} ops (PR #196869)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun May 10 21:07:26 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-spirv
Author: Arseniy Obolenskiy (aobolensk)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/196869.diff
3 Files Affected:
- (modified) mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td (+84)
- (modified) mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir (+72)
- (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 71f9c9579db81..37989e6e7e54a 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
@@ -386,6 +386,48 @@ def SPIRV_CLExpOp : SPIRV_CLUnaryArithmeticOp<"exp", 19, SPIRV_Float> {
// -----
+def SPIRV_CLExp2Op : SPIRV_CLUnaryArithmeticOp<"exp2", 20, SPIRV_Float> {
+ let summary = "Compute the base-2 exponential of x.";
+
+ let description = [{
+ Result Type and x 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.exp2 %0 : f32
+ %3 = spirv.CL.exp2 %1 : vector<3xf16>
+ ```
+ }];
+}
+
+// -----
+
+def SPIRV_CLExp10Op : SPIRV_CLUnaryArithmeticOp<"exp10", 21, SPIRV_Float> {
+ let summary = "Compute the base-10 exponential of x.";
+
+ let description = [{
+ Result Type and x 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.exp10 %0 : f32
+ %3 = spirv.CL.exp10 %1 : vector<3xf16>
+ ```
+ }];
+}
+
+// -----
+
def SPIRV_CLFAbsOp : SPIRV_CLUnaryArithmeticOp<"fabs", 23, SPIRV_Float> {
let summary = "Absolute value of operand";
@@ -568,6 +610,48 @@ def SPIRV_CLLogOp : SPIRV_CLUnaryArithmeticOp<"log", 37, SPIRV_Float> {
// -----
+def SPIRV_CLLog2Op : SPIRV_CLUnaryArithmeticOp<"log2", 38, SPIRV_Float> {
+ let summary = "Compute the base-2 logarithm of x.";
+
+ let description = [{
+ Result Type and x 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.log2 %0 : f32
+ %3 = spirv.CL.log2 %1 : vector<3xf16>
+ ```
+ }];
+}
+
+// -----
+
+def SPIRV_CLLog10Op : SPIRV_CLUnaryArithmeticOp<"log10", 39, SPIRV_Float> {
+ let summary = "Compute the base-10 logarithm of x.";
+
+ let description = [{
+ Result Type and x 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.log10 %0 : f32
+ %3 = spirv.CL.log10 %1 : vector<3xf16>
+ ```
+ }];
+}
+
+// -----
+
def SPIRV_CLMixOp : SPIRV_CLTernaryArithmeticOp<"mix", 99, SPIRV_Float> {
let summary = "Returns the linear blend of x & y implemented as: x + (y - x) * a";
diff --git a/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir b/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
index d6d3c53f23356..3b1ddf2494ca0 100644
--- a/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
@@ -50,6 +50,78 @@ func.func @exp(%arg0 : i32) -> () {
// -----
+//===----------------------------------------------------------------------===//
+// spirv.CL.exp2
+//===----------------------------------------------------------------------===//
+
+func.func @exp2(%arg0 : f32) -> () {
+ // CHECK: spirv.CL.exp2 {{%.*}} : f32
+ %2 = spirv.CL.exp2 %arg0 : f32
+ return
+}
+
+func.func @exp2vec(%arg0 : vector<3xf16>) -> () {
+ // CHECK: spirv.CL.exp2 {{%.*}} : vector<3xf16>
+ %2 = spirv.CL.exp2 %arg0 : vector<3xf16>
+ return
+}
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.CL.exp10
+//===----------------------------------------------------------------------===//
+
+func.func @exp10(%arg0 : f32) -> () {
+ // CHECK: spirv.CL.exp10 {{%.*}} : f32
+ %2 = spirv.CL.exp10 %arg0 : f32
+ return
+}
+
+func.func @exp10vec(%arg0 : vector<3xf16>) -> () {
+ // CHECK: spirv.CL.exp10 {{%.*}} : vector<3xf16>
+ %2 = spirv.CL.exp10 %arg0 : vector<3xf16>
+ return
+}
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.CL.log2
+//===----------------------------------------------------------------------===//
+
+func.func @log2(%arg0 : f32) -> () {
+ // CHECK: spirv.CL.log2 {{%.*}} : f32
+ %2 = spirv.CL.log2 %arg0 : f32
+ return
+}
+
+func.func @log2vec(%arg0 : vector<3xf16>) -> () {
+ // CHECK: spirv.CL.log2 {{%.*}} : vector<3xf16>
+ %2 = spirv.CL.log2 %arg0 : vector<3xf16>
+ return
+}
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.CL.log10
+//===----------------------------------------------------------------------===//
+
+func.func @log10(%arg0 : f32) -> () {
+ // CHECK: spirv.CL.log10 {{%.*}} : f32
+ %2 = spirv.CL.log10 %arg0 : f32
+ return
+}
+
+func.func @log10vec(%arg0 : vector<3xf16>) -> () {
+ // CHECK: spirv.CL.log10 {{%.*}} : vector<3xf16>
+ %2 = spirv.CL.log10 %arg0 : vector<3xf16>
+ return
+}
+
+// -----
+
//===----------------------------------------------------------------------===//
// spirv.CL.fabs
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Target/SPIRV/ocl-ops.mlir b/mlir/test/Target/SPIRV/ocl-ops.mlir
index 7a4abbd9dd344..e43223e65db5c 100644
--- a/mlir/test/Target/SPIRV/ocl-ops.mlir
+++ b/mlir/test/Target/SPIRV/ocl-ops.mlir
@@ -17,6 +17,14 @@ spirv.module Physical64 OpenCL requires #spirv.vce<v1.0, [Kernel, Addresses, Vec
%3 = spirv.CL.cos %arg0 : f32
// CHECK: {{%.*}} = spirv.CL.log {{%.*}} : f32
%4 = spirv.CL.log %arg0 : f32
+ // CHECK: {{%.*}} = spirv.CL.exp2 {{%.*}} : f32
+ %exp2 = spirv.CL.exp2 %arg0 : f32
+ // CHECK: {{%.*}} = spirv.CL.exp10 {{%.*}} : f32
+ %exp10 = spirv.CL.exp10 %arg0 : f32
+ // CHECK: {{%.*}} = spirv.CL.log2 {{%.*}} : f32
+ %log2 = spirv.CL.log2 %arg0 : f32
+ // CHECK: {{%.*}} = spirv.CL.log10 {{%.*}} : f32
+ %log10 = spirv.CL.log10 %arg0 : f32
// CHECK: {{%.*}} = spirv.CL.sqrt {{%.*}} : f32
%5 = spirv.CL.sqrt %arg0 : f32
// CHECK: {{%.*}} = spirv.CL.ceil {{%.*}} : f32
``````````
</details>
https://github.com/llvm/llvm-project/pull/196869
More information about the Mlir-commits
mailing list