[PATCH] D151434: [RISCV] Generalise shouldExtendTypeInLibcall logic to apply to all <XLEN floats on soft ABIs
Alex Bradbury via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 25 05:39:41 PDT 2023
asb created this revision.
asb added reviewers: craig.topper, reames, kito-cheng, jrtc27.
Herald added subscribers: jobnoorman, luke, wingo, pmatos, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
asb requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.
This results in improved codegen for half libcalls on soft ABIs, and this logic will kick in for bf16 on soft ABIs as well.
I don't think there's an existing hook for checking if we're on a soft ABI (perhaps I missed it?) and this patch doesn't add one, though there'd be an argument for doing so even if this is the only user.
https://reviews.llvm.org/D151434
Files:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/half-convert.ll
Index: llvm/test/CodeGen/RISCV/half-convert.ll
===================================================================
--- llvm/test/CodeGen/RISCV/half-convert.ll
+++ llvm/test/CodeGen/RISCV/half-convert.ll
@@ -1828,8 +1828,6 @@
; RV32I-NEXT: sw s3, 12(sp) # 4-byte Folded Spill
; RV32I-NEXT: sw s4, 8(sp) # 4-byte Folded Spill
; RV32I-NEXT: sw s5, 4(sp) # 4-byte Folded Spill
-; RV32I-NEXT: slli a0, a0, 16
-; RV32I-NEXT: srli a0, a0, 16
; RV32I-NEXT: call __extendhfsf2 at plt
; RV32I-NEXT: mv s1, a0
; RV32I-NEXT: lui a1, 913408
@@ -2393,8 +2391,6 @@
; RV32I-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
; RV32I-NEXT: sw s1, 4(sp) # 4-byte Folded Spill
; RV32I-NEXT: sw s2, 0(sp) # 4-byte Folded Spill
-; RV32I-NEXT: slli a0, a0, 16
-; RV32I-NEXT: srli a0, a0, 16
; RV32I-NEXT: call __extendhfsf2 at plt
; RV32I-NEXT: mv s0, a0
; RV32I-NEXT: lui a1, 391168
@@ -3748,8 +3744,6 @@
; RV32I: # %bb.0:
; RV32I-NEXT: addi sp, sp, -16
; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
-; RV32I-NEXT: slli a0, a0, 16
-; RV32I-NEXT: srli a0, a0, 16
; RV32I-NEXT: call __extendhfsf2 at plt
; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
; RV32I-NEXT: addi sp, sp, 16
@@ -3759,8 +3753,6 @@
; RV64I: # %bb.0:
; RV64I-NEXT: addi sp, sp, -16
; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
-; RV64I-NEXT: slli a0, a0, 48
-; RV64I-NEXT: srli a0, a0, 48
; RV64I-NEXT: call __extendhfsf2 at plt
; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
; RV64I-NEXT: addi sp, sp, 16
@@ -4011,8 +4003,6 @@
; RV32I: # %bb.0:
; RV32I-NEXT: addi sp, sp, -16
; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
-; RV32I-NEXT: slli a0, a0, 16
-; RV32I-NEXT: srli a0, a0, 16
; RV32I-NEXT: call __extendhfsf2 at plt
; RV32I-NEXT: call __extendsfdf2 at plt
; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
@@ -4023,11 +4013,7 @@
; RV64I: # %bb.0:
; RV64I-NEXT: addi sp, sp, -16
; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
-; RV64I-NEXT: slli a0, a0, 48
-; RV64I-NEXT: srli a0, a0, 48
; RV64I-NEXT: call __extendhfsf2 at plt
-; RV64I-NEXT: slli a0, a0, 32
-; RV64I-NEXT: srli a0, a0, 32
; RV64I-NEXT: call __extendsfdf2 at plt
; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
; RV64I-NEXT: addi sp, sp, 16
Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -15865,9 +15865,12 @@
bool RISCVTargetLowering::shouldExtendTypeInLibCall(EVT Type) const {
// Return false to suppress the unnecessary extensions if the LibCall
- // arguments or return value is f32 type for LP64 ABI.
+ // arguments or return value is a float narrower than XLEN on a soft FP ABI.
RISCVABI::ABI ABI = Subtarget.getTargetABI();
- if (ABI == RISCVABI::ABI_LP64 && (Type == MVT::f32))
+ bool IsSoftABI = ABI == RISCVABI::ABI_LP64 || ABI == RISCVABI::ABI_ILP32 ||
+ ABI == RISCVABI::ABI_ILP32E;
+ if (IsSoftABI && (Type.isFloatingPoint() && !Type.isVector() &&
+ Type.getSizeInBits() < Subtarget.getXLen()))
return false;
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151434.525559.patch
Type: text/x-patch
Size: 3282 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230525/532a6d36/attachment.bin>
More information about the llvm-commits
mailing list