[Mlir-commits] [mlir] [mlir][SPIR-V] Add GL atan2 op (PR #201927)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Jun 5 13:03:39 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Arseniy Obolenskiy (aobolensk)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/201927.diff


3 Files Affected:

- (modified) mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td (+25) 
- (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 f08d2c01f2317..65fbb55cd1a95 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
@@ -862,6 +862,31 @@ def SPIRV_GLAtanhOp : SPIRV_GLUnaryArithmeticOp<"Atanh", 24, SPIRV_Float16or32>
 
 // -----
 
+def SPIRV_GLAtan2Op : SPIRV_GLBinaryArithmeticOp<"Atan2", 25, SPIRV_Float16or32> {
+  let summary = "Arc tangent of y / x in radians";
+
+  let description = [{
+    Result is the arc tangent of y / x. The signs of x and y are used to
+    determine what quadrant the angle is in. The range of result values is
+    [-π, π]. Result is undefined if x and y are both 0.
+
+    The operand y and x must be a scalar or vector whose component type is
+    16-bit or 32-bit floating-point.
+
+    Result Type and the type of all operands must be the same type. Results are
+    computed per component.
+
+    #### Example:
+
+    ```mlir
+    %2 = spirv.GL.Atan2 %0, %1 : f32
+    %3 = spirv.GL.Atan2 %0, %1 : vector<3xf16>
+    ```
+  }];
+}
+
+// -----
+
 def SPIRV_GLExp2Op : SPIRV_GLUnaryArithmeticOp<"Exp2", 29, SPIRV_Float16or32> {
   let summary = "Result is 2 raised to the x power";
 
diff --git a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
index 61942e1369dab..88593d54a6783 100644
--- a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
@@ -319,6 +319,32 @@ func.func @atanhvec(%arg0 : vector<3xf16>) -> () {
   return
 }
 
+//===----------------------------------------------------------------------===//
+// spirv.GL.Atan2
+//===----------------------------------------------------------------------===//
+
+func.func @atan2(%arg0 : f32, %arg1 : f32) -> () {
+  // CHECK: spirv.GL.Atan2 {{%.*}}, {{%.*}} : f32
+  %2 = spirv.GL.Atan2 %arg0, %arg1 : f32
+  return
+}
+
+func.func @atan2vec(%arg0 : vector<3xf16>, %arg1 : vector<3xf16>) -> () {
+  // CHECK: spirv.GL.Atan2 {{%.*}}, {{%.*}} : vector<3xf16>
+  %2 = spirv.GL.Atan2 %arg0, %arg1 : vector<3xf16>
+  return
+}
+
+// -----
+
+func.func @atan2_error(%arg0 : i32, %arg1 : i32) -> () {
+  // expected-error @+1 {{op operand #0 must be 16/32-bit float or fixed-length vector of 16/32-bit float values}}
+  %2 = spirv.GL.Atan2 %arg0, %arg1 : i32
+  return
+}
+
+// -----
+
 //===----------------------------------------------------------------------===//
 // spirv.GL.Pow
 //===----------------------------------------------------------------------===//
diff --git a/mlir/test/Target/SPIRV/gl-ops.mlir b/mlir/test/Target/SPIRV/gl-ops.mlir
index 041e40ad1249e..f4dc4051818bf 100644
--- a/mlir/test/Target/SPIRV/gl-ops.mlir
+++ b/mlir/test/Target/SPIRV/gl-ops.mlir
@@ -23,6 +23,8 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Linkage], []> {
     %7 = spirv.GL.Asin %arg0 : f32
     // CHECK: {{%.*}} = spirv.GL.Atan {{%.*}} : f32
     %8 = spirv.GL.Atan %arg0 : f32
+    // CHECK: {{%.*}} = spirv.GL.Atan2 {{%.*}}, {{%.*}} : f32
+    %atan2 = spirv.GL.Atan2 %arg0, %arg1 : f32
     // CHECK: {{%.*}} = spirv.GL.Sinh {{%.*}} : f32
     %9 = spirv.GL.Sinh %arg0 : f32
     // CHECK: {{%.*}} = spirv.GL.Cosh {{%.*}} : f32

``````````

</details>


https://github.com/llvm/llvm-project/pull/201927


More information about the Mlir-commits mailing list