Skip to content

Commit

Permalink
[LoongArch] Suppress the unnecessary extensions for arguments in make…
Browse files Browse the repository at this point in the history
…LibCall

Reviewed By: SixWeining, heiher

Pull Request: llvm#92376
  • Loading branch information
wangleiat authored May 17, 2024
1 parent 5a204a5 commit bf1d417
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
9 changes: 9 additions & 0 deletions llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4991,3 +4991,12 @@ bool LoongArchTargetLowering::shouldSignExtendTypeInLibCall(

return IsSigned;
}

bool LoongArchTargetLowering::shouldExtendTypeInLibCall(EVT Type) const {
// Return false to suppress the unnecessary extensions if the LibCall
// arguments or return value is a float narrower than GRLEN on a soft FP ABI.
if (Subtarget.isSoftFPABI() && (Type.isFloatingPoint() && !Type.isVector() &&
Type.getSizeInBits() < Subtarget.getGRLen()))
return false;
return true;
}
1 change: 1 addition & 0 deletions llvm/lib/Target/LoongArch/LoongArchISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class LoongArchTargetLowering : public TargetLowering {
}
bool shouldConsiderGEPOffsetSplit() const override { return true; }
bool shouldSignExtendTypeInLibCall(EVT Type, bool IsSigned) const override;
bool shouldExtendTypeInLibCall(EVT Type) const override;

private:
/// Target-specific function used to lower LoongArch calling conventions.
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/LoongArch/LoongArchSubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class LoongArchSubtarget : public LoongArchGenSubtargetInfo {
MVT getGRLenVT() const { return GRLenVT; }
unsigned getGRLen() const { return GRLen; }
LoongArchABI::ABI getTargetABI() const { return TargetABI; }
bool isSoftFPABI() const {
return TargetABI == LoongArchABI::ABI_LP64S ||
TargetABI == LoongArchABI::ABI_ILP32S;
}
bool isXRaySupported() const override { return is64Bit(); }
Align getPrefFunctionAlignment() const { return PrefFunctionAlignment; }
Align getPrefLoopAlignment() const { return PrefLoopAlignment; }
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/LoongArch/calling-conv-lp64s.ll
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ define i64 @callee_float_in_regs(i64 %a, float %b) nounwind {
; CHECK-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
; CHECK-NEXT: st.d $fp, $sp, 0 # 8-byte Folded Spill
; CHECK-NEXT: move $fp, $a0
; CHECK-NEXT: addi.w $a0, $a1, 0
; CHECK-NEXT: move $a0, $a1
; CHECK-NEXT: bl %plt(__fixsfdi)
; CHECK-NEXT: add.d $a0, $fp, $a0
; CHECK-NEXT: ld.d $fp, $sp, 0 # 8-byte Folded Reload
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/LoongArch/libcall-extend.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ define signext i32 @convert_float_to_i32(i32 %tmp, float %a) nounwind {
; CHECK: # %bb.0:
; CHECK-NEXT: addi.d $sp, $sp, -16
; CHECK-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
; CHECK-NEXT: bstrpick.d $a0, $a1, 31, 0
; CHECK-NEXT: move $a0, $a1
; CHECK-NEXT: bl %plt(__fixsfsi)
; CHECK-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
; CHECK-NEXT: addi.d $sp, $sp, 16
Expand Down
8 changes: 2 additions & 6 deletions llvm/test/CodeGen/LoongArch/sextw-removal.ll
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,9 @@ define void @test6(i32 signext %arg, i32 signext %arg1) nounwind {
; CHECK-NEXT: addi.w $a0, $fp, 0
; CHECK-NEXT: bl %plt(baz)
; CHECK-NEXT: move $s0, $a0
; CHECK-NEXT: bstrpick.d $a0, $a0, 31, 0
; CHECK-NEXT: bl %plt(__fixsfsi)
; CHECK-NEXT: move $fp, $a0
; CHECK-NEXT: addi.w $a0, $s0, 0
; CHECK-NEXT: move $a0, $s0
; CHECK-NEXT: move $a1, $zero
; CHECK-NEXT: bl %plt(__nesf2)
; CHECK-NEXT: bnez $a0, .LBB5_1
Expand All @@ -285,10 +284,9 @@ define void @test6(i32 signext %arg, i32 signext %arg1) nounwind {
; NORMV-NEXT: addi.w $a0, $fp, 0
; NORMV-NEXT: bl %plt(baz)
; NORMV-NEXT: move $s0, $a0
; NORMV-NEXT: bstrpick.d $a0, $a0, 31, 0
; NORMV-NEXT: bl %plt(__fixsfsi)
; NORMV-NEXT: move $fp, $a0
; NORMV-NEXT: addi.w $a0, $s0, 0
; NORMV-NEXT: move $a0, $s0
; NORMV-NEXT: move $a1, $zero
; NORMV-NEXT: bl %plt(__nesf2)
; NORMV-NEXT: bnez $a0, .LBB5_1
Expand Down Expand Up @@ -562,7 +560,6 @@ define void @test10(i32 signext %arg, i32 signext %arg1) nounwind {
; CHECK-NEXT: addi.w $a0, $fp, 0
; CHECK-NEXT: bl %plt(baz)
; CHECK-NEXT: move $fp, $a0
; CHECK-NEXT: addi.w $a0, $a0, 0
; CHECK-NEXT: move $a1, $zero
; CHECK-NEXT: bl %plt(__nesf2)
; CHECK-NEXT: bnez $a0, .LBB9_1
Expand All @@ -584,7 +581,6 @@ define void @test10(i32 signext %arg, i32 signext %arg1) nounwind {
; NORMV-NEXT: addi.w $a0, $fp, 0
; NORMV-NEXT: bl %plt(baz)
; NORMV-NEXT: move $fp, $a0
; NORMV-NEXT: addi.w $a0, $a0, 0
; NORMV-NEXT: move $a1, $zero
; NORMV-NEXT: bl %plt(__nesf2)
; NORMV-NEXT: bnez $a0, .LBB9_1
Expand Down
2 changes: 0 additions & 2 deletions llvm/test/CodeGen/LoongArch/soft-fp-to-int.ll
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ define i32 @fptosi_i32_float(float %X) nounwind {
; LA64: # %bb.0:
; LA64-NEXT: addi.d $sp, $sp, -16
; LA64-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
; LA64-NEXT: bstrpick.d $a0, $a0, 31, 0
; LA64-NEXT: bl %plt(__fixsfsi)
; LA64-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
; LA64-NEXT: addi.d $sp, $sp, 16
Expand Down Expand Up @@ -145,7 +144,6 @@ define i64 @fptosi_i64_float(float %X) nounwind {
; LA64: # %bb.0:
; LA64-NEXT: addi.d $sp, $sp, -16
; LA64-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
; LA64-NEXT: addi.w $a0, $a0, 0
; LA64-NEXT: bl %plt(__fixsfdi)
; LA64-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
; LA64-NEXT: addi.d $sp, $sp, 16
Expand Down

0 comments on commit bf1d417

Please sign in to comment.