Skip to content

[X86][GlobalISel] Enable Trigonometric functions with libcall mapping #126931

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 6 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
.widenScalarToNextPow2(0, /*Min=*/8)
.clampScalar(0, s8, sMaxScalar);

getActionDefinitionsBuilder(G_LROUND).libcall();

getActionDefinitionsBuilder(G_LLROUND).libcall();
getActionDefinitionsBuilder({G_LROUND, G_LLROUND, G_FCOS, G_FCOSH, G_FACOS,
G_FSIN, G_FSINH, G_FASIN, G_FTAN, G_FTANH,
G_FATAN, G_FATAN2})
.libcall();

// merge/unmerge
for (unsigned Op : {G_MERGE_VALUES, G_UNMERGE_VALUES}) {
Expand Down
117 changes: 79 additions & 38 deletions llvm/test/CodeGen/X86/llvm.acos.ll
Original file line number Diff line number Diff line change
@@ -1,39 +1,76 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel=0 | FileCheck %s --check-prefixes=X86,SDAG-X86
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel=0 | FileCheck %s --check-prefixes=X64,SDAG-X64
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=X86,GISEL-X86
; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=X64,GISEL-X64
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel=0 | FileCheck %s --check-prefixes=SDAG-X64
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X86,GISEL-X86
; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X64

define float @use_acosf32(float %a) nounwind {
; X86-LABEL: use_acosf32:
; X86: # %bb.0:
; X86-NEXT: subl $12, %esp
; X86-NEXT: flds {{[0-9]+}}(%esp)
; X86-NEXT: fstps (%esp)
; X86-NEXT: calll acosf
; X86-NEXT: addl $12, %esp
; X86-NEXT: retl
; SDAG-X86-LABEL: use_acosf32:
; SDAG-X86: # %bb.0:
; SDAG-X86-NEXT: subl $12, %esp
; SDAG-X86-NEXT: flds {{[0-9]+}}(%esp)
; SDAG-X86-NEXT: fstps (%esp)
; SDAG-X86-NEXT: calll acosf
; SDAG-X86-NEXT: addl $12, %esp
; SDAG-X86-NEXT: retl
;
; X64-LABEL: use_acosf32:
; X64: # %bb.0:
; X64-NEXT: jmp acosf@PLT # TAILCALL
; SDAG-X64-LABEL: use_acosf32:
; SDAG-X64: # %bb.0:
; SDAG-X64-NEXT: jmp acosf@PLT # TAILCALL
;
; GISEL-X86-LABEL: use_acosf32:
; GISEL-X86: # %bb.0:
; GISEL-X86-NEXT: subl $12, %esp
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; GISEL-X86-NEXT: movl %eax, (%esp)
; GISEL-X86-NEXT: calll acosf
; GISEL-X86-NEXT: addl $12, %esp
; GISEL-X86-NEXT: retl
;
; GISEL-X64-LABEL: use_acosf32:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: pushq %rax
; GISEL-X64-NEXT: callq acosf
; GISEL-X64-NEXT: popq %rax
; GISEL-X64-NEXT: retq
%x = call float @llvm.acos.f32(float %a)
ret float %x
}

define double @use_acosf64(double %a) nounwind {
; X86-LABEL: use_acosf64:
; X86: # %bb.0:
; X86-NEXT: subl $12, %esp
; X86-NEXT: fldl {{[0-9]+}}(%esp)
; X86-NEXT: fstpl (%esp)
; X86-NEXT: calll acos
; X86-NEXT: addl $12, %esp
; X86-NEXT: retl
; SDAG-X86-LABEL: use_acosf64:
; SDAG-X86: # %bb.0:
; SDAG-X86-NEXT: subl $12, %esp
; SDAG-X86-NEXT: fldl {{[0-9]+}}(%esp)
; SDAG-X86-NEXT: fstpl (%esp)
; SDAG-X86-NEXT: calll acos
; SDAG-X86-NEXT: addl $12, %esp
; SDAG-X86-NEXT: retl
;
; X64-LABEL: use_acosf64:
; X64: # %bb.0:
; X64-NEXT: jmp acos@PLT # TAILCALL
; SDAG-X64-LABEL: use_acosf64:
; SDAG-X64: # %bb.0:
; SDAG-X64-NEXT: jmp acos@PLT # TAILCALL
;
; GISEL-X86-LABEL: use_acosf64:
; GISEL-X86: # %bb.0:
; GISEL-X86-NEXT: subl $12, %esp
; GISEL-X86-NEXT: leal {{[0-9]+}}(%esp), %eax
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
; GISEL-X86-NEXT: movl 4(%eax), %eax
; GISEL-X86-NEXT: xorl %edx, %edx
; GISEL-X86-NEXT: addl %esp, %edx
; GISEL-X86-NEXT: movl %ecx, (%esp)
; GISEL-X86-NEXT: movl %eax, 4(%edx)
; GISEL-X86-NEXT: calll acos
; GISEL-X86-NEXT: addl $12, %esp
; GISEL-X86-NEXT: retl
;
; GISEL-X64-LABEL: use_acosf64:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: pushq %rax
; GISEL-X64-NEXT: callq acos
; GISEL-X64-NEXT: popq %rax
; GISEL-X64-NEXT: retq
%x = call double @llvm.acos.f64(double %a)
ret double %x
}
Expand All @@ -48,23 +85,27 @@ define x86_fp80 @use_acosf80(x86_fp80 %a) nounwind {
; X86-NEXT: addl $12, %esp
; X86-NEXT: retl
;
; X64-LABEL: use_acosf80:
; X64: # %bb.0:
; X64-NEXT: subq $24, %rsp
; X64-NEXT: fldt {{[0-9]+}}(%rsp)
; X64-NEXT: fstpt (%rsp)
; X64-NEXT: callq acosl@PLT
; X64-NEXT: addq $24, %rsp
; X64-NEXT: retq
; SDAG-X64-LABEL: use_acosf80:
; SDAG-X64: # %bb.0:
; SDAG-X64-NEXT: subq $24, %rsp
; SDAG-X64-NEXT: fldt {{[0-9]+}}(%rsp)
; SDAG-X64-NEXT: fstpt (%rsp)
; SDAG-X64-NEXT: callq acosl@PLT
; SDAG-X64-NEXT: addq $24, %rsp
; SDAG-X64-NEXT: retq
;
; GISEL-X64-LABEL: use_acosf80:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: subq $24, %rsp
; GISEL-X64-NEXT: fldt {{[0-9]+}}(%rsp)
; GISEL-X64-NEXT: fstpt (%rsp)
; GISEL-X64-NEXT: callq acosl
; GISEL-X64-NEXT: addq $24, %rsp
; GISEL-X64-NEXT: retq
%x = call x86_fp80 @llvm.acos.f80(x86_fp80 %a)
ret x86_fp80 %x
}

declare float @llvm.acos.f32(float)
declare double @llvm.acos.f64(double)
declare x86_fp80 @llvm.acos.f80(x86_fp80)
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; GISEL-X64: {{.*}}
; GISEL-X86: {{.*}}
; SDAG-X64: {{.*}}
; SDAG-X86: {{.*}}
117 changes: 79 additions & 38 deletions llvm/test/CodeGen/X86/llvm.asin.ll
Original file line number Diff line number Diff line change
@@ -1,39 +1,76 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel=0 | FileCheck %s --check-prefixes=X86,SDAG-X86
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel=0 | FileCheck %s --check-prefixes=X64,SDAG-X64
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=X86,GISEL-X86
; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=X64,GISEL-X64
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel=0 | FileCheck %s --check-prefixes=SDAG-X64
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X86,GISEL-X86
; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X64

define float @use_asinf32(float %a) nounwind {
; X86-LABEL: use_asinf32:
; X86: # %bb.0:
; X86-NEXT: subl $12, %esp
; X86-NEXT: flds {{[0-9]+}}(%esp)
; X86-NEXT: fstps (%esp)
; X86-NEXT: calll asinf
; X86-NEXT: addl $12, %esp
; X86-NEXT: retl
; SDAG-X86-LABEL: use_asinf32:
; SDAG-X86: # %bb.0:
; SDAG-X86-NEXT: subl $12, %esp
; SDAG-X86-NEXT: flds {{[0-9]+}}(%esp)
; SDAG-X86-NEXT: fstps (%esp)
; SDAG-X86-NEXT: calll asinf
; SDAG-X86-NEXT: addl $12, %esp
; SDAG-X86-NEXT: retl
;
; X64-LABEL: use_asinf32:
; X64: # %bb.0:
; X64-NEXT: jmp asinf@PLT # TAILCALL
; SDAG-X64-LABEL: use_asinf32:
; SDAG-X64: # %bb.0:
; SDAG-X64-NEXT: jmp asinf@PLT # TAILCALL
;
; GISEL-X86-LABEL: use_asinf32:
; GISEL-X86: # %bb.0:
; GISEL-X86-NEXT: subl $12, %esp
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; GISEL-X86-NEXT: movl %eax, (%esp)
; GISEL-X86-NEXT: calll asinf
; GISEL-X86-NEXT: addl $12, %esp
; GISEL-X86-NEXT: retl
;
; GISEL-X64-LABEL: use_asinf32:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: pushq %rax
; GISEL-X64-NEXT: callq asinf
; GISEL-X64-NEXT: popq %rax
; GISEL-X64-NEXT: retq
%x = call float @llvm.asin.f32(float %a)
ret float %x
}

define double @use_asinf64(double %a) nounwind {
; X86-LABEL: use_asinf64:
; X86: # %bb.0:
; X86-NEXT: subl $12, %esp
; X86-NEXT: fldl {{[0-9]+}}(%esp)
; X86-NEXT: fstpl (%esp)
; X86-NEXT: calll asin
; X86-NEXT: addl $12, %esp
; X86-NEXT: retl
; SDAG-X86-LABEL: use_asinf64:
; SDAG-X86: # %bb.0:
; SDAG-X86-NEXT: subl $12, %esp
; SDAG-X86-NEXT: fldl {{[0-9]+}}(%esp)
; SDAG-X86-NEXT: fstpl (%esp)
; SDAG-X86-NEXT: calll asin
; SDAG-X86-NEXT: addl $12, %esp
; SDAG-X86-NEXT: retl
;
; X64-LABEL: use_asinf64:
; X64: # %bb.0:
; X64-NEXT: jmp asin@PLT # TAILCALL
; SDAG-X64-LABEL: use_asinf64:
; SDAG-X64: # %bb.0:
; SDAG-X64-NEXT: jmp asin@PLT # TAILCALL
;
; GISEL-X86-LABEL: use_asinf64:
; GISEL-X86: # %bb.0:
; GISEL-X86-NEXT: subl $12, %esp
; GISEL-X86-NEXT: leal {{[0-9]+}}(%esp), %eax
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
; GISEL-X86-NEXT: movl 4(%eax), %eax
; GISEL-X86-NEXT: xorl %edx, %edx
; GISEL-X86-NEXT: addl %esp, %edx
; GISEL-X86-NEXT: movl %ecx, (%esp)
; GISEL-X86-NEXT: movl %eax, 4(%edx)
; GISEL-X86-NEXT: calll asin
; GISEL-X86-NEXT: addl $12, %esp
; GISEL-X86-NEXT: retl
;
; GISEL-X64-LABEL: use_asinf64:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: pushq %rax
; GISEL-X64-NEXT: callq asin
; GISEL-X64-NEXT: popq %rax
; GISEL-X64-NEXT: retq
%x = call double @llvm.asin.f64(double %a)
ret double %x
}
Expand All @@ -48,23 +85,27 @@ define x86_fp80 @use_asinf80(x86_fp80 %a) nounwind {
; X86-NEXT: addl $12, %esp
; X86-NEXT: retl
;
; X64-LABEL: use_asinf80:
; X64: # %bb.0:
; X64-NEXT: subq $24, %rsp
; X64-NEXT: fldt {{[0-9]+}}(%rsp)
; X64-NEXT: fstpt (%rsp)
; X64-NEXT: callq asinl@PLT
; X64-NEXT: addq $24, %rsp
; X64-NEXT: retq
; SDAG-X64-LABEL: use_asinf80:
; SDAG-X64: # %bb.0:
; SDAG-X64-NEXT: subq $24, %rsp
; SDAG-X64-NEXT: fldt {{[0-9]+}}(%rsp)
; SDAG-X64-NEXT: fstpt (%rsp)
; SDAG-X64-NEXT: callq asinl@PLT
; SDAG-X64-NEXT: addq $24, %rsp
; SDAG-X64-NEXT: retq
;
; GISEL-X64-LABEL: use_asinf80:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: subq $24, %rsp
; GISEL-X64-NEXT: fldt {{[0-9]+}}(%rsp)
; GISEL-X64-NEXT: fstpt (%rsp)
; GISEL-X64-NEXT: callq asinl
; GISEL-X64-NEXT: addq $24, %rsp
; GISEL-X64-NEXT: retq
%x = call x86_fp80 @llvm.asin.f80(x86_fp80 %a)
ret x86_fp80 %x
}

declare float @llvm.asin.f32(float)
declare double @llvm.asin.f64(double)
declare x86_fp80 @llvm.asin.f80(x86_fp80)
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; GISEL-X64: {{.*}}
; GISEL-X86: {{.*}}
; SDAG-X64: {{.*}}
; SDAG-X86: {{.*}}
Loading
Loading