From 4cc320ff63ad8bdf6ac5b7fa99a525abbfc8178a Mon Sep 17 00:00:00 2001 From: Chauhan Jaydeep Ashwinbhai Date: Fri, 4 Apr 2025 05:09:18 -0700 Subject: [PATCH] [X86][GlobalISel] Enable POWI function with libcall mapping --- .../lib/Target/X86/GISel/X86LegalizerInfo.cpp | 8 ++-- llvm/test/CodeGen/X86/powi.ll | 43 ++++++++++++------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp index b474d6a3f6356..ba9fa254a477a 100644 --- a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp +++ b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp @@ -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) diff --git a/llvm/test/CodeGen/X86/powi.ll b/llvm/test/CodeGen/X86/powi.ll index e4c691bfbd2e5..4420d0499a5d0 100644 --- a/llvm/test/CodeGen/X86/powi.ll +++ b/llvm/test/CodeGen/X86/powi.ll @@ -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: @@ -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 @@ -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 } @@ -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: @@ -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 } @@ -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 @@ -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)