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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Jun 11 12:08:21 PDT 2026


Author: Arseniy Obolenskiy
Date: 2026-06-11T21:08:15+02:00
New Revision: 9bece3b7dc3bb184ae3e6f1bdc4a864a096a6d68

URL: https://github.com/llvm/llvm-project/commit/9bece3b7dc3bb184ae3e6f1bdc4a864a096a6d68
DIFF: https://github.com/llvm/llvm-project/commit/9bece3b7dc3bb184ae3e6f1bdc4a864a096a6d68.diff

LOG: [mlir][SPIR-V] Add GL atan2 op (#201927)

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 4682a66418848..83a3ff5c3adb0 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 poison 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, [AlwaysSpeculatable]> {
   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


        


More information about the Mlir-commits mailing list