[llvm] 43ede46 - [RISCV][GISel] Add legalization for more fp128 libcalls.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 16 23:39:26 PST 2024


Author: Craig Topper
Date: 2024-12-16T23:39:09-08:00
New Revision: 43ede4689892a716fc9ec1c9ae4096621f3b0f57

URL: https://github.com/llvm/llvm-project/commit/43ede4689892a716fc9ec1c9ae4096621f3b0f57
DIFF: https://github.com/llvm/llvm-project/commit/43ede4689892a716fc9ec1c9ae4096621f3b0f57.diff

LOG: [RISCV][GISel] Add legalization for more fp128 libcalls.

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
    llvm/test/CodeGen/RISCV/GlobalISel/fp128.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
index 21bfb444a569d4..82847370b7085d 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
@@ -598,7 +598,8 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
       .legalFor(ST.hasStdExtZfa(), {s32})
       .legalFor(ST.hasStdExtZfa() && ST.hasStdExtD(), {s64})
       .legalFor(ST.hasStdExtZfa() && ST.hasStdExtZfh(), {s16})
-      .libcallFor({s32, s64});
+      .libcallFor({s32, s64})
+      .libcallFor(ST.is64Bit(), {s128});
 
   getActionDefinitionsBuilder({G_FMAXIMUM, G_FMINIMUM})
       .legalFor(ST.hasStdExtZfa(), {s32})
@@ -609,9 +610,11 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
                                G_FLOG10, G_FEXP, G_FEXP2, G_FEXP10, G_FACOS,
                                G_FASIN, G_FATAN, G_FATAN2, G_FCOSH, G_FSINH,
                                G_FTANH})
-      .libcallFor({s32, s64});
+      .libcallFor({s32, s64})
+      .libcallFor(ST.is64Bit(), {s128});
   getActionDefinitionsBuilder({G_FPOWI, G_FLDEXP})
-      .libcallFor({{s32, s32}, {s64, s32}});
+      .libcallFor({{s32, s32}, {s64, s32}})
+      .libcallFor(ST.is64Bit(), {s128, s32});
 
   getActionDefinitionsBuilder(G_VASTART).customFor({p0});
 

diff  --git a/llvm/test/CodeGen/RISCV/GlobalISel/fp128.ll b/llvm/test/CodeGen/RISCV/GlobalISel/fp128.ll
index 978a6b0dc024c1..e29c450c26cb4b 100644
--- a/llvm/test/CodeGen/RISCV/GlobalISel/fp128.ll
+++ b/llvm/test/CodeGen/RISCV/GlobalISel/fp128.ll
@@ -532,3 +532,382 @@ define fp128 @uitofp_i128(i128 %x) nounwind {
   %a = uitofp i128 %x to fp128
   ret fp128 %a
 }
+
+define fp128 @sqrt(fp128 %a) nounwind {
+; CHECK-LABEL: sqrt:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call sqrtl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.sqrt.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @powi(fp128 %a, i32 %b) nounwind {
+; CHECK-LABEL: powi:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    sext.w a2, a2
+; CHECK-NEXT:    call __powitf2
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.powi.f128.i32(fp128 %a, i32 %b)
+  ret fp128 %1
+}
+
+define fp128 @sin(fp128 %a) nounwind {
+; CHECK-LABEL: sin:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call sinl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.sin.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @cos(fp128 %a) nounwind {
+; CHECK-LABEL: cos:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call cosl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.cos.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @pow(fp128 %a, fp128 %b) nounwind {
+; CHECK-LABEL: pow:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call powl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.pow.f128(fp128 %a, fp128 %b)
+  ret fp128 %1
+}
+
+define fp128 @exp(fp128 %a) nounwind {
+; CHECK-LABEL: exp:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call expl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.exp.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @exp2(fp128 %a) nounwind {
+; CHECK-LABEL: exp2:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call exp2l
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.exp2.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @exp10(fp128 %a) nounwind {
+; CHECK-LABEL: exp10:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call exp10l
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.exp10.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @log(fp128 %a) nounwind {
+; CHECK-LABEL: log:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call logl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.log.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @log10(fp128 %a) nounwind {
+; CHECK-LABEL: log10:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call log10l
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.log10.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @log2(fp128 %a) nounwind {
+; CHECK-LABEL: log2:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call log2l
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.log2.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @minnum(fp128 %a, fp128 %b) nounwind {
+; CHECK-LABEL: minnum:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call fminl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.minnum.f128(fp128 %a, fp128 %b)
+  ret fp128 %1
+}
+
+define fp128 @maxnum(fp128 %a, fp128 %b) nounwind {
+; CHECK-LABEL: maxnum:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call fmaxl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.maxnum.f128(fp128 %a, fp128 %b)
+  ret fp128 %1
+}
+
+define fp128 @floor(fp128 %a) nounwind {
+; CHECK-LABEL: floor:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call floorl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.floor.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @ceil(fp128 %a) nounwind {
+; CHECK-LABEL: ceil:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call ceill
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.ceil.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @trunc(fp128 %a) nounwind {
+; CHECK-LABEL: trunc:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call truncl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.trunc.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @rint(fp128 %a) nounwind {
+; CHECK-LABEL: rint:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call rintl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.rint.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @nearbyint(fp128 %a) nounwind {
+; CHECK-LABEL: nearbyint:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call nearbyintl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.nearbyint.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @round(fp128 %a) nounwind {
+; CHECK-LABEL: round:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call roundl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.round.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @roundeven(fp128 %a) nounwind {
+; CHECK-LABEL: roundeven:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call roundevenl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.roundeven.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @tan(fp128 %a) nounwind {
+; CHECK-LABEL: tan:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call tanl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.tan.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @ldexp_fp128(fp128 %x, i32 %y) nounwind {
+; CHECK-LABEL: ldexp_fp128:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    sext.w a2, a2
+; CHECK-NEXT:    call ldexpl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %z = call fp128 @llvm.ldexp.f128.i32(fp128 %x, i32 %y)
+  ret fp128 %z
+}
+
+define fp128 @asin(fp128 %a) nounwind {
+; CHECK-LABEL: asin:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call asinl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.asin.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @acos(fp128 %a) nounwind {
+; CHECK-LABEL: acos:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call acosl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.acos.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @atan(fp128 %a) nounwind {
+; CHECK-LABEL: atan:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call atanl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.atan.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @atan2(fp128 %a, fp128 %b) nounwind {
+; CHECK-LABEL: atan2:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call atan2l
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.atan2.f128(fp128 %a, fp128 %b)
+  ret fp128 %1
+}
+
+define fp128 @sinh(fp128 %a) nounwind {
+; CHECK-LABEL: sinh:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call sinhl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.sinh.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @cosh(fp128 %a) nounwind {
+; CHECK-LABEL: cosh:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call coshl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.cosh.f128(fp128 %a)
+  ret fp128 %1
+}
+
+define fp128 @tanh(fp128 %a) nounwind {
+; CHECK-LABEL: tanh:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -16
+; CHECK-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    call tanhl
+; CHECK-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    addi sp, sp, 16
+; CHECK-NEXT:    ret
+  %1 = call fp128 @llvm.tanh.f128(fp128 %a)
+  ret fp128 %1
+}


        


More information about the llvm-commits mailing list