[Mlir-commits] [mlir] [mlir][spirv] Add definition for GL Log2 (PR #143409)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Jun 9 09:42:00 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Igor Wodiany (IgWod-IMG)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/143409.diff
3 Files Affected:
- (modified) mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td (+30)
- (modified) mlir/test/Dialect/SPIRV/IR/gl-ops.mlir (+26)
- (modified) mlir/test/Target/SPIRV/gl-ops.mlir (+2)
``````````diff
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
index 057dfac4d6308..8c5a0b858c42d 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
@@ -767,6 +767,36 @@ def SPIRV_GLTanhOp : SPIRV_GLUnaryArithmeticOp<"Tanh", 21, SPIRV_Float16or32> {
// -----
+def SPIRV_GLLog2Op : SPIRV_GLUnaryArithmeticOp<"Log2", 30, SPIRV_Float16or32> {
+ let summary = "Result is the base-2 logarithm of x";
+
+ let description = [{
+ Result is the base-2 logarithm of x, i.e., the value y which satisfies the
+ equation x = 2y. The resulting value is NaN if x < 0. Moreover:
+
+ ```
+ log(Inf) = Inf
+ log(1.0) = +0
+ log(±0) = -Inf
+ ```
+
+ The operand x must be a scalar or vector whose component type is 16-bit or
+ 32-bit floating-point.
+
+ Result Type and the type of x must be the same type. Results are computed
+ per component.
+
+ #### Example:
+
+ ```mlir
+ %2 = spirv.GL.Log2 %0 : f32
+ %3 = spirv.GL.Log2 %1 : vector<3xf16>
+ ```
+ }];
+}
+
+// -----
+
def SPIRV_GLFClampOp : SPIRV_GLTernaryArithmeticOp<"FClamp", 43, SPIRV_Float> {
let summary = "Clamp x between min and max values.";
diff --git a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
index 0be047932c1f3..8f8e9e3a2417d 100644
--- a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
@@ -689,3 +689,29 @@ func.func @fract_invalid_type(%arg0 : i32) {
%0 = spirv.GL.Fract %arg0 : i32
return
}
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.GL.Log2
+//===----------------------------------------------------------------------===//
+
+func.func @log2(%arg0 : f32) -> () {
+ // CHECK: spirv.GL.Log2 {{%.*}} : f32
+ %0 = spirv.GL.Log2 %arg0 : f32
+ return
+}
+
+func.func @log2vec(%arg0 : vector<3xf16>) -> () {
+ // CHECK: spirv.GL.Log2 {{%.*}} : vector<3xf16>
+ %0 = spirv.GL.Log2 %arg0 : vector<3xf16>
+ return
+}
+
+// -----
+
+func.func @log2_invalid_type(%arg0 : i32) -> () {
+ // expected-error @+1 {{op operand #0 must be 16/32-bit float or vector of 16/32-bit float values}}
+ %0 = spirv.GL.Log2 %arg0 : i32
+ return
+}
diff --git a/mlir/test/Target/SPIRV/gl-ops.mlir b/mlir/test/Target/SPIRV/gl-ops.mlir
index 7f9771220b75d..bd6cf5957fac6 100644
--- a/mlir/test/Target/SPIRV/gl-ops.mlir
+++ b/mlir/test/Target/SPIRV/gl-ops.mlir
@@ -34,6 +34,8 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
%15 = spirv.GL.FMix %arg0 : f32, %arg1 : f32, %arg0 : f32 -> f32
// CHECK: {{%.*}} = spirv.GL.Fract {{%.*}} : f32
%16 = spirv.GL.Fract %arg0 : f32
+ // CHECK: {{%.*}} = spirv.GL.Log2 {{%.*}} : f32
+ %17 = spirv.GL.Log2 %arg0 : f32
spirv.Return
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/143409
More information about the Mlir-commits
mailing list