Skip to content

Commit 5a204a5

Browse files
authored
[LoongArch] Use sign extend for i32 arguments in makeLibCall on LA64
The 32 bits arguments and returns on LA64 are always sign extended to i64. So we should be taking this into account around libcalls. Reviewed By: heiher, SixWeining Pull Request: #92375
1 parent 96d2db4 commit 5a204a5

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4983,3 +4983,11 @@ ISD::NodeType LoongArchTargetLowering::getExtendForAtomicCmpSwapArg() const {
49834983
// TODO: LAMCAS will use amcas{_DB,}.[bhwd] which does not require extension.
49844984
return ISD::SIGN_EXTEND;
49854985
}
4986+
4987+
bool LoongArchTargetLowering::shouldSignExtendTypeInLibCall(
4988+
EVT Type, bool IsSigned) const {
4989+
if (Subtarget.is64Bit() && Type == MVT::i32)
4990+
return true;
4991+
4992+
return IsSigned;
4993+
}

llvm/lib/Target/LoongArch/LoongArchISelLowering.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class LoongArchTargetLowering : public TargetLowering {
239239
return false;
240240
}
241241
bool shouldConsiderGEPOffsetSplit() const override { return true; }
242+
bool shouldSignExtendTypeInLibCall(EVT Type, bool IsSigned) const override;
242243

243244
private:
244245
/// Target-specific function used to lower LoongArch calling conventions.

llvm/test/CodeGen/LoongArch/calling-conv-lp64s.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define i64 @callee_float_in_regs(i64 %a, float %b) nounwind {
1010
; CHECK-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
1111
; CHECK-NEXT: st.d $fp, $sp, 0 # 8-byte Folded Spill
1212
; CHECK-NEXT: move $fp, $a0
13-
; CHECK-NEXT: bstrpick.d $a0, $a1, 31, 0
13+
; CHECK-NEXT: addi.w $a0, $a1, 0
1414
; CHECK-NEXT: bl %plt(__fixsfdi)
1515
; CHECK-NEXT: add.d $a0, $fp, $a0
1616
; CHECK-NEXT: ld.d $fp, $sp, 0 # 8-byte Folded Reload

llvm/test/CodeGen/LoongArch/libcall-extend.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ define signext i32 @convert_float_to_i32(i32 %tmp, float %a) nounwind {
88
; CHECK-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
99
; CHECK-NEXT: bstrpick.d $a0, $a1, 31, 0
1010
; CHECK-NEXT: bl %plt(__fixsfsi)
11-
; CHECK-NEXT: addi.w $a0, $a0, 0
1211
; CHECK-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
1312
; CHECK-NEXT: addi.d $sp, $sp, 16
1413
; CHECK-NEXT: ret
@@ -23,7 +22,6 @@ define signext i32 @convert_double_to_i32(i32 %tmp, double %a) nounwind {
2322
; CHECK-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
2423
; CHECK-NEXT: move $a0, $a1
2524
; CHECK-NEXT: bl %plt(__fixdfsi)
26-
; CHECK-NEXT: addi.w $a0, $a0, 0
2725
; CHECK-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
2826
; CHECK-NEXT: addi.d $sp, $sp, 16
2927
; CHECK-NEXT: ret
@@ -39,7 +37,6 @@ define signext i32 @convert_fp128_to_i32(i32 %tmp, fp128 %a) nounwind {
3937
; CHECK-NEXT: move $a0, $a1
4038
; CHECK-NEXT: move $a1, $a2
4139
; CHECK-NEXT: bl %plt(__fixtfsi)
42-
; CHECK-NEXT: addi.w $a0, $a0, 0
4340
; CHECK-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
4441
; CHECK-NEXT: addi.d $sp, $sp, 16
4542
; CHECK-NEXT: ret

llvm/test/CodeGen/LoongArch/sextw-removal.ll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ define void @test6(i32 signext %arg, i32 signext %arg1) nounwind {
257257
; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
258258
; CHECK-NEXT: addi.w $a0, $fp, 0
259259
; CHECK-NEXT: bl %plt(baz)
260-
; CHECK-NEXT: bstrpick.d $s0, $a0, 31, 0
261-
; CHECK-NEXT: move $a0, $s0
260+
; CHECK-NEXT: move $s0, $a0
261+
; CHECK-NEXT: bstrpick.d $a0, $a0, 31, 0
262262
; CHECK-NEXT: bl %plt(__fixsfsi)
263263
; CHECK-NEXT: move $fp, $a0
264-
; CHECK-NEXT: move $a0, $s0
264+
; CHECK-NEXT: addi.w $a0, $s0, 0
265265
; CHECK-NEXT: move $a1, $zero
266266
; CHECK-NEXT: bl %plt(__nesf2)
267267
; CHECK-NEXT: bnez $a0, .LBB5_1
@@ -284,11 +284,11 @@ define void @test6(i32 signext %arg, i32 signext %arg1) nounwind {
284284
; NORMV-NEXT: # =>This Inner Loop Header: Depth=1
285285
; NORMV-NEXT: addi.w $a0, $fp, 0
286286
; NORMV-NEXT: bl %plt(baz)
287-
; NORMV-NEXT: bstrpick.d $s0, $a0, 31, 0
288-
; NORMV-NEXT: move $a0, $s0
287+
; NORMV-NEXT: move $s0, $a0
288+
; NORMV-NEXT: bstrpick.d $a0, $a0, 31, 0
289289
; NORMV-NEXT: bl %plt(__fixsfsi)
290290
; NORMV-NEXT: move $fp, $a0
291-
; NORMV-NEXT: move $a0, $s0
291+
; NORMV-NEXT: addi.w $a0, $s0, 0
292292
; NORMV-NEXT: move $a1, $zero
293293
; NORMV-NEXT: bl %plt(__nesf2)
294294
; NORMV-NEXT: bnez $a0, .LBB5_1
@@ -562,7 +562,7 @@ define void @test10(i32 signext %arg, i32 signext %arg1) nounwind {
562562
; CHECK-NEXT: addi.w $a0, $fp, 0
563563
; CHECK-NEXT: bl %plt(baz)
564564
; CHECK-NEXT: move $fp, $a0
565-
; CHECK-NEXT: bstrpick.d $a0, $a0, 31, 0
565+
; CHECK-NEXT: addi.w $a0, $a0, 0
566566
; CHECK-NEXT: move $a1, $zero
567567
; CHECK-NEXT: bl %plt(__nesf2)
568568
; CHECK-NEXT: bnez $a0, .LBB9_1
@@ -584,7 +584,7 @@ define void @test10(i32 signext %arg, i32 signext %arg1) nounwind {
584584
; NORMV-NEXT: addi.w $a0, $fp, 0
585585
; NORMV-NEXT: bl %plt(baz)
586586
; NORMV-NEXT: move $fp, $a0
587-
; NORMV-NEXT: bstrpick.d $a0, $a0, 31, 0
587+
; NORMV-NEXT: addi.w $a0, $a0, 0
588588
; NORMV-NEXT: move $a1, $zero
589589
; NORMV-NEXT: bl %plt(__nesf2)
590590
; NORMV-NEXT: bnez $a0, .LBB9_1

llvm/test/CodeGen/LoongArch/soft-fp-to-int.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ define i64 @fptosi_i64_float(float %X) nounwind {
145145
; LA64: # %bb.0:
146146
; LA64-NEXT: addi.d $sp, $sp, -16
147147
; LA64-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
148-
; LA64-NEXT: bstrpick.d $a0, $a0, 31, 0
148+
; LA64-NEXT: addi.w $a0, $a0, 0
149149
; LA64-NEXT: bl %plt(__fixsfdi)
150150
; LA64-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
151151
; LA64-NEXT: addi.d $sp, $sp, 16

0 commit comments

Comments
 (0)