Skip to content

[MLIR][LLVMIR] Add support for atan2 intrinsics op #127970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

FantasqueX
Copy link
Contributor

This is similar to #127317

@llvmbot
Copy link
Member

llvmbot commented Feb 20, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-llvm

Author: Letu Ren (FantasqueX)

Changes

This is similar to #127317


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

3 Files Affected:

  • (modified) mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td (+1)
  • (modified) mlir/test/Target/LLVMIR/Import/intrinsic.ll (+8)
  • (modified) mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir (+9)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
index c270b0898f865..aa6551eb43fa6 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
@@ -173,6 +173,7 @@ def LLVM_TanOp : LLVM_UnaryIntrOpF<"tan">;
 def LLVM_ASinOp : LLVM_UnaryIntrOpF<"asin">;
 def LLVM_ACosOp : LLVM_UnaryIntrOpF<"acos">;
 def LLVM_ATanOp : LLVM_UnaryIntrOpF<"atan">;
+def LLVM_ATan2Op : LLVM_BinarySameArgsIntrOpF<"atan2">;
 
 def LLVM_SinhOp : LLVM_UnaryIntrOpF<"sinh">;
 def LLVM_CoshOp : LLVM_UnaryIntrOpF<"cosh">;
diff --git a/mlir/test/Target/LLVMIR/Import/intrinsic.ll b/mlir/test/Target/LLVMIR/Import/intrinsic.ll
index 569b0def37856..d14fc8a5942ca 100644
--- a/mlir/test/Target/LLVMIR/Import/intrinsic.ll
+++ b/mlir/test/Target/LLVMIR/Import/intrinsic.ll
@@ -139,6 +139,14 @@ define void @inv_trig_test(float %0, <8 x float> %1) {
 
   ret void
 }
+; CHECK-LABEL:  llvm.func @atan2_test
+define void @atan2_test(float %0, float %1, <8 x float> %2, <8 x float> %3) {
+  ; CHECK:  llvm.intr.atan2(%{{.*}}, %{{.*}}) : (f32, f32) -> f32
+  %5 = call float @llvm.atan2.f32(float %0, float %1)
+  ; CHECK:  llvm.intr.atan2(%{{.*}}, %{{.*}}) : (vector<8xf32>, vector<8xf32>) -> vector<8xf32>
+  %6 = call <8 x float> @llvm.atan2.v8f32(<8 x float> %2, <8 x float> %3)
+  ret void
+}
 ; CHECK-LABEL:  llvm.func @hyperbolic_trig_test
 define void @hyperbolic_trig_test(float %0, <8 x float> %1) {
   ; CHECK: llvm.intr.sinh(%{{.*}}) : (f32) -> f32
diff --git a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
index 3616a2e3c7b21..0b47163cc51d3 100644
--- a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
@@ -142,6 +142,15 @@ llvm.func @inv_trig_test(%arg0: f32, %arg1: vector<8xf32>) {
   llvm.return
 }
 
+// CHECK-LABEL: @atan2_test
+llvm.func @atan2_test(%arg0: f32, %arg1: f32, %arg2: vector<8xf32>, %arg3: vector<8xf32>) {
+  // CHECK: call float @llvm.atan2.f32
+  "llvm.intr.atan2"(%arg0, %arg1) : (f32, f32) -> f32
+  // CHECK: call <8 x float> @llvm.atan2.v8f32
+  "llvm.intr.atan2"(%arg2, %arg3) : (vector<8xf32>, vector<8xf32>) -> vector<8xf32>
+  llvm.return
+}
+
 // CHECK-LABEL: @hyperbolic_trig_test
 llvm.func @hyperbolic_trig_test(%arg0: f32, %arg1: vector<8xf32>) {
   // CHECK: call float @llvm.sinh.f32

Copy link
Contributor

@Dinistro Dinistro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@bcardosolopes bcardosolopes merged commit 403b7b6 into llvm:main Feb 27, 2025
11 checks passed
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants