[Mlir-commits] [mlir] 5e7ce91 - [mlir][SPIR-V] Add CL.{exp2, exp10, log2, log10} ops (#196869)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon May 11 02:43:24 PDT 2026


Author: Arseniy Obolenskiy
Date: 2026-05-11T11:43:19+02:00
New Revision: 5e7ce91c68990bee67ddcb68969c2ae901e72a87

URL: https://github.com/llvm/llvm-project/commit/5e7ce91c68990bee67ddcb68969c2ae901e72a87
DIFF: https://github.com/llvm/llvm-project/commit/5e7ce91c68990bee67ddcb68969c2ae901e72a87.diff

LOG: [mlir][SPIR-V] Add CL.{exp2,exp10,log2,log10} ops (#196869)

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 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..68751211c5fa6 100644
--- a/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
@@ -50,6 +50,206 @@ 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
+}
+
+// -----
+
+func.func @exp2(%arg0 : i32) -> () {
+  // expected-error @+1 {{op operand #0 must be 16/32/64-bit float or fixed-length vector of 16/32/64-bit float values}}
+  %2 = spirv.CL.exp2 %arg0 : i32
+  return
+}
+
+// -----
+
+func.func @exp2(%arg0 : vector<5xf32>) -> () {
+  // expected-error @+1 {{op operand #0 must be 16/32/64-bit float or fixed-length vector of 16/32/64-bit float values of length 2/3/4}}
+  %2 = spirv.CL.exp2 %arg0 : vector<5xf32>
+  return
+}
+
+// -----
+
+func.func @exp2(%arg0 : f32, %arg1 : f32) -> () {
+  // expected-error @+1 {{expected ':'}}
+  %2 = spirv.CL.exp2 %arg0, %arg1 : i32
+  return
+}
+
+// -----
+
+func.func @exp2(%arg0 : i32) -> () {
+  // expected-error @+1 {{expected non-function type}}
+  %2 = spirv.CL.exp2 %arg0 :
+  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
+}
+
+// -----
+
+func.func @exp10(%arg0 : i32) -> () {
+  // expected-error @+1 {{op operand #0 must be 16/32/64-bit float or fixed-length vector of 16/32/64-bit float values}}
+  %2 = spirv.CL.exp10 %arg0 : i32
+  return
+}
+
+// -----
+
+func.func @exp10(%arg0 : vector<5xf32>) -> () {
+  // expected-error @+1 {{op operand #0 must be 16/32/64-bit float or fixed-length vector of 16/32/64-bit float values of length 2/3/4}}
+  %2 = spirv.CL.exp10 %arg0 : vector<5xf32>
+  return
+}
+
+// -----
+
+func.func @exp10(%arg0 : f32, %arg1 : f32) -> () {
+  // expected-error @+1 {{expected ':'}}
+  %2 = spirv.CL.exp10 %arg0, %arg1 : i32
+  return
+}
+
+// -----
+
+func.func @exp10(%arg0 : i32) -> () {
+  // expected-error @+1 {{expected non-function type}}
+  %2 = spirv.CL.exp10 %arg0 :
+  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
+}
+
+// -----
+
+func.func @log2(%arg0 : i32) -> () {
+  // expected-error @+1 {{op operand #0 must be 16/32/64-bit float or fixed-length vector of 16/32/64-bit float values}}
+  %2 = spirv.CL.log2 %arg0 : i32
+  return
+}
+
+// -----
+
+func.func @log2(%arg0 : vector<5xf32>) -> () {
+  // expected-error @+1 {{op operand #0 must be 16/32/64-bit float or fixed-length vector of 16/32/64-bit float values of length 2/3/4}}
+  %2 = spirv.CL.log2 %arg0 : vector<5xf32>
+  return
+}
+
+// -----
+
+func.func @log2(%arg0 : f32, %arg1 : f32) -> () {
+  // expected-error @+1 {{expected ':'}}
+  %2 = spirv.CL.log2 %arg0, %arg1 : i32
+  return
+}
+
+// -----
+
+func.func @log2(%arg0 : i32) -> () {
+  // expected-error @+1 {{expected non-function type}}
+  %2 = spirv.CL.log2 %arg0 :
+  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
+}
+
+// -----
+
+func.func @log10(%arg0 : i32) -> () {
+  // expected-error @+1 {{op operand #0 must be 16/32/64-bit float or fixed-length vector of 16/32/64-bit float values}}
+  %2 = spirv.CL.log10 %arg0 : i32
+  return
+}
+
+// -----
+
+func.func @log10(%arg0 : vector<5xf32>) -> () {
+  // expected-error @+1 {{op operand #0 must be 16/32/64-bit float or fixed-length vector of 16/32/64-bit float values of length 2/3/4}}
+  %2 = spirv.CL.log10 %arg0 : vector<5xf32>
+  return
+}
+
+// -----
+
+func.func @log10(%arg0 : f32, %arg1 : f32) -> () {
+  // expected-error @+1 {{expected ':'}}
+  %2 = spirv.CL.log10 %arg0, %arg1 : i32
+  return
+}
+
+// -----
+
+func.func @log10(%arg0 : i32) -> () {
+  // expected-error @+1 {{expected non-function type}}
+  %2 = spirv.CL.log10 %arg0 :
+  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


        


More information about the Mlir-commits mailing list