[Mlir-commits] [mlir] 4e68962 - [mlir][spirv] Add definitions for GL inverse hyperbolic functions (#141720)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Jun 9 15:40:07 PDT 2025
Author: Darren Wihandi
Date: 2025-06-09T18:40:04-04:00
New Revision: 4e6896244f4129a22e311f7f6290a595b6f03b75
URL: https://github.com/llvm/llvm-project/commit/4e6896244f4129a22e311f7f6290a595b6f03b75
DIFF: https://github.com/llvm/llvm-project/commit/4e6896244f4129a22e311f7f6290a595b6f03b75.diff
LOG: [mlir][spirv] Add definitions for GL inverse hyperbolic functions (#141720)
Adds definitions for `Asinh`, `Acosh` and `Atanh` based on [SPIR-V
extended instructions for
GLSL](https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html).
Their instruction numbers are 22, 23 and 24.
Added:
Modified:
mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
mlir/test/Target/SPIRV/gl-ops.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
index 057dfac4d6308..feae817c9b4ef 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
@@ -767,6 +767,77 @@ def SPIRV_GLTanhOp : SPIRV_GLUnaryArithmeticOp<"Tanh", 21, SPIRV_Float16or32> {
// -----
+def SPIRV_GLAsinhOp : SPIRV_GLUnaryArithmeticOp<"Asinh", 22, SPIRV_Float16or32> {
+ let summary = "Arc hyperbolic sine of operand in radians.";
+
+ let description = [{
+ Arc hyperbolic sine; result is the inverse of sinh.
+
+ 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.Asinh %0 : f32
+ %3 = spirv.GL.Asinh %1 : vector<3xf16>
+ ```
+ }];
+}
+
+// -----
+
+def SPIRV_GLAcoshOp : SPIRV_GLUnaryArithmeticOp<"Acosh", 23, SPIRV_Float16or32> {
+ let summary = "Arc hyperbolic cosine of operand in radians.";
+
+ let description = [{
+ Arc hyperbolic cosine; result is the non-negative inverse of cosh. The resulting
+ value is NaN if x < 1.
+
+ 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.Acosh %0 : f32
+ %3 = spirv.GL.Acosh %1 : vector<3xf16>
+ ```
+ }];
+}
+
+// -----
+
+def SPIRV_GLAtanhOp : SPIRV_GLUnaryArithmeticOp<"Atanh", 24, SPIRV_Float16or32> {
+ let summary = "Arc hyperbolic tangent of operand in radians.";
+
+ let description = [{
+ Arc hyperbolic tangent; result is the inverse of tanh. The resulting value
+ is NaN if abs x ≥ 1.
+
+ 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.Atanh %0 : f32
+ %3 = spirv.GL.Atanh %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..680a7e12b1082 100644
--- a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
@@ -254,6 +254,54 @@ func.func @coshvec(%arg0 : vector<3xf16>) -> () {
return
}
+//===----------------------------------------------------------------------===//
+// spirv.GL.Asinh
+//===----------------------------------------------------------------------===//
+
+func.func @asinh(%arg0 : f32) -> () {
+ // CHECK: spirv.GL.Asinh {{%.*}} : f32
+ %2 = spirv.GL.Asinh %arg0 : f32
+ return
+}
+
+func.func @asinhvec(%arg0 : vector<3xf16>) -> () {
+ // CHECK: spirv.GL.Asinh {{%.*}} : vector<3xf16>
+ %2 = spirv.GL.Asinh %arg0 : vector<3xf16>
+ return
+}
+
+//===----------------------------------------------------------------------===//
+// spirv.GL.Acosh
+//===----------------------------------------------------------------------===//
+
+func.func @acosh(%arg0 : f32) -> () {
+ // CHECK: spirv.GL.Acosh {{%.*}} : f32
+ %2 = spirv.GL.Acosh %arg0 : f32
+ return
+}
+
+func.func @acoshvec(%arg0 : vector<3xf16>) -> () {
+ // CHECK: spirv.GL.Acosh {{%.*}} : vector<3xf16>
+ %2 = spirv.GL.Acosh %arg0 : vector<3xf16>
+ return
+}
+
+//===----------------------------------------------------------------------===//
+// spirv.GL.Atanh
+//===----------------------------------------------------------------------===//
+
+func.func @atanh(%arg0 : f32) -> () {
+ // CHECK: spirv.GL.Atanh {{%.*}} : f32
+ %2 = spirv.GL.Atanh %arg0 : f32
+ return
+}
+
+func.func @atanhvec(%arg0 : vector<3xf16>) -> () {
+ // CHECK: spirv.GL.Atanh {{%.*}} : vector<3xf16>
+ %2 = spirv.GL.Atanh %arg0 : vector<3xf16>
+ return
+}
+
//===----------------------------------------------------------------------===//
// spirv.GL.Pow
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Target/SPIRV/gl-ops.mlir b/mlir/test/Target/SPIRV/gl-ops.mlir
index 7f9771220b75d..28e5a1fd72ec5 100644
--- a/mlir/test/Target/SPIRV/gl-ops.mlir
+++ b/mlir/test/Target/SPIRV/gl-ops.mlir
@@ -34,6 +34,12 @@ 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.Asinh {{%.*}} : f32
+ %17 = spirv.GL.Asinh %arg0 : f32
+ // CHECK: {{%.*}} = spirv.GL.Acosh {{%.*}} : f32
+ %18 = spirv.GL.Acosh %arg0 : f32
+ // CHECK: {{%.*}} = spirv.GL.Atanh {{%.*}} : f32
+ %19 = spirv.GL.Atanh %arg0 : f32
spirv.Return
}
More information about the Mlir-commits
mailing list