Skip to content

[X86][GlobalISel] Enable POWI function with libcall mapping #134369

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
Apr 7, 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
8 changes: 4 additions & 4 deletions llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
.widenScalarToNextPow2(0, /*Min=*/8)
.clampScalar(0, s8, sMaxScalar);

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, G_FPOW, G_FEXP, G_FEXP2,
G_FEXP10, G_FLOG, G_FLOG2, G_FLOG10})
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, G_FPOW, G_FEXP, G_FEXP2,
G_FEXP10, G_FLOG, G_FLOG2, G_FLOG10, G_FPOWI})
.libcall();

getActionDefinitionsBuilder(G_FSQRT)
Expand Down
43 changes: 28 additions & 15 deletions llvm/test/CodeGen/X86/powi.ll
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
; RUN: llc < %s -mtriple=i686-linux-gnu -fast-isel | FileCheck %s --check-prefixes=FAST-X86
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel=0 -fast-isel=0 | FileCheck %s --check-prefixes=SDAG-X86
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=GISEL-X86
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X86
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -fast-isel | FileCheck %s --check-prefixes=FAST-X64
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel=0 -fast-isel=0 | FileCheck %s --check-prefixes=SDAG-X64
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=GISEL-X64
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X64

define float @test_powi_f32_i32(float %Val, i32 %x) nounwind {
; FAST-X86-LABEL: test_powi_f32_i32:
Expand Down Expand Up @@ -32,10 +32,10 @@ define float @test_powi_f32_i32(float %Val, i32 %x) nounwind {
; GISEL-X86-LABEL: test_powi_f32_i32:
; GISEL-X86: # %bb.0:
; GISEL-X86-NEXT: subl $12, %esp
; GISEL-X86-NEXT: flds {{[0-9]+}}(%esp)
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; GISEL-X86-NEXT: movl %eax, {{[0-9]+}}(%esp)
; GISEL-X86-NEXT: fstps (%esp)
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
; GISEL-X86-NEXT: movl %eax, (%esp)
; GISEL-X86-NEXT: movl %ecx, {{[0-9]+}}(%esp)
; GISEL-X86-NEXT: calll __powisf2
; GISEL-X86-NEXT: addl $12, %esp
; GISEL-X86-NEXT: retl
Expand All @@ -53,7 +53,10 @@ define float @test_powi_f32_i32(float %Val, i32 %x) nounwind {
;
; GISEL-X64-LABEL: test_powi_f32_i32:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: jmp __powisf2@PLT # TAILCALL
; GISEL-X64-NEXT: pushq %rax
; GISEL-X64-NEXT: callq __powisf2
; GISEL-X64-NEXT: popq %rax
; GISEL-X64-NEXT: retq
%res = call float @llvm.powi.f32.i32(float %Val, i32 %x)
ret float %res
}
Expand Down Expand Up @@ -83,13 +86,20 @@ define double @test_powi_f64_i32(double %Val, i32 %x) nounwind {
;
; GISEL-X86-LABEL: test_powi_f64_i32:
; GISEL-X86: # %bb.0:
; GISEL-X86-NEXT: subl $12, %esp
; GISEL-X86-NEXT: fldl {{[0-9]+}}(%esp)
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; GISEL-X86-NEXT: movl %eax, {{[0-9]+}}(%esp)
; GISEL-X86-NEXT: fstpl (%esp)
; GISEL-X86-NEXT: pushl %esi
; GISEL-X86-NEXT: subl $24, %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: movl {{[0-9]+}}(%esp), %edx
; GISEL-X86-NEXT: xorl %esi, %esi
; GISEL-X86-NEXT: addl %esp, %esi
; GISEL-X86-NEXT: movl %ecx, (%esp)
; GISEL-X86-NEXT: movl %eax, 4(%esi)
; GISEL-X86-NEXT: movl %edx, {{[0-9]+}}(%esp)
; GISEL-X86-NEXT: calll __powidf2
; GISEL-X86-NEXT: addl $12, %esp
; GISEL-X86-NEXT: addl $24, %esp
; GISEL-X86-NEXT: popl %esi
; GISEL-X86-NEXT: retl
;
; FAST-X64-LABEL: test_powi_f64_i32:
Expand All @@ -105,7 +115,10 @@ define double @test_powi_f64_i32(double %Val, i32 %x) nounwind {
;
; GISEL-X64-LABEL: test_powi_f64_i32:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: jmp __powidf2@PLT # TAILCALL
; GISEL-X64-NEXT: pushq %rax
; GISEL-X64-NEXT: callq __powidf2
; GISEL-X64-NEXT: popq %rax
; GISEL-X64-NEXT: retq
%res = call double @llvm.powi.f64.i32(double %Val, i32 %x)
ret double %res
}
Expand Down Expand Up @@ -138,8 +151,8 @@ define x86_fp80 @test_powi_f80_i32(x86_fp80 %Val, i32 %x) nounwind {
; GISEL-X86-NEXT: subl $28, %esp
; GISEL-X86-NEXT: fldt {{[0-9]+}}(%esp)
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; GISEL-X86-NEXT: movl %eax, {{[0-9]+}}(%esp)
; GISEL-X86-NEXT: fstpt (%esp)
; GISEL-X86-NEXT: movl %eax, {{[0-9]+}}(%esp)
; GISEL-X86-NEXT: calll __powixf2
; GISEL-X86-NEXT: addl $28, %esp
; GISEL-X86-NEXT: retl
Expand Down Expand Up @@ -167,7 +180,7 @@ define x86_fp80 @test_powi_f80_i32(x86_fp80 %Val, i32 %x) nounwind {
; GISEL-X64-NEXT: subq $24, %rsp
; GISEL-X64-NEXT: fldt {{[0-9]+}}(%rsp)
; GISEL-X64-NEXT: fstpt (%rsp)
; GISEL-X64-NEXT: callq __powixf2@PLT
; GISEL-X64-NEXT: callq __powixf2
; GISEL-X64-NEXT: addq $24, %rsp
; GISEL-X64-NEXT: retq
%res = call x86_fp80 @llvm.powi.f80.i32(x86_fp80 %Val, i32 %x)
Expand Down